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.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * libcfs/include/libcfs/winnt/winnt-mem.h
36 * Basic library routines of memory manipulation routines.
39 #ifndef __LIBCFS_WINNT_CFS_MEM_H__
40 #define __LIBCFS_WINNT_CFS_MEM_H__
42 #ifndef __LIBCFS_LIBCFS_H__
43 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
46 #include <libcfs/winnt/portals_utils.h>
50 typedef struct cfs_mem_cache cfs_mem_cache_t;
56 #define CFS_PAGE_SIZE PAGE_SIZE
57 #define CFS_PAGE_SHIFT PAGE_SHIFT
58 #define CFS_PAGE_MASK (~(PAGE_SIZE - 1))
60 typedef struct cfs_page {
72 #define page_private(page) ((page)->private)
73 #define set_page_private(page, v) ((page)->private = (v))
76 #define page_count(page) (0)
78 #define PG_locked 0 /* Page is locked. Don't touch. */
80 #define PG_referenced 2
86 #define PG_slab 7 /* slab debug (Suparna wants this) */
88 #define PG_owner_priv_1 8 /* Owner use. If pagecache, fs may use*/
90 #define PG_reserved 10
91 #define PG_private 11 /* If pagecache, has fs-private data */
93 #define PG_writeback 12 /* Page is under writeback */
94 #define PG_compound 14 /* Part of a compound page */
95 #define PG_swapcache 15 /* Swap page: swp_entry_t in private */
97 #define PG_mappedtodisk 16 /* Has blocks allocated on-disk */
98 #define PG_reclaim 17 /* To be reclaimed asap */
99 #define PG_buddy 19 /* Page is free, on buddy lists */
101 #define PG_virt 31 /* addr is not */
103 #ifndef arch_set_page_uptodate
104 #define arch_set_page_uptodate(page)
107 /* Make it prettier to test the above... */
108 #define UnlockPage(page) unlock_page(page)
109 #define Page_Uptodate(page) test_bit(PG_uptodate, &(page)->flags)
110 #define SetPageUptodate(page) \
112 arch_set_page_uptodate(page); \
113 set_bit(PG_uptodate, &(page)->flags); \
115 #define ClearPageUptodate(page) clear_bit(PG_uptodate, &(page)->flags)
116 #define PageDirty(page) test_bit(PG_dirty, &(page)->flags)
117 #define SetPageDirty(page) set_bit(PG_dirty, &(page)->flags)
118 #define ClearPageDirty(page) clear_bit(PG_dirty, &(page)->flags)
119 #define PageLocked(page) test_bit(PG_locked, &(page)->flags)
120 #define LockPage(page) set_bit(PG_locked, &(page)->flags)
121 #define TryLockPage(page) test_and_set_bit(PG_locked, &(page)->flags)
122 #define PageChecked(page) test_bit(PG_checked, &(page)->flags)
123 #define SetPageChecked(page) set_bit(PG_checked, &(page)->flags)
124 #define ClearPageChecked(page) clear_bit(PG_checked, &(page)->flags)
125 #define PageLaunder(page) test_bit(PG_launder, &(page)->flags)
126 #define SetPageLaunder(page) set_bit(PG_launder, &(page)->flags)
127 #define ClearPageLaunder(page) clear_bit(PG_launder, &(page)->flags)
128 #define ClearPageArch1(page) clear_bit(PG_arch_1, &(page)->flags)
130 #define PageError(page) test_bit(PG_error, &(page)->flags)
131 #define SetPageError(page) set_bit(PG_error, &(page)->flags)
132 #define ClearPageError(page) clear_bit(PG_error, &(page)->flags)
133 #define PageReferenced(page) test_bit(PG_referenced, &(page)->flags)
134 #define SetPageReferenced(page) set_bit(PG_referenced, &(page)->flags)
135 #define ClearPageReferenced(page) clear_bit(PG_referenced, &(page)->flags)
137 #define PageActive(page) test_bit(PG_active, &(page)->flags)
138 #define SetPageActive(page) set_bit(PG_active, &(page)->flags)
139 #define ClearPageActive(page) clear_bit(PG_active, &(page)->flags)
141 #define PageWriteback(page) test_bit(PG_writeback, &(page)->flags)
142 #define TestSetPageWriteback(page) test_and_set_bit(PG_writeback, \
144 #define TestClearPageWriteback(page) test_and_clear_bit(PG_writeback, \
148 #define GFP_KERNEL (2)
149 #define GFP_ATOMIC (4)
151 cfs_page_t *cfs_alloc_page(int flags);
152 void cfs_free_page(cfs_page_t *pg);
153 void cfs_release_page(cfs_page_t *pg);
154 cfs_page_t * virt_to_page(void * addr);
155 int cfs_mem_is_in_cache(const void *addr, const cfs_mem_cache_t *kmem);
157 #define page_cache_get(a) do {} while (0)
158 #define page_cache_release(a) do {} while (0)
160 static inline void *cfs_page_address(cfs_page_t *page)
165 static inline void *cfs_kmap(cfs_page_t *page)
170 static inline void cfs_kunmap(cfs_page_t *page)
175 static inline void cfs_get_page(cfs_page_t *page)
177 cfs_atomic_inc(&page->count);
180 static inline void cfs_put_page(cfs_page_t *page)
182 cfs_atomic_dec(&page->count);
185 static inline int cfs_page_count(cfs_page_t *page)
187 return cfs_atomic_read(&page->count);
190 #define cfs_page_index(p) ((p)->index)
196 #define CFS_ALLOC_ATOMIC_TRY (0)
197 extern void *cfs_alloc(size_t nr_bytes, u_int32_t flags);
198 extern void cfs_free(void *addr);
200 #define kmalloc cfs_alloc
202 extern void *cfs_alloc_large(size_t nr_bytes);
203 extern void cfs_free_large(void *addr);
209 #define CFS_SLAB_HWCACHE_ALIGN 0
211 /* The cache name is limited to 20 chars */
213 struct cfs_mem_cache {
216 NPAGED_LOOKASIDE_LIST npll;
220 extern cfs_mem_cache_t *cfs_mem_cache_create (const char *, size_t, size_t,
222 extern int cfs_mem_cache_destroy (cfs_mem_cache_t * );
223 extern void *cfs_mem_cache_alloc (cfs_mem_cache_t *, int);
224 extern void cfs_mem_cache_free (cfs_mem_cache_t *, void *);
229 typedef int (*shrink_callback)(int nr_to_scan, gfp_t gfp_mask);
230 struct cfs_shrinker {
232 int seeks; /* seeks to recreate an obj */
234 /* These are for internal use */
236 long nr; /* objs pending delete */
239 struct cfs_shrinker *cfs_set_shrinker(int seeks, shrink_callback cb);
240 void cfs_remove_shrinker(struct cfs_shrinker *s);
242 int start_shrinker_timer();
243 void stop_shrinker_timer();
246 * Page allocator slabs
249 extern cfs_mem_cache_t *cfs_page_t_slab;
250 extern cfs_mem_cache_t *cfs_page_p_slab;
253 #define CFS_DECL_MMSPACE
254 #define CFS_MMSPACE_OPEN do {} while(0)
255 #define CFS_MMSPACE_CLOSE do {} while(0)
258 #define cfs_mb() do {} while(0)
259 #define rmb() cfs_mb()
260 #define wmb() cfs_mb()
263 * MM defintions from (linux/mm.h)
266 #define CFS_DEFAULT_SEEKS 2 /* shrink seek */
268 #else /* !__KERNEL__ */
270 #include "../user-mem.h"
272 /* page alignmed buffer allocation */
273 void* pgalloc(size_t factor);
274 void pgfree(void * page);
276 #endif /* __KERNEL__ */
278 #endif /* __WINNT_CFS_MEM_H__ */