X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=fs%2Fxfs%2Flinux-2.6%2Fkmem.h;h=ffe383e14e36a0f506878d61d0ee3aa4f00b1e68;hb=9bf4aaab3e101692164d49b7ca357651eb691cb6;hp=13e6dcd595c9a7c305e4faffea337683177012ef;hpb=db216c3d5e4c040e557a50f8f5d35d5c415e8c1c;p=linux-2.6.git diff --git a/fs/xfs/linux-2.6/kmem.h b/fs/xfs/linux-2.6/kmem.h index 13e6dcd59..ffe383e14 100644 --- a/fs/xfs/linux-2.6/kmem.h +++ b/fs/xfs/linux-2.6/kmem.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved. + * Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as @@ -32,32 +32,34 @@ #ifndef __XFS_SUPPORT_KMEM_H__ #define __XFS_SUPPORT_KMEM_H__ -#include -#include #include -#include - -/* - * Cutoff point to use vmalloc instead of kmalloc. - */ -#define MAX_SLAB_SIZE 0x20000 +#include +#include /* - * XFS uses slightly different names for these due to the - * IRIX heritage. + * memory management routines */ -#define kmem_zone kmem_cache_s -#define kmem_zone_t kmem_cache_t - #define KM_SLEEP 0x0001 #define KM_NOSLEEP 0x0002 #define KM_NOFS 0x0004 -#define KM_MAYFAIL 0x0005 +#define KM_MAYFAIL 0x0008 + +#define kmem_zone kmem_cache_s +#define kmem_zone_t kmem_cache_t typedef unsigned long xfs_pflags_t; +#define PFLAGS_TEST_NOIO() (current->flags & PF_NOIO) #define PFLAGS_TEST_FSTRANS() (current->flags & PF_FSTRANS) +#define PFLAGS_SET_NOIO() do { \ + current->flags |= PF_NOIO; \ +} while (0) + +#define PFLAGS_CLEAR_NOIO() do { \ + current->flags &= ~PF_NOIO; \ +} while (0) + /* these could be nested, so we save state */ #define PFLAGS_SET_FSTRANS(STATEP) do { \ *(STATEP) = current->flags; \ @@ -79,12 +81,11 @@ typedef unsigned long xfs_pflags_t; *(NSTATEP) = *(OSTATEP); \ } while (0) -static __inline unsigned int -kmem_flags_convert(int flags) +static __inline unsigned int kmem_flags_convert(int flags) { int lflags; -#if DEBUG +#ifdef DEBUG if (unlikely(flags & ~(KM_SLEEP|KM_NOSLEEP|KM_NOFS|KM_MAYFAIL))) { printk(KERN_WARNING "XFS: memory allocation with wrong flags (%x)\n", flags); @@ -100,54 +101,9 @@ kmem_flags_convert(int flags) /* avoid recusive callbacks to filesystem during transactions */ if (PFLAGS_TEST_FSTRANS() || (flags & KM_NOFS)) lflags &= ~__GFP_FS; - - if (!(flags & KM_MAYFAIL)) - lflags |= __GFP_NOFAIL; - } - - return lflags; -} - -static __inline void * -kmem_alloc(size_t size, int flags) -{ - if (unlikely(MAX_SLAB_SIZE < size)) - /* Avoid doing filesystem sensitive stuff to get this */ - return __vmalloc(size, kmem_flags_convert(flags), PAGE_KERNEL); - return kmalloc(size, kmem_flags_convert(flags)); -} - -static __inline void * -kmem_zalloc(size_t size, int flags) -{ - void *ptr = kmem_alloc(size, flags); - if (likely(ptr != NULL)) - memset(ptr, 0, size); - return ptr; -} - -static __inline void -kmem_free(void *ptr, size_t size) -{ - if (unlikely((unsigned long)ptr < VMALLOC_START || - (unsigned long)ptr >= VMALLOC_END)) - kfree(ptr); - else - vfree(ptr); -} - -static __inline void * -kmem_realloc(void *ptr, size_t newsize, size_t oldsize, int flags) -{ - void *new = kmem_alloc(newsize, flags); - - if (likely(ptr != NULL)) { - if (likely(new != NULL)) - memcpy(new, ptr, min(oldsize, newsize)); - kmem_free(ptr, oldsize); } - - return new; + + return lflags; } static __inline kmem_zone_t * @@ -156,27 +112,33 @@ kmem_zone_init(int size, char *zone_name) return kmem_cache_create(zone_name, size, 0, 0, NULL, NULL); } -static __inline void * -kmem_zone_alloc(kmem_zone_t *zone, int flags) +static __inline void +kmem_zone_free(kmem_zone_t *zone, void *ptr) { - return kmem_cache_alloc(zone, kmem_flags_convert(flags)); + kmem_cache_free(zone, ptr); } -static __inline void * -kmem_zone_zalloc(kmem_zone_t *zone, int flags) +static __inline void +kmem_zone_destroy(kmem_zone_t *zone) { - void *ptr = kmem_zone_alloc(zone, flags); - if (likely(ptr != NULL)) - memset(ptr, 0, kmem_cache_size(zone)); - return ptr; + if (zone && kmem_cache_destroy(zone)) + BUG(); } -static __inline void -kmem_zone_free(kmem_zone_t *zone, void *ptr) +static __inline int +kmem_zone_shrink(kmem_zone_t *zone) { - kmem_cache_free(zone, ptr); + return kmem_cache_shrink(zone); } +extern void *kmem_zone_zalloc(kmem_zone_t *, int); +extern void *kmem_zone_alloc(kmem_zone_t *, int); + +extern void *kmem_alloc(size_t, int); +extern void *kmem_realloc(void *, size_t, size_t, int); +extern void *kmem_zalloc(size_t, int); +extern void kmem_free(void *, size_t); + typedef struct shrinker *kmem_shaker_t; typedef int (*kmem_shake_func_t)(int, unsigned int);