Whamcloud - gitweb
LU-1346 libcfs: replace cfs_ memory wrappers
[fs/lustre-release.git] / libcfs / libcfs / linux / linux-mem.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36 #define DEBUG_SUBSYSTEM S_LNET
37
38 #include <linux/mm.h>
39 #include <linux/vmalloc.h>
40 #include <linux/slab.h>
41 #include <linux/highmem.h>
42 #include <libcfs/libcfs.h>
43
44 void *
45 cfs_cpt_malloc(struct cfs_cpt_table *cptab, int cpt,
46                size_t nr_bytes, unsigned int flags)
47 {
48         void    *ptr;
49
50         ptr = kmalloc_node(nr_bytes, flags,
51                            cfs_cpt_spread_node(cptab, cpt));
52         if (ptr != NULL && (flags & __GFP_ZERO) != 0)
53                 memset(ptr, 0, nr_bytes);
54
55         return ptr;
56 }
57 EXPORT_SYMBOL(cfs_cpt_malloc);
58
59 void *
60 cfs_cpt_vmalloc(struct cfs_cpt_table *cptab, int cpt, size_t nr_bytes)
61 {
62         return vmalloc_node(nr_bytes, cfs_cpt_spread_node(cptab, cpt));
63 }
64 EXPORT_SYMBOL(cfs_cpt_vmalloc);
65
66 struct page *
67 cfs_page_cpt_alloc(struct cfs_cpt_table *cptab, int cpt, unsigned int flags)
68 {
69         return alloc_pages_node(cfs_cpt_spread_node(cptab, cpt), flags, 0);
70 }
71 EXPORT_SYMBOL(cfs_page_cpt_alloc);
72
73 void *
74 cfs_mem_cache_cpt_alloc(struct kmem_cache *cachep, struct cfs_cpt_table *cptab,
75                         int cpt, unsigned int flags)
76 {
77         return kmem_cache_alloc_node(cachep, flags,
78                                      cfs_cpt_spread_node(cptab, cpt));
79 }
80 EXPORT_SYMBOL(cfs_mem_cache_cpt_alloc);