staging/lustre: Always try kmalloc first for OBD_ALLOC_LARGE
Create libcfs_kvzalloc and libcfs_kvzalloc_cpt that are designed to replace OBD_ALLOC_LARGE and OBD_CPT_ALLOC_LARGE. Not a drop-in replacement as they also take gfp flags armument for more flexibility. Signed-off-by: Oleg Drokin <green@linuxhacker.ru> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
640f7d6938
commit
99d56ff7c1
4 changed files with 67 additions and 21 deletions
|
@ -184,4 +184,8 @@ static inline void *__container_of(void *ptr, unsigned long shift)
|
||||||
|
|
||||||
#define _LIBCFS_H
|
#define _LIBCFS_H
|
||||||
|
|
||||||
|
void *libcfs_kvzalloc(size_t size, gfp_t flags);
|
||||||
|
void *libcfs_kvzalloc_cpt(struct cfs_cpt_table *cptab, int cpt, size_t size,
|
||||||
|
gfp_t flags);
|
||||||
|
|
||||||
#endif /* _LIBCFS_H */
|
#endif /* _LIBCFS_H */
|
||||||
|
|
|
@ -676,37 +676,19 @@ do { \
|
||||||
__OBD_VMALLOC_VEROBSE(ptr, cptab, cpt, size)
|
__OBD_VMALLOC_VEROBSE(ptr, cptab, cpt, size)
|
||||||
|
|
||||||
|
|
||||||
/* Allocations above this size are considered too big and could not be done
|
|
||||||
* atomically.
|
|
||||||
*
|
|
||||||
* Be very careful when changing this value, especially when decreasing it,
|
|
||||||
* since vmalloc in Linux doesn't perform well on multi-cores system, calling
|
|
||||||
* vmalloc in critical path would hurt performance badly. See LU-66.
|
|
||||||
*/
|
|
||||||
#define OBD_ALLOC_BIG (4 * PAGE_CACHE_SIZE)
|
|
||||||
|
|
||||||
#define OBD_ALLOC_LARGE(ptr, size) \
|
#define OBD_ALLOC_LARGE(ptr, size) \
|
||||||
do { \
|
do { \
|
||||||
if (size > OBD_ALLOC_BIG) \
|
ptr = libcfs_kvzalloc(size, GFP_NOFS); \
|
||||||
OBD_VMALLOC(ptr, size); \
|
|
||||||
else \
|
|
||||||
OBD_ALLOC(ptr, size); \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define OBD_CPT_ALLOC_LARGE(ptr, cptab, cpt, size) \
|
#define OBD_CPT_ALLOC_LARGE(ptr, cptab, cpt, size) \
|
||||||
do { \
|
do { \
|
||||||
if (size > OBD_ALLOC_BIG) \
|
ptr = libcfs_kvzalloc_cpt(cptab, cpt, size, GFP_NOFS); \
|
||||||
OBD_CPT_VMALLOC(ptr, cptab, cpt, size); \
|
|
||||||
else \
|
|
||||||
OBD_CPT_ALLOC(ptr, cptab, cpt, size); \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define OBD_FREE_LARGE(ptr, size) \
|
#define OBD_FREE_LARGE(ptr, size) \
|
||||||
do { \
|
do { \
|
||||||
if (size > OBD_ALLOC_BIG) \
|
kvfree(ptr); \
|
||||||
OBD_VFREE(ptr, size); \
|
|
||||||
else \
|
|
||||||
OBD_FREE(ptr, size); \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ libcfs-linux-objs += linux-curproc.o
|
||||||
libcfs-linux-objs += linux-module.o
|
libcfs-linux-objs += linux-module.o
|
||||||
libcfs-linux-objs += linux-crypto.o
|
libcfs-linux-objs += linux-crypto.o
|
||||||
libcfs-linux-objs += linux-crypto-adler.o
|
libcfs-linux-objs += linux-crypto-adler.o
|
||||||
|
libcfs-linux-objs += linux-mem.o
|
||||||
|
|
||||||
libcfs-linux-objs := $(addprefix linux/,$(libcfs-linux-objs))
|
libcfs-linux-objs := $(addprefix linux/,$(libcfs-linux-objs))
|
||||||
|
|
||||||
|
|
59
drivers/staging/lustre/lustre/libcfs/linux/linux-mem.c
Normal file
59
drivers/staging/lustre/lustre/libcfs/linux/linux-mem.c
Normal file
|
@ -0,0 +1,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);
|
Loading…
Add table
Reference in a new issue