1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #define DEBUG_SUBSYSTEM S_LNET
24 #include <linux/vmalloc.h>
25 #include <linux/slab.h>
26 #include <linux/highmem.h>
27 #include <libcfs/libcfs.h>
29 static unsigned int cfs_alloc_flags_to_gfp(u_int32_t flags)
31 unsigned int mflags = 0;
33 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
34 if (flags & CFS_ALLOC_ATOMIC)
36 else if (flags & CFS_ALLOC_WAIT)
39 mflags |= (__GFP_HIGH | __GFP_WAIT);
40 if (flags & CFS_ALLOC_IO)
41 mflags |= __GFP_IO | __GFP_HIGHIO;
43 if (flags & CFS_ALLOC_ATOMIC)
47 if (flags & CFS_ALLOC_NOWARN)
48 mflags |= __GFP_NOWARN;
49 if (flags & CFS_ALLOC_IO)
52 if (flags & CFS_ALLOC_FS)
54 if (flags & CFS_ALLOC_HIGH)
60 cfs_alloc(size_t nr_bytes, u_int32_t flags)
64 ptr = kmalloc(nr_bytes, cfs_alloc_flags_to_gfp(flags));
65 if (ptr != NULL && (flags & CFS_ALLOC_ZERO))
66 memset(ptr, 0, nr_bytes);
77 cfs_alloc_large(size_t nr_bytes)
79 return vmalloc(nr_bytes);
83 cfs_free_large(void *addr)
88 cfs_page_t *cfs_alloc_pages(unsigned int flags, unsigned int order)
91 * XXX nikita: do NOT call portals_debug_msg() (CDEBUG/ENTRY/EXIT)
92 * from here: this will lead to infinite recursion.
94 return alloc_pages(cfs_alloc_flags_to_gfp(flags), order);
97 void __cfs_free_pages(cfs_page_t *page, unsigned int order)
99 __free_pages(page, order);
103 cfs_mem_cache_create (const char *name, size_t size, size_t offset,
106 return kmem_cache_create(name, size, offset, flags, NULL, NULL);
110 cfs_mem_cache_destroy (cfs_mem_cache_t * cachep)
112 #ifdef HAVE_KMEM_CACHE_DESTROY_INT
113 return kmem_cache_destroy(cachep);
115 kmem_cache_destroy(cachep);
121 cfs_mem_cache_alloc(cfs_mem_cache_t *cachep, int flags)
123 return kmem_cache_alloc(cachep, cfs_alloc_flags_to_gfp(flags));
127 cfs_mem_cache_free(cfs_mem_cache_t *cachep, void *objp)
129 return kmem_cache_free(cachep, objp);
132 EXPORT_SYMBOL(cfs_alloc);
133 EXPORT_SYMBOL(cfs_free);
134 EXPORT_SYMBOL(cfs_alloc_large);
135 EXPORT_SYMBOL(cfs_free_large);
136 EXPORT_SYMBOL(cfs_alloc_pages);
137 EXPORT_SYMBOL(__cfs_free_pages);
138 EXPORT_SYMBOL(cfs_mem_cache_create);
139 EXPORT_SYMBOL(cfs_mem_cache_destroy);
140 EXPORT_SYMBOL(cfs_mem_cache_alloc);
141 EXPORT_SYMBOL(cfs_mem_cache_free);