2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 only,
4 * as published by the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful, but
7 * WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 * General Public License version 2 for more details (a copy is included
10 * in the LICENSE file that accompanied this code).
12 * You should have received a copy of the GNU General Public License
13 * version 2 along with this program; If not, see
14 * http://www.gnu.org/licenses/gpl-2.0.html
18 * This file creates a memory allocation primitive for Lustre, that
19 * allows to fallback to vmalloc allocations should regular kernel allocations
20 * fail due to size or system memory fragmentation.
22 * Author: Oleg Drokin <green@linuxhacker.ru>
26 * This file is part of Lustre, http://www.lustre.org/
27 * Lustre is a trademark of Seagate Technology.
29 #include <linux/slab.h>
30 #include <linux/vmalloc.h>
32 #include "../../../include/linux/libcfs/libcfs.h"
34 void *libcfs_kvzalloc(size_t size, gfp_t flags)
38 ret = kzalloc(size, flags | __GFP_NOWARN);
40 ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL);
43 EXPORT_SYMBOL(libcfs_kvzalloc);
45 void *libcfs_kvzalloc_cpt(struct cfs_cpt_table *cptab, int cpt, size_t size,
50 ret = kzalloc_node(size, flags | __GFP_NOWARN,
51 cfs_cpt_spread_node(cptab, cpt));
53 WARN_ON(!(flags & (__GFP_FS | __GFP_HIGH)));
54 ret = vmalloc_node(size, cfs_cpt_spread_node(cptab, cpt));
59 EXPORT_SYMBOL(libcfs_kvzalloc_cpt);