1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * libcfs/include/libcfs/linux/linux-mem.h
38 * Basic library routines.
41 #ifndef __LIBCFS_LINUX_CFS_MEM_H__
42 #define __LIBCFS_LINUX_CFS_MEM_H__
44 #ifndef __LIBCFS_LIBCFS_H__
45 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
49 #error This include is only for kernel use.
53 #include <linux/vmalloc.h>
54 #include <linux/pagemap.h>
55 #include <linux/slab.h>
57 # include <linux/mm_inline.h>
60 typedef struct page cfs_page_t;
61 #define CFS_PAGE_SIZE PAGE_CACHE_SIZE
62 #define CFS_PAGE_SHIFT PAGE_CACHE_SHIFT
63 #define CFS_PAGE_MASK (~((__u64)CFS_PAGE_SIZE-1))
65 #define cfs_num_physpages num_physpages
67 #define cfs_copy_from_user(to, from, n) copy_from_user(to, from, n)
68 #define cfs_copy_to_user(to, from, n) copy_to_user(to, from, n)
70 static inline void *cfs_page_address(cfs_page_t *page)
73 * XXX nikita: do NOT call portals_debug_msg() (CDEBUG/ENTRY/EXIT)
74 * from here: this will lead to infinite recursion.
76 return page_address(page);
79 static inline void *cfs_kmap(cfs_page_t *page)
84 static inline void cfs_kunmap(cfs_page_t *page)
89 static inline void cfs_get_page(cfs_page_t *page)
94 static inline int cfs_page_count(cfs_page_t *page)
96 return page_count(page);
99 #define cfs_page_index(p) ((p)->index)
101 #define cfs_page_pin(page) page_cache_get(page)
102 #define cfs_page_unpin(page) page_cache_release(page)
106 * XXX Liang: move these declare to public file
108 extern void *cfs_alloc(size_t nr_bytes, u_int32_t flags);
109 extern void cfs_free(void *addr);
111 extern void *cfs_alloc_large(size_t nr_bytes);
112 extern void cfs_free_large(void *addr);
114 extern cfs_page_t *cfs_alloc_page(unsigned int flags);
115 extern void cfs_free_page(cfs_page_t *page);
117 #define cfs_memory_pressure_get() (current->flags & PF_MEMALLOC)
118 #define cfs_memory_pressure_set() do { current->flags |= PF_MEMALLOC; } while (0)
119 #define cfs_memory_pressure_clr() do { current->flags &= ~PF_MEMALLOC; } while (0)
121 #if BITS_PER_LONG == 32
122 /* limit to lowmem on 32-bit systems */
123 #define CFS_NUM_CACHEPAGES \
124 min(cfs_num_physpages, 1UL << (30 - CFS_PAGE_SHIFT) * 3 / 4)
126 #define CFS_NUM_CACHEPAGES cfs_num_physpages
130 * In Linux there is no way to determine whether current execution context is
133 #define CFS_ALLOC_ATOMIC_TRY CFS_ALLOC_ATOMIC
137 * XXX Liang: move these declare to public file
139 #ifdef HAVE_KMEM_CACHE
140 typedef struct kmem_cache cfs_mem_cache_t;
142 typedef kmem_cache_t cfs_mem_cache_t;
144 extern cfs_mem_cache_t * cfs_mem_cache_create (const char *, size_t, size_t, unsigned long);
145 extern int cfs_mem_cache_destroy ( cfs_mem_cache_t * );
146 extern void *cfs_mem_cache_alloc ( cfs_mem_cache_t *, int);
147 extern void cfs_mem_cache_free ( cfs_mem_cache_t *, void *);
148 extern int cfs_mem_is_in_cache(const void *addr, const cfs_mem_cache_t *kmem);
150 #define CFS_DECL_MMSPACE mm_segment_t __oldfs
151 #define CFS_MMSPACE_OPEN \
152 do { __oldfs = get_fs(); set_fs(get_ds());} while(0)
153 #define CFS_MMSPACE_CLOSE set_fs(__oldfs)
155 #define CFS_SLAB_HWCACHE_ALIGN SLAB_HWCACHE_ALIGN
156 #define CFS_SLAB_KERNEL SLAB_KERNEL
157 #define CFS_SLAB_NOFS SLAB_NOFS
163 #ifndef HAVE_REGISTER_SHRINKER
164 /* Shrinker callback */
165 typedef shrinker_t cfs_shrinker_t;
166 #define cfs_set_shrinker(seeks, shrinker) set_shrinker(seeks, shrinker)
167 #define cfs_remove_shrinker(shrinker) remove_shrinker(shrinker)
168 #endif /* !HAVE_REGISTER_SHRINKER */
170 /* struct shrinker */
171 #define cfs_shrinker shrinker
173 #define CFS_DEFAULT_SEEKS DEFAULT_SEEKS
174 #endif /* __LINUX_CFS_MEM_H__ */