aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/lustre/lustre/libcfs/linux/linux-mem.c
blob: 025e2f0028ab1ee80680924fc4059506dffbeedc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 only,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License version 2 for more details (a copy is included
 * in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU General Public License
 * version 2 along with this program; If not, see
 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
 *
 */
/*
 * This file creates a memory allocation primitive for Lustre, that
 * allows to fallback to vmalloc allocations should regular kernel allocations
 * fail due to size or system memory fragmentation.
 *
 * Author: Oleg Drokin <green@linuxhacker.ru>
 *
 */
/*
 * This file is part of Lustre, http://www.lustre.org/
 * Lustre is a trademark of Seagate Technology.
 */
#include <linux/slab.h>
#include <linux/vmalloc.h>

#include "../../../include/linux/libcfs/libcfs.h"

void *libcfs_kvzalloc(size_t size, gfp_t flags)
{
	void *ret;

	ret = kzalloc(size, flags | __GFP_NOWARN);
	if (!ret)
		ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL);
	return ret;
}
EXPORT_SYMBOL(libcfs_kvzalloc);

void *libcfs_kvzalloc_cpt(struct cfs_cpt_table *cptab, int cpt, size_t size,
			  gfp_t flags)
{
	void *ret;

	ret = kzalloc_node(size, flags | __GFP_NOWARN,
			   cfs_cpt_spread_node(cptab, cpt));
	if (!ret) {
		WARN_ON(!(flags & (__GFP_FS|__GFP_HIGH)));
		ret = vmalloc_node(size, cfs_cpt_spread_node(cptab, cpt));
	}

	return ret;
}
EXPORT_SYMBOL(libcfs_kvzalloc_cpt);