X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=libcfs%2Finclude%2Flibcfs%2Fdarwin%2Fdarwin-mem.h;h=b1a6cd539fcf030af5b047914808d743b390a6eb;hb=92c51841c50cc4061c20b277d3f7c4468f2a80cc;hp=cfe54c38e0cbd730bc5fbf40fb3870d279390938;hpb=70e80ade90af09300396706b8910e196a7928520;p=fs%2Flustre-release.git diff --git a/libcfs/include/libcfs/darwin/darwin-mem.h b/libcfs/include/libcfs/darwin/darwin-mem.h index cfe54c3..b1a6cd5 100644 --- a/libcfs/include/libcfs/darwin/darwin-mem.h +++ b/libcfs/include/libcfs/darwin/darwin-mem.h @@ -1,6 +1,4 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * +/* * GPL HEADER START * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -16,8 +14,8 @@ * in the LICENSE file that accompanied this code). * * You should have received a copy of the GNU General Public License - * version 2 along with this program; If not, see [sun.com URL with a - * copy of GPLv2]. + * version 2 along with this program; If not, see + * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, * CA 95054 USA or visit www.sun.com if you need additional information or @@ -26,7 +24,7 @@ * GPL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. */ /* @@ -76,14 +74,14 @@ /* Variable sized pages are not supported */ #ifdef PAGE_SHIFT -#define CFS_PAGE_SHIFT PAGE_SHIFT +#define PAGE_CACHE_SHIFT PAGE_SHIFT #else -#define CFS_PAGE_SHIFT 12 +#define PAGE_CACHE_SHIFT 12 #endif -#define CFS_PAGE_SIZE (1UL << CFS_PAGE_SHIFT) +#define PAGE_CACHE_SIZE (1UL << PAGE_CACHE_SHIFT) -#define CFS_PAGE_MASK (~((__u64)CFS_PAGE_SIZE - 1)) +#define CFS_PAGE_MASK (~((__u64)PAGE_CACHE_SIZE - 1)) enum { XNU_PAGE_RAW, @@ -103,23 +101,23 @@ typedef __u32 page_off_t; * - "xll" pages (XNU_PAGE_XLL): these are used by file system to cache * file data, owned by file system objects, hashed, lrued, etc. * - * cfs_page_t has to cover both of them, because core Lustre code is based on + * struct page has to cover both of them, because core Lustre code is based on * the Linux assumption that page is _both_ memory buffer and file system * caching entity. * * To achieve this, all types of pages supported on XNU has to start from - * common header that contains only "page type". Common cfs_page_t operations + * common header that contains only "page type". Common struct page operations * dispatch through operation vector based on page type. * */ typedef struct xnu_page { int type; -} cfs_page_t; +} struct page; struct xnu_page_ops { - void *(*page_map) (cfs_page_t *); - void (*page_unmap) (cfs_page_t *); - void *(*page_address) (cfs_page_t *); + void *(*page_map) (struct page *); + void (*page_unmap) (struct page *); + void *(*page_address) (struct page *); }; void xnu_page_ops_register(int type, struct xnu_page_ops *ops); @@ -138,44 +136,81 @@ struct xnu_raw_page { /* * Public interface to lustre * - * - cfs_alloc_page(f) - * - cfs_free_page(p) - * - cfs_kmap(p) - * - cfs_kunmap(p) - * - cfs_page_address(p) + * - alloc_page(f) + * - __free_page(p) + * - kmap(p) + * - kunmap(p) + * - page_address(p) */ /* - * Of all functions above only cfs_kmap(), cfs_kunmap(), and - * cfs_page_address() can be called on file system pages. The rest is for raw + * Of all functions above only kmap(), kunmap(), and + * page_address() can be called on file system pages. The rest is for raw * pages only. */ -cfs_page_t *cfs_alloc_page(u_int32_t flags); -void cfs_free_page(cfs_page_t *page); -void cfs_get_page(cfs_page_t *page); -int cfs_put_page_testzero(cfs_page_t *page); -int cfs_page_count(cfs_page_t *page); -#define cfs_page_index(pg) (0) +struct page *alloc_page(u_int32_t flags); +void __free_page(struct page *page); +void get_page(struct page *page); +int cfs_put_page_testzero(struct page *page); +int page_count(struct page *page); +#define page_index(pg) (0) -void *cfs_page_address(cfs_page_t *pg); -void *cfs_kmap(cfs_page_t *pg); -void cfs_kunmap(cfs_page_t *pg); +void *page_address(struct page *pg); +void *kmap(struct page *pg); +void kunmap(struct page *pg); /* * Memory allocator */ -void *cfs_alloc(size_t nr_bytes, u_int32_t flags); -void cfs_free(void *addr); +void *kmalloc(size_t nr_bytes, u_int32_t flags); +void kfree(void *addr); -void *cfs_alloc_large(size_t nr_bytes); -void cfs_free_large(void *addr); +void *vmalloc(size_t nr_bytes); +void vfree(void *addr); extern int get_preemption_level(void); -#define CFS_ALLOC_ATOMIC_TRY \ - (get_preemption_level() != 0 ? CFS_ALLOC_ATOMIC : 0) +/* + * 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, +}; + +#define ALLOC_ATOMIC_TRY \ + (get_preemption_level() != 0 ? GFP_ATOMIC : 0) + +#define memory_pressure_get() (0) +#define memory_pressure_set() do {} while (0) +#define memory_pressure_clr() do {} while (0) /* * Slab: @@ -209,30 +244,32 @@ typedef zone_t mem_cache_t; #define MC_NAME_MAX_LEN 64 -typedef struct cfs_mem_cache { +struct kmem_cache { int mc_size; mem_cache_t mc_cache; struct list_head mc_link; char mc_name [MC_NAME_MAX_LEN]; -} cfs_mem_cache_t; +}; #define KMEM_CACHE_MAX_COUNT 64 #define KMEM_MAX_ZONE 8192 -cfs_mem_cache_t * cfs_mem_cache_create (const char *, size_t, size_t, unsigned long); -int cfs_mem_cache_destroy ( cfs_mem_cache_t * ); -void *cfs_mem_cache_alloc ( cfs_mem_cache_t *, int); -void cfs_mem_cache_free ( cfs_mem_cache_t *, void *); +struct kmem_cache *kmem_cache_create(const char *, size_t, size_t, + unsigned long, void *); +void kmem_cache_destroy(struct kmem_cache *); +void *kmem_cache_alloc(struct kmem_cache *, int); +void kmem_cache_free(struct kmem_cache *, void *); /* * Misc */ -/* XXX Liang: num_physpages... fix me */ -#define num_physpages (64 * 1024) +/* XXX Liang: totalram_pages... fix me */ +#define totalram_pages (64 * 1024) +#define NUM_CACHEPAGES totalram_pages -#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 copy_from_user(kaddr, uaddr, size) copyin(CAST_USER_ADDR_T(uaddr), (caddr_t)kaddr, size) #define copy_to_user(uaddr, kaddr, size) copyout((caddr_t)kaddr, CAST_USER_ADDR_T(uaddr), size)