diff options
author | Christoph Hellwig <hch@infradead.org> | 2010-01-20 16:55:30 -0500 |
---|---|---|
committer | Alex Elder <aelder@sgi.com> | 2010-01-21 14:44:56 -0500 |
commit | bdfb04301fa5fdd95f219539a9a5b9663b1e5fc2 (patch) | |
tree | 6d50b1c71d1f227cf1800ee0531a475266ef6da8 /fs/xfs/linux-2.6/kmem.c | |
parent | a14a348bff2f99471a28e5928eb6801224c053d8 (diff) |
xfs: replace KM_LARGE with explicit vmalloc use
We use the KM_LARGE flag to make kmem_alloc and friends use vmalloc
if necessary. As we only need this for a few boot/mount time
allocations just switch to explicit vmalloc calls there.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Alex Elder <aelder@sgi.com>
Diffstat (limited to 'fs/xfs/linux-2.6/kmem.c')
-rw-r--r-- | fs/xfs/linux-2.6/kmem.c | 56 |
1 files changed, 20 insertions, 36 deletions
diff --git a/fs/xfs/linux-2.6/kmem.c b/fs/xfs/linux-2.6/kmem.c index 2d3f90afe5f1..bc7405585def 100644 --- a/fs/xfs/linux-2.6/kmem.c +++ b/fs/xfs/linux-2.6/kmem.c | |||
@@ -16,7 +16,6 @@ | |||
16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
17 | */ | 17 | */ |
18 | #include <linux/mm.h> | 18 | #include <linux/mm.h> |
19 | #include <linux/vmalloc.h> | ||
20 | #include <linux/highmem.h> | 19 | #include <linux/highmem.h> |
21 | #include <linux/swap.h> | 20 | #include <linux/swap.h> |
22 | #include <linux/blkdev.h> | 21 | #include <linux/blkdev.h> |
@@ -24,8 +23,25 @@ | |||
24 | #include "time.h" | 23 | #include "time.h" |
25 | #include "kmem.h" | 24 | #include "kmem.h" |
26 | 25 | ||
27 | #define MAX_VMALLOCS 6 | 26 | /* |
28 | #define MAX_SLAB_SIZE 0x20000 | 27 | * Greedy allocation. May fail and may return vmalloced memory. |
28 | * | ||
29 | * Must be freed using kmem_free_large. | ||
30 | */ | ||
31 | void * | ||
32 | kmem_zalloc_greedy(size_t *size, size_t minsize, size_t maxsize) | ||
33 | { | ||
34 | void *ptr; | ||
35 | size_t kmsize = maxsize; | ||
36 | |||
37 | while (!(ptr = kmem_zalloc_large(kmsize))) { | ||
38 | if ((kmsize >>= 1) <= minsize) | ||
39 | kmsize = minsize; | ||
40 | } | ||
41 | if (ptr) | ||
42 | *size = kmsize; | ||
43 | return ptr; | ||
44 | } | ||
29 | 45 | ||
30 | void * | 46 | void * |
31 | kmem_alloc(size_t size, unsigned int __nocast flags) | 47 | kmem_alloc(size_t size, unsigned int __nocast flags) |
@@ -34,19 +50,8 @@ kmem_alloc(size_t size, unsigned int __nocast flags) | |||
34 | gfp_t lflags = kmem_flags_convert(flags); | 50 | gfp_t lflags = kmem_flags_convert(flags); |
35 | void *ptr; | 51 | void *ptr; |
36 | 52 | ||
37 | #ifdef DEBUG | ||
38 | if (unlikely(!(flags & KM_LARGE) && (size > PAGE_SIZE))) { | ||
39 | printk(KERN_WARNING "Large %s attempt, size=%ld\n", | ||
40 | __func__, (long)size); | ||
41 | dump_stack(); | ||
42 | } | ||
43 | #endif | ||
44 | |||
45 | do { | 53 | do { |
46 | if (size < MAX_SLAB_SIZE || retries > MAX_VMALLOCS) | 54 | ptr = kmalloc(size, lflags); |
47 | ptr = kmalloc(size, lflags); | ||
48 | else | ||
49 | ptr = __vmalloc(size, lflags, PAGE_KERNEL); | ||
50 | if (ptr || (flags & (KM_MAYFAIL|KM_NOSLEEP))) | 55 | if (ptr || (flags & (KM_MAYFAIL|KM_NOSLEEP))) |
51 | return ptr; | 56 | return ptr; |
52 | if (!(++retries % 100)) | 57 | if (!(++retries % 100)) |
@@ -68,27 +73,6 @@ kmem_zalloc(size_t size, unsigned int __nocast flags) | |||
68 | return ptr; | 73 | return ptr; |
69 | } | 74 | } |
70 | 75 | ||
71 | void * | ||
72 | kmem_zalloc_greedy(size_t *size, size_t minsize, size_t maxsize, | ||
73 | unsigned int __nocast flags) | ||
74 | { | ||
75 | void *ptr; | ||
76 | size_t kmsize = maxsize; | ||
77 | unsigned int kmflags = (flags & ~KM_SLEEP) | KM_NOSLEEP; | ||
78 | |||
79 | while (!(ptr = kmem_zalloc(kmsize, kmflags))) { | ||
80 | if ((kmsize <= minsize) && (flags & KM_NOSLEEP)) | ||
81 | break; | ||
82 | if ((kmsize >>= 1) <= minsize) { | ||
83 | kmsize = minsize; | ||
84 | kmflags = flags; | ||
85 | } | ||
86 | } | ||
87 | if (ptr) | ||
88 | *size = kmsize; | ||
89 | return ptr; | ||
90 | } | ||
91 | |||
92 | void | 76 | void |
93 | kmem_free(const void *ptr) | 77 | kmem_free(const void *ptr) |
94 | { | 78 | { |