diff options
Diffstat (limited to 'fs/xfs/linux-2.6/kmem.h')
| -rw-r--r-- | fs/xfs/linux-2.6/kmem.h | 91 |
1 files changed, 55 insertions, 36 deletions
diff --git a/fs/xfs/linux-2.6/kmem.h b/fs/xfs/linux-2.6/kmem.h index c64a29cdfff3..f0268a84e6fd 100644 --- a/fs/xfs/linux-2.6/kmem.h +++ b/fs/xfs/linux-2.6/kmem.h | |||
| @@ -23,17 +23,8 @@ | |||
| 23 | #include <linux/mm.h> | 23 | #include <linux/mm.h> |
| 24 | 24 | ||
| 25 | /* | 25 | /* |
| 26 | * memory management routines | 26 | * Process flags handling |
| 27 | */ | 27 | */ |
| 28 | #define KM_SLEEP 0x0001u | ||
| 29 | #define KM_NOSLEEP 0x0002u | ||
| 30 | #define KM_NOFS 0x0004u | ||
| 31 | #define KM_MAYFAIL 0x0008u | ||
| 32 | |||
| 33 | #define kmem_zone kmem_cache | ||
| 34 | #define kmem_zone_t struct kmem_cache | ||
| 35 | |||
| 36 | typedef unsigned long xfs_pflags_t; | ||
| 37 | 28 | ||
| 38 | #define PFLAGS_TEST_NOIO() (current->flags & PF_NOIO) | 29 | #define PFLAGS_TEST_NOIO() (current->flags & PF_NOIO) |
| 39 | #define PFLAGS_TEST_FSTRANS() (current->flags & PF_FSTRANS) | 30 | #define PFLAGS_TEST_FSTRANS() (current->flags & PF_FSTRANS) |
| @@ -67,74 +58,102 @@ typedef unsigned long xfs_pflags_t; | |||
| 67 | *(NSTATEP) = *(OSTATEP); \ | 58 | *(NSTATEP) = *(OSTATEP); \ |
| 68 | } while (0) | 59 | } while (0) |
| 69 | 60 | ||
| 70 | static __inline gfp_t kmem_flags_convert(unsigned int __nocast flags) | 61 | /* |
| 62 | * General memory allocation interfaces | ||
| 63 | */ | ||
| 64 | |||
| 65 | #define KM_SLEEP 0x0001u | ||
| 66 | #define KM_NOSLEEP 0x0002u | ||
| 67 | #define KM_NOFS 0x0004u | ||
| 68 | #define KM_MAYFAIL 0x0008u | ||
| 69 | |||
| 70 | /* | ||
| 71 | * We use a special process flag to avoid recursive callbacks into | ||
| 72 | * the filesystem during transactions. We will also issue our own | ||
| 73 | * warnings, so we explicitly skip any generic ones (silly of us). | ||
| 74 | */ | ||
| 75 | static inline gfp_t | ||
| 76 | kmem_flags_convert(unsigned int __nocast flags) | ||
| 71 | { | 77 | { |
| 72 | gfp_t lflags = __GFP_NOWARN; /* we'll report problems, if need be */ | 78 | gfp_t lflags; |
| 73 | 79 | ||
| 74 | #ifdef DEBUG | 80 | BUG_ON(flags & ~(KM_SLEEP|KM_NOSLEEP|KM_NOFS|KM_MAYFAIL)); |
| 75 | if (unlikely(flags & ~(KM_SLEEP|KM_NOSLEEP|KM_NOFS|KM_MAYFAIL))) { | ||
| 76 | printk(KERN_WARNING | ||
| 77 | "XFS: memory allocation with wrong flags (%x)\n", flags); | ||
| 78 | BUG(); | ||
| 79 | } | ||
| 80 | #endif | ||
| 81 | 81 | ||
| 82 | if (flags & KM_NOSLEEP) { | 82 | if (flags & KM_NOSLEEP) { |
| 83 | lflags |= GFP_ATOMIC; | 83 | lflags = GFP_ATOMIC | __GFP_NOWARN; |
| 84 | } else { | 84 | } else { |
| 85 | lflags |= GFP_KERNEL; | 85 | lflags = GFP_KERNEL | __GFP_NOWARN; |
| 86 | |||
| 87 | /* avoid recusive callbacks to filesystem during transactions */ | ||
| 88 | if (PFLAGS_TEST_FSTRANS() || (flags & KM_NOFS)) | 86 | if (PFLAGS_TEST_FSTRANS() || (flags & KM_NOFS)) |
| 89 | lflags &= ~__GFP_FS; | 87 | lflags &= ~__GFP_FS; |
| 90 | } | 88 | } |
| 91 | 89 | return lflags; | |
| 92 | return lflags; | ||
| 93 | } | 90 | } |
| 94 | 91 | ||
| 95 | static __inline kmem_zone_t * | 92 | extern void *kmem_alloc(size_t, unsigned int __nocast); |
| 93 | extern void *kmem_realloc(void *, size_t, size_t, unsigned int __nocast); | ||
| 94 | extern void *kmem_zalloc(size_t, unsigned int __nocast); | ||
| 95 | extern void kmem_free(void *, size_t); | ||
| 96 | |||
| 97 | /* | ||
| 98 | * Zone interfaces | ||
| 99 | */ | ||
| 100 | |||
| 101 | #define KM_ZONE_HWALIGN SLAB_HWCACHE_ALIGN | ||
| 102 | #define KM_ZONE_RECLAIM SLAB_RECLAIM_ACCOUNT | ||
| 103 | #define KM_ZONE_SPREAD 0 | ||
| 104 | |||
| 105 | #define kmem_zone kmem_cache | ||
| 106 | #define kmem_zone_t struct kmem_cache | ||
| 107 | |||
| 108 | static inline kmem_zone_t * | ||
| 96 | kmem_zone_init(int size, char *zone_name) | 109 | kmem_zone_init(int size, char *zone_name) |
| 97 | { | 110 | { |
| 98 | return kmem_cache_create(zone_name, size, 0, 0, NULL, NULL); | 111 | return kmem_cache_create(zone_name, size, 0, 0, NULL, NULL); |
| 99 | } | 112 | } |
| 100 | 113 | ||
| 101 | static __inline void | 114 | static inline kmem_zone_t * |
| 115 | kmem_zone_init_flags(int size, char *zone_name, unsigned long flags, | ||
| 116 | void (*construct)(void *, kmem_zone_t *, unsigned long)) | ||
| 117 | { | ||
| 118 | return kmem_cache_create(zone_name, size, 0, flags, construct, NULL); | ||
| 119 | } | ||
| 120 | |||
| 121 | static inline void | ||
| 102 | kmem_zone_free(kmem_zone_t *zone, void *ptr) | 122 | kmem_zone_free(kmem_zone_t *zone, void *ptr) |
| 103 | { | 123 | { |
| 104 | kmem_cache_free(zone, ptr); | 124 | kmem_cache_free(zone, ptr); |
| 105 | } | 125 | } |
| 106 | 126 | ||
| 107 | static __inline void | 127 | static inline void |
| 108 | kmem_zone_destroy(kmem_zone_t *zone) | 128 | kmem_zone_destroy(kmem_zone_t *zone) |
| 109 | { | 129 | { |
| 110 | if (zone && kmem_cache_destroy(zone)) | 130 | if (zone && kmem_cache_destroy(zone)) |
| 111 | BUG(); | 131 | BUG(); |
| 112 | } | 132 | } |
| 113 | 133 | ||
| 114 | extern void *kmem_zone_zalloc(kmem_zone_t *, unsigned int __nocast); | ||
| 115 | extern void *kmem_zone_alloc(kmem_zone_t *, unsigned int __nocast); | 134 | extern void *kmem_zone_alloc(kmem_zone_t *, unsigned int __nocast); |
| 135 | extern void *kmem_zone_zalloc(kmem_zone_t *, unsigned int __nocast); | ||
| 116 | 136 | ||
| 117 | extern void *kmem_alloc(size_t, unsigned int __nocast); | 137 | /* |
| 118 | extern void *kmem_realloc(void *, size_t, size_t, unsigned int __nocast); | 138 | * Low memory cache shrinkers |
| 119 | extern void *kmem_zalloc(size_t, unsigned int __nocast); | 139 | */ |
| 120 | extern void kmem_free(void *, size_t); | ||
| 121 | 140 | ||
| 122 | typedef struct shrinker *kmem_shaker_t; | 141 | typedef struct shrinker *kmem_shaker_t; |
| 123 | typedef int (*kmem_shake_func_t)(int, gfp_t); | 142 | typedef int (*kmem_shake_func_t)(int, gfp_t); |
| 124 | 143 | ||
| 125 | static __inline kmem_shaker_t | 144 | static inline kmem_shaker_t |
| 126 | kmem_shake_register(kmem_shake_func_t sfunc) | 145 | kmem_shake_register(kmem_shake_func_t sfunc) |
| 127 | { | 146 | { |
| 128 | return set_shrinker(DEFAULT_SEEKS, sfunc); | 147 | return set_shrinker(DEFAULT_SEEKS, sfunc); |
| 129 | } | 148 | } |
| 130 | 149 | ||
| 131 | static __inline void | 150 | static inline void |
| 132 | kmem_shake_deregister(kmem_shaker_t shrinker) | 151 | kmem_shake_deregister(kmem_shaker_t shrinker) |
| 133 | { | 152 | { |
| 134 | remove_shrinker(shrinker); | 153 | remove_shrinker(shrinker); |
| 135 | } | 154 | } |
| 136 | 155 | ||
| 137 | static __inline int | 156 | static inline int |
| 138 | kmem_shake_allow(gfp_t gfp_mask) | 157 | kmem_shake_allow(gfp_t gfp_mask) |
| 139 | { | 158 | { |
| 140 | return (gfp_mask & __GFP_WAIT); | 159 | return (gfp_mask & __GFP_WAIT); |
