Whamcloud - gitweb
0887a31419937640777a1aa539986ccd9c445bed
[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         return kmalloc_node(nr_bytes, flags,
49                             cfs_cpt_spread_node(cptab, cpt));
50 }
51 EXPORT_SYMBOL(cfs_cpt_malloc);
52
53 void *
54 cfs_cpt_vzalloc(struct cfs_cpt_table *cptab, int cpt, size_t nr_bytes)
55 {
56         /* vzalloc_node() sets __GFP_FS by default but no current Kernel
57          * exported entry-point allows for both a NUMA node specification
58          * and a custom allocation flags mask. This may be an issue since
59          * __GFP_FS usage can cause some deadlock situations in our code,
60          * like when memory reclaim started, within the same context of a
61          * thread doing FS operations, that can also attempt conflicting FS
62          * operations, ...
63          */
64         return vzalloc_node(nr_bytes, cfs_cpt_spread_node(cptab, cpt));
65 }
66 EXPORT_SYMBOL(cfs_cpt_vzalloc);
67
68 struct page *
69 cfs_page_cpt_alloc(struct cfs_cpt_table *cptab, int cpt, unsigned int flags)
70 {
71         return alloc_pages_node(cfs_cpt_spread_node(cptab, cpt), flags, 0);
72 }
73 EXPORT_SYMBOL(cfs_page_cpt_alloc);
74
75 void *
76 cfs_mem_cache_cpt_alloc(struct kmem_cache *cachep, struct cfs_cpt_table *cptab,
77                         int cpt, unsigned int flags)
78 {
79         return kmem_cache_alloc_node(cachep, flags,
80                                      cfs_cpt_spread_node(cptab, cpt));
81 }
82 EXPORT_SYMBOL(cfs_mem_cache_cpt_alloc);