Whamcloud - gitweb
LU-1346 libcfs: replace cfs_ memory wrappers
[fs/lustre-release.git] / libcfs / include / libcfs / winnt / winnt-mem.h
index 2435915..e13dd59 100644 (file)
 
 #ifdef __KERNEL__
 
-typedef struct cfs_mem_cache cfs_mem_cache_t;
-
 /*
  * page definitions
  */
 
-#define CFS_PAGE_SIZE                   PAGE_SIZE
-#define CFS_PAGE_SHIFT                  PAGE_SHIFT
+#define PAGE_CACHE_SIZE                   PAGE_SIZE
+#define PAGE_CACHE_SHIFT                  PAGE_SHIFT
 #define CFS_PAGE_MASK                   (~(PAGE_SIZE - 1))
 
-typedef struct cfs_page {
+#define memory_pressure_get() (0)
+#define memory_pressure_set() do {} while (0)
+#define memory_pressure_clr() do {} while (0)
+
+struct page {
     void *          addr;
     cfs_atomic_t    count;
     void *          private;
     void *          mapping;
     __u32           index;
     __u32           flags;
-} cfs_page_t;
+};
 
 #define page cfs_page
 
@@ -146,90 +148,115 @@ typedef struct cfs_page {
 #define TestClearPageWriteback(page) test_and_clear_bit(PG_writeback,  \
                                                        &(page)->flags)
 
-#define __GFP_FS    (1)
-#define GFP_KERNEL  (2)
-#define GFP_ATOMIC  (4)
+/*
+ * Universal memory allocator API
+ */
+enum cfs_alloc_flags {
+       /* allocation is not allowed to block */
+       GFP_ATOMIC = 0x1,
+       /* allocation is allowed to block */
+       __GFP_WAIT   = 0x2,
+       /* allocation should return zeroed memory */
+       __GFP_ZERO   = 0x4,
+       /* allocation is allowed to call file-system code to free/clean
+        * memory */
+       __GFP_FS     = 0x8,
+       /* allocation is allowed to do io to free/clean memory */
+       __GFP_IO     = 0x10,
+       /* don't report allocation failure to the console */
+       __GFP_NOWARN = 0x20,
+       /* standard allocator flag combination */
+       GFP_IOFS    = __GFP_FS | __GFP_IO,
+       GFP_USER   = __GFP_WAIT | __GFP_FS | __GFP_IO,
+       GFP_NOFS   = __GFP_WAIT | __GFP_IO,
+       GFP_KERNEL = __GFP_WAIT | __GFP_IO | __GFP_FS,
+};
+
+/* flags for cfs_page_alloc() in addition to enum cfs_alloc_flags */
+enum cfs_alloc_page_flags {
+       /* allow to return page beyond KVM. It has to be mapped into KVM by
+        * kmap() and unmapped with kunmap(). */
+       __GFP_HIGHMEM  = 0x40,
+       GFP_HIGHUSER = __GFP_WAIT | __GFP_FS | __GFP_IO |
+                            __GFP_HIGHMEM,
+};
 
-cfs_page_t *cfs_alloc_page(int flags);
-void cfs_free_page(cfs_page_t *pg);
-void cfs_release_page(cfs_page_t *pg);
-cfs_page_t * virt_to_page(void * addr);
-int cfs_mem_is_in_cache(const void *addr, const cfs_mem_cache_t *kmem);
+struct page *alloc_page(int flags);
+void __free_page(struct page *pg);
+void cfs_release_page(struct page *pg);
+struct page *virt_to_page(void *addr);
 
 #define page_cache_get(a) do {} while (0)
 #define page_cache_release(a) do {} while (0)
 
-static inline void *cfs_page_address(cfs_page_t *page)
+static inline void *page_address(struct page *page)
 {
     return page->addr;
 }
 
-static inline void *cfs_kmap(cfs_page_t *page)
+static inline void *kmap(struct page *page)
 {
     return page->addr;
 }
 
-static inline void cfs_kunmap(cfs_page_t *page)
+static inline void kunmap(struct page *page)
 {
     return;
 }
 
-static inline void cfs_get_page(cfs_page_t *page)
+static inline void get_page(struct page *page)
 {
     cfs_atomic_inc(&page->count);
 }
 
-static inline void cfs_put_page(cfs_page_t *page)
+static inline void cfs_put_page(struct page *page)
 {
     cfs_atomic_dec(&page->count);
 }
 
-static inline int cfs_page_count(cfs_page_t *page)
+static inline int page_count(struct page *page)
 {
     return cfs_atomic_read(&page->count);
 }
 
-#define cfs_page_index(p)       ((p)->index)
+#define page_index(p)       ((p)->index)
 
 /*
  * Memory allocator
  */
 
-#define CFS_ALLOC_ATOMIC_TRY   (0)
-extern void *cfs_alloc(size_t nr_bytes, u_int32_t flags);
-extern void  cfs_free(void *addr);
-
-#define kmalloc cfs_alloc
-
-extern void *cfs_alloc_large(size_t nr_bytes);
-extern void  cfs_free_large(void *addr);
+#define ALLOC_ATOMIC_TRY       (0)
+extern void *kmalloc(size_t nr_bytes, u_int32_t flags);
+extern void  kfree(void *addr);
+extern void *vmalloc(size_t nr_bytes);
+extern void  vfree(void *addr);
 
 /*
  * SLAB allocator
  */
 
-#define CFS_SLAB_HWCACHE_ALIGN         0
+#define SLAB_HWCACHE_ALIGN             0
 
 /* The cache name is limited to 20 chars */
 
-struct cfs_mem_cache {
+struct kmem_cache {
     char                    name[20];
     ulong_ptr_t             flags;
     NPAGED_LOOKASIDE_LIST   npll;
 };
 
 
-extern cfs_mem_cache_t *cfs_mem_cache_create (const char *, size_t, size_t,
-                                              unsigned long);
-extern int cfs_mem_cache_destroy (cfs_mem_cache_t * );
-extern void *cfs_mem_cache_alloc (cfs_mem_cache_t *, int);
-extern void cfs_mem_cache_free (cfs_mem_cache_t *, void *);
+extern struct kmem_cache *kmem_cache_create(const char *, size_t, size_t,
+                                           unsigned long, void *);
+extern kmem_cache_destroy(struct kmem_cache *);
+extern void *kmem_cache_alloc(struct kmem_cache *, int);
+extern void kmem_cache_free(struct kmem_cache *, void *);
 
 /*
  * shrinker 
  */
 typedef int (*shrink_callback)(int nr_to_scan, gfp_t gfp_mask);
-struct cfs_shrinker {
+struct shrinker {
         shrink_callback cb;
        int seeks;      /* seeks to recreate an obj */
 
@@ -238,8 +265,8 @@ struct cfs_shrinker {
        long nr;        /* objs pending delete */
 };
 
-struct cfs_shrinker *cfs_set_shrinker(int seeks, shrink_callback cb);
-void cfs_remove_shrinker(struct cfs_shrinker *s);
+struct shrinker *set_shrinker(int seeks, shrink_callback cb);
+void remove_shrinker(struct shrinker *s);
 
 int start_shrinker_timer();
 void stop_shrinker_timer();
@@ -248,13 +275,13 @@ void stop_shrinker_timer();
  * Page allocator slabs 
  */
 
-extern cfs_mem_cache_t *cfs_page_t_slab;
-extern cfs_mem_cache_t *cfs_page_p_slab;
+extern struct kmem_cache *cfs_page_t_slab;
+extern struct kmem_cache *cfs_page_p_slab;
 
 
-#define CFS_DECL_MMSPACE
-#define CFS_MMSPACE_OPEN    do {} while(0)
-#define CFS_MMSPACE_CLOSE   do {} while(0)
+#define DECL_MMSPACE
+#define MMSPACE_OPEN    do {} while (0)
+#define MMSPACE_CLOSE   do {} while (0)
 
 
 #define cfs_mb()     do {} while(0)
@@ -265,7 +292,7 @@ extern cfs_mem_cache_t *cfs_page_p_slab;
  * MM defintions from (linux/mm.h)
  */
 
-#define CFS_DEFAULT_SEEKS 2 /* shrink seek */
+#define DEFAULT_SEEKS 2 /* shrink seek */
 
 #else  /* !__KERNEL__ */