4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * libcfs/include/libcfs/winnt/winnt-mem.h
38 * Basic library routines of memory manipulation routines.
41 #ifndef __LIBCFS_WINNT_CFS_MEM_H__
42 #define __LIBCFS_WINNT_CFS_MEM_H__
44 #ifndef __LIBCFS_LIBCFS_H__
45 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
48 #include <libcfs/winnt/portals_utils.h>
56 #define PAGE_CACHE_SIZE PAGE_SIZE
57 #define PAGE_CACHE_SHIFT PAGE_SHIFT
58 #define CFS_PAGE_MASK (~(PAGE_SIZE - 1))
60 #define memory_pressure_get() (0)
61 #define memory_pressure_set() do {} while (0)
62 #define memory_pressure_clr() do {} while (0)
76 #define page_private(page) ((page)->private)
77 #define set_page_private(page, v) ((page)->private = (v))
80 #define page_count(page) (0)
82 #define PG_locked 0 /* Page is locked. Don't touch. */
84 #define PG_referenced 2
90 #define PG_slab 7 /* slab debug (Suparna wants this) */
92 #define PG_owner_priv_1 8 /* Owner use. If pagecache, fs may use*/
94 #define PG_reserved 10
95 #define PG_private 11 /* If pagecache, has fs-private data */
97 #define PG_writeback 12 /* Page is under writeback */
98 #define PG_compound 14 /* Part of a compound page */
99 #define PG_swapcache 15 /* Swap page: swp_entry_t in private */
101 #define PG_mappedtodisk 16 /* Has blocks allocated on-disk */
102 #define PG_reclaim 17 /* To be reclaimed asap */
103 #define PG_buddy 19 /* Page is free, on buddy lists */
105 #define PG_virt 31 /* addr is not */
107 #ifndef arch_set_page_uptodate
108 #define arch_set_page_uptodate(page)
111 /* Make it prettier to test the above... */
112 #define UnlockPage(page) unlock_page(page)
113 #define Page_Uptodate(page) test_bit(PG_uptodate, &(page)->flags)
114 #define SetPageUptodate(page) \
116 arch_set_page_uptodate(page); \
117 set_bit(PG_uptodate, &(page)->flags); \
119 #define ClearPageUptodate(page) clear_bit(PG_uptodate, &(page)->flags)
120 #define PageDirty(page) test_bit(PG_dirty, &(page)->flags)
121 #define SetPageDirty(page) set_bit(PG_dirty, &(page)->flags)
122 #define ClearPageDirty(page) clear_bit(PG_dirty, &(page)->flags)
123 #define PageLocked(page) test_bit(PG_locked, &(page)->flags)
124 #define LockPage(page) set_bit(PG_locked, &(page)->flags)
125 #define TryLockPage(page) test_and_set_bit(PG_locked, &(page)->flags)
126 #define PageChecked(page) test_bit(PG_checked, &(page)->flags)
127 #define SetPageChecked(page) set_bit(PG_checked, &(page)->flags)
128 #define ClearPageChecked(page) clear_bit(PG_checked, &(page)->flags)
129 #define PageLaunder(page) test_bit(PG_launder, &(page)->flags)
130 #define SetPageLaunder(page) set_bit(PG_launder, &(page)->flags)
131 #define ClearPageLaunder(page) clear_bit(PG_launder, &(page)->flags)
132 #define ClearPageArch1(page) clear_bit(PG_arch_1, &(page)->flags)
134 #define PageError(page) test_bit(PG_error, &(page)->flags)
135 #define SetPageError(page) set_bit(PG_error, &(page)->flags)
136 #define ClearPageError(page) clear_bit(PG_error, &(page)->flags)
137 #define PageReferenced(page) test_bit(PG_referenced, &(page)->flags)
138 #define SetPageReferenced(page) set_bit(PG_referenced, &(page)->flags)
139 #define ClearPageReferenced(page) clear_bit(PG_referenced, &(page)->flags)
141 #define PageActive(page) test_bit(PG_active, &(page)->flags)
142 #define SetPageActive(page) set_bit(PG_active, &(page)->flags)
143 #define ClearPageActive(page) clear_bit(PG_active, &(page)->flags)
145 #define PageWriteback(page) test_bit(PG_writeback, &(page)->flags)
146 #define TestSetPageWriteback(page) test_and_set_bit(PG_writeback, \
148 #define TestClearPageWriteback(page) test_and_clear_bit(PG_writeback, \
152 * Universal memory allocator API
154 enum cfs_alloc_flags {
155 /* allocation is not allowed to block */
157 /* allocation is allowed to block */
159 /* allocation should return zeroed memory */
161 /* allocation is allowed to call file-system code to free/clean
164 /* allocation is allowed to do io to free/clean memory */
166 /* don't report allocation failure to the console */
168 /* standard allocator flag combination */
169 GFP_IOFS = __GFP_FS | __GFP_IO,
170 GFP_USER = __GFP_WAIT | __GFP_FS | __GFP_IO,
171 GFP_NOFS = __GFP_WAIT | __GFP_IO,
172 GFP_KERNEL = __GFP_WAIT | __GFP_IO | __GFP_FS,
175 /* flags for cfs_page_alloc() in addition to enum cfs_alloc_flags */
176 enum cfs_alloc_page_flags {
177 /* allow to return page beyond KVM. It has to be mapped into KVM by
178 * kmap() and unmapped with kunmap(). */
179 __GFP_HIGHMEM = 0x40,
180 GFP_HIGHUSER = __GFP_WAIT | __GFP_FS | __GFP_IO |
184 struct page *alloc_page(int flags);
185 void __free_page(struct page *pg);
186 void cfs_release_page(struct page *pg);
187 struct page *virt_to_page(void *addr);
189 #define page_cache_get(a) do {} while (0)
190 #define page_cache_release(a) do {} while (0)
192 static inline void *page_address(struct page *page)
197 static inline void *kmap(struct page *page)
202 static inline void kunmap(struct page *page)
207 static inline void get_page(struct page *page)
209 cfs_atomic_inc(&page->count);
212 static inline void cfs_put_page(struct page *page)
214 cfs_atomic_dec(&page->count);
217 static inline int page_count(struct page *page)
219 return cfs_atomic_read(&page->count);
222 #define page_index(p) ((p)->index)
228 #define ALLOC_ATOMIC_TRY (0)
229 extern void *kmalloc(size_t nr_bytes, u_int32_t flags);
230 extern void kfree(void *addr);
231 extern void *vmalloc(size_t nr_bytes);
232 extern void vfree(void *addr);
238 #define SLAB_HWCACHE_ALIGN 0
240 /* The cache name is limited to 20 chars */
245 NPAGED_LOOKASIDE_LIST npll;
249 extern struct kmem_cache *kmem_cache_create(const char *, size_t, size_t,
250 unsigned long, void *);
251 extern kmem_cache_destroy(struct kmem_cache *);
252 extern void *kmem_cache_alloc(struct kmem_cache *, int);
253 extern void kmem_cache_free(struct kmem_cache *, void *);
258 typedef int (*shrink_callback)(int nr_to_scan, gfp_t gfp_mask);
261 int seeks; /* seeks to recreate an obj */
263 /* These are for internal use */
265 long nr; /* objs pending delete */
268 struct shrinker *set_shrinker(int seeks, shrink_callback cb);
269 void remove_shrinker(struct shrinker *s);
271 int start_shrinker_timer();
272 void stop_shrinker_timer();
275 * Page allocator slabs
278 extern struct kmem_cache *cfs_page_t_slab;
279 extern struct kmem_cache *cfs_page_p_slab;
283 #define MMSPACE_OPEN do {} while (0)
284 #define MMSPACE_CLOSE do {} while (0)
287 #define cfs_mb() do {} while(0)
288 #define rmb() cfs_mb()
289 #define wmb() cfs_mb()
292 * MM defintions from (linux/mm.h)
295 #define DEFAULT_SEEKS 2 /* shrink seek */
297 #else /* !__KERNEL__ */
299 #include "../user-mem.h"
301 /* page alignmed buffer allocation */
302 void* pgalloc(size_t factor);
303 void pgfree(void * page);
305 #endif /* __KERNEL__ */
307 #endif /* __WINNT_CFS_MEM_H__ */