Commit c90e1718 authored by NeilBrown's avatar NeilBrown Committed by Greg Kroah-Hartman

staging: lustre: discard libcfs_kvzalloc and linux-mem.c

The only interesting difference between libcfs_kvzalloc()
and kvzalloc() is that the former appears to work
with GFP_NOFS, which the latter gives a WARN_ON_ONCE()
when that is attempted.

Each libcfs_kvzalloc() should really be analysed
and either converted to a kzalloc() call if the size is never
more than a page, or to use GFP_KERNEL if no locks are held.

If there is ever a case where locks are held and a large allocation
is needed, then some other technique should be used.

It might be nice to not always blindly zero pages too...

For now, just convert libcfs_kvzalloc() calls to
kvzalloc(), and let the warning remind us that there is work to do.
Signed-off-by: default avatarNeilBrown <neilb@suse.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 033085ff
...@@ -112,8 +112,6 @@ static inline void *__container_of(void *ptr, unsigned long shift) ...@@ -112,8 +112,6 @@ 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);
extern struct miscdevice libcfs_dev; extern struct miscdevice libcfs_dev;
/** /**
* The path of debug log dump upcall script. * The path of debug log dump upcall script.
......
...@@ -9,7 +9,6 @@ libcfs-linux-objs += linux-cpu.o ...@@ -9,7 +9,6 @@ libcfs-linux-objs += linux-cpu.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))
......
// SPDX-License-Identifier: GPL-2.0
/*
* 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.gnu.org/licenses/gpl-2.0.html
*
*/
/*
* 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 <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);
...@@ -3361,7 +3361,7 @@ static int ll_layout_fetch(struct inode *inode, struct ldlm_lock *lock) ...@@ -3361,7 +3361,7 @@ static int ll_layout_fetch(struct inode *inode, struct ldlm_lock *lock)
goto out; goto out;
} }
lvbdata = libcfs_kvzalloc(lmmsize, GFP_NOFS); lvbdata = kvzalloc(lmmsize, GFP_NOFS);
if (!lvbdata) { if (!lvbdata) {
rc = -ENOMEM; rc = -ENOMEM;
goto out; goto out;
......
...@@ -1035,7 +1035,7 @@ static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp, ...@@ -1035,7 +1035,7 @@ static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
reqlen = offsetof(typeof(*hur), reqlen = offsetof(typeof(*hur),
hur_user_item[nr]) hur_user_item[nr])
+ hur->hur_request.hr_data_len; + hur->hur_request.hr_data_len;
req = libcfs_kvzalloc(reqlen, GFP_NOFS); req = kvzalloc(reqlen, GFP_NOFS);
if (!req) if (!req)
return -ENOMEM; return -ENOMEM;
...@@ -2733,7 +2733,7 @@ static int lmv_unpackmd(struct obd_export *exp, struct lmv_stripe_md **lsmp, ...@@ -2733,7 +2733,7 @@ static int lmv_unpackmd(struct obd_export *exp, struct lmv_stripe_md **lsmp,
lsm_size = lmv_stripe_md_size(0); lsm_size = lmv_stripe_md_size(0);
if (!lsm) { if (!lsm) {
lsm = libcfs_kvzalloc(lsm_size, GFP_NOFS); lsm = kvzalloc(lsm_size, GFP_NOFS);
if (!lsm) if (!lsm)
return -ENOMEM; return -ENOMEM;
allocated = true; allocated = true;
......
...@@ -89,7 +89,7 @@ struct lov_stripe_md *lsm_alloc_plain(u16 stripe_count) ...@@ -89,7 +89,7 @@ struct lov_stripe_md *lsm_alloc_plain(u16 stripe_count)
oinfo_ptrs_size = sizeof(struct lov_oinfo *) * stripe_count; oinfo_ptrs_size = sizeof(struct lov_oinfo *) * stripe_count;
lsm_size = sizeof(*lsm) + oinfo_ptrs_size; lsm_size = sizeof(*lsm) + oinfo_ptrs_size;
lsm = libcfs_kvzalloc(lsm_size, GFP_NOFS); lsm = kvzalloc(lsm_size, GFP_NOFS);
if (!lsm) if (!lsm)
return NULL; return NULL;
......
...@@ -243,7 +243,7 @@ static int lov_io_subio_init(const struct lu_env *env, struct lov_io *lio, ...@@ -243,7 +243,7 @@ static int lov_io_subio_init(const struct lu_env *env, struct lov_io *lio,
* when writing a page. -jay * when writing a page. -jay
*/ */
lio->lis_subs = lio->lis_subs =
libcfs_kvzalloc(lsm->lsm_stripe_count * kvzalloc(lsm->lsm_stripe_count *
sizeof(lio->lis_subs[0]), sizeof(lio->lis_subs[0]),
GFP_NOFS); GFP_NOFS);
if (lio->lis_subs) { if (lio->lis_subs) {
......
...@@ -145,7 +145,7 @@ static struct lov_lock *lov_lock_sub_init(const struct lu_env *env, ...@@ -145,7 +145,7 @@ static struct lov_lock *lov_lock_sub_init(const struct lu_env *env,
nr++; nr++;
} }
LASSERT(nr > 0); LASSERT(nr > 0);
lovlck = libcfs_kvzalloc(offsetof(struct lov_lock, lls_sub[nr]), lovlck = kvzalloc(offsetof(struct lov_lock, lls_sub[nr]),
GFP_NOFS); GFP_NOFS);
if (!lovlck) if (!lovlck)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
......
...@@ -242,7 +242,7 @@ static int lov_init_raid0(const struct lu_env *env, struct lov_device *dev, ...@@ -242,7 +242,7 @@ static int lov_init_raid0(const struct lu_env *env, struct lov_device *dev,
r0->lo_nr = lsm->lsm_stripe_count; r0->lo_nr = lsm->lsm_stripe_count;
LASSERT(r0->lo_nr <= lov_targets_nr(dev)); LASSERT(r0->lo_nr <= lov_targets_nr(dev));
r0->lo_sub = libcfs_kvzalloc(r0->lo_nr * sizeof(r0->lo_sub[0]), r0->lo_sub = kvzalloc(r0->lo_nr * sizeof(r0->lo_sub[0]),
GFP_NOFS); GFP_NOFS);
if (r0->lo_sub) { if (r0->lo_sub) {
int psz = 0; int psz = 0;
...@@ -1375,7 +1375,7 @@ static int lov_object_fiemap(const struct lu_env *env, struct cl_object *obj, ...@@ -1375,7 +1375,7 @@ static int lov_object_fiemap(const struct lu_env *env, struct cl_object *obj,
if (fiemap_count_to_size(fiemap->fm_extent_count) < buffer_size) if (fiemap_count_to_size(fiemap->fm_extent_count) < buffer_size)
buffer_size = fiemap_count_to_size(fiemap->fm_extent_count); buffer_size = fiemap_count_to_size(fiemap->fm_extent_count);
fm_local = libcfs_kvzalloc(buffer_size, GFP_NOFS); fm_local = kvzalloc(buffer_size, GFP_NOFS);
if (!fm_local) { if (!fm_local) {
rc = -ENOMEM; rc = -ENOMEM;
goto out; goto out;
......
...@@ -333,7 +333,7 @@ int lov_getstripe(struct lov_object *obj, struct lov_stripe_md *lsm, ...@@ -333,7 +333,7 @@ int lov_getstripe(struct lov_object *obj, struct lov_stripe_md *lsm,
lmmk_size = lov_mds_md_size(stripe_count, lsm->lsm_magic); lmmk_size = lov_mds_md_size(stripe_count, lsm->lsm_magic);
lmmk = libcfs_kvzalloc(lmmk_size, GFP_NOFS); lmmk = kvzalloc(lmmk_size, GFP_NOFS);
if (!lmmk) { if (!lmmk) {
rc = -ENOMEM; rc = -ENOMEM;
goto out; goto out;
......
...@@ -660,7 +660,7 @@ static int mdc_finish_enqueue(struct obd_export *exp, ...@@ -660,7 +660,7 @@ static int mdc_finish_enqueue(struct obd_export *exp,
LDLM_DEBUG(lock, "layout lock returned by: %s, lvb_len: %d", LDLM_DEBUG(lock, "layout lock returned by: %s, lvb_len: %d",
ldlm_it2str(it->it_op), lvb_len); ldlm_it2str(it->it_op), lvb_len);
lmm = libcfs_kvzalloc(lvb_len, GFP_NOFS); lmm = kvzalloc(lvb_len, GFP_NOFS);
if (!lmm) { if (!lmm) {
LDLM_LOCK_PUT(lock); LDLM_LOCK_PUT(lock);
return -ENOMEM; return -ENOMEM;
......
...@@ -180,7 +180,7 @@ int obd_ioctl_getdata(char **buf, int *len, void __user *arg) ...@@ -180,7 +180,7 @@ int obd_ioctl_getdata(char **buf, int *len, void __user *arg)
* obdfilter-survey is an example, which relies on ioctl. So we'd * obdfilter-survey is an example, which relies on ioctl. So we'd
* better avoid vmalloc on ioctl path. LU-66 * better avoid vmalloc on ioctl path. LU-66
*/ */
*buf = libcfs_kvzalloc(hdr.ioc_len, GFP_KERNEL); *buf = kvzalloc(hdr.ioc_len, GFP_KERNEL);
if (!*buf) { if (!*buf) {
CERROR("Cannot allocate control buffer of len %d\n", CERROR("Cannot allocate control buffer of len %d\n",
hdr.ioc_len); hdr.ioc_len);
......
...@@ -155,7 +155,7 @@ int llog_init_handle(const struct lu_env *env, struct llog_handle *handle, ...@@ -155,7 +155,7 @@ int llog_init_handle(const struct lu_env *env, struct llog_handle *handle,
LASSERT(!handle->lgh_hdr); LASSERT(!handle->lgh_hdr);
LASSERT(chunk_size >= LLOG_MIN_CHUNK_SIZE); LASSERT(chunk_size >= LLOG_MIN_CHUNK_SIZE);
llh = libcfs_kvzalloc(sizeof(*llh), GFP_KERNEL); llh = kvzalloc(sizeof(*llh), GFP_KERNEL);
if (!llh) if (!llh)
return -ENOMEM; return -ENOMEM;
handle->lgh_hdr = llh; handle->lgh_hdr = llh;
...@@ -240,7 +240,7 @@ static int llog_process_thread(void *arg) ...@@ -240,7 +240,7 @@ static int llog_process_thread(void *arg)
/* expect chunk_size to be power of two */ /* expect chunk_size to be power of two */
LASSERT(is_power_of_2(chunk_size)); LASSERT(is_power_of_2(chunk_size));
buf = libcfs_kvzalloc(chunk_size, GFP_NOFS); buf = kvzalloc(chunk_size, GFP_NOFS);
if (!buf) { if (!buf) {
lpi->lpi_rc = -ENOMEM; lpi->lpi_rc = -ENOMEM;
return 0; return 0;
......
...@@ -184,7 +184,7 @@ int class_handle_init(void) ...@@ -184,7 +184,7 @@ int class_handle_init(void)
LASSERT(!handle_hash); LASSERT(!handle_hash);
handle_hash = libcfs_kvzalloc(sizeof(*bucket) * HANDLE_HASH_SIZE, handle_hash = kvzalloc(sizeof(*bucket) * HANDLE_HASH_SIZE,
GFP_KERNEL); GFP_KERNEL);
if (!handle_hash) if (!handle_hash)
return -ENOMEM; return -ENOMEM;
......
...@@ -547,7 +547,7 @@ int ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq) ...@@ -547,7 +547,7 @@ int ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq)
req = ptlrpc_request_cache_alloc(GFP_KERNEL); req = ptlrpc_request_cache_alloc(GFP_KERNEL);
if (!req) if (!req)
return i; return i;
msg = libcfs_kvzalloc(size, GFP_KERNEL); msg = kvzalloc(size, GFP_KERNEL);
if (!msg) { if (!msg) {
ptlrpc_request_cache_free(req); ptlrpc_request_cache_free(req);
return i; return i;
......
...@@ -442,7 +442,7 @@ int sptlrpc_req_ctx_switch(struct ptlrpc_request *req, ...@@ -442,7 +442,7 @@ int sptlrpc_req_ctx_switch(struct ptlrpc_request *req,
/* save request message */ /* save request message */
reqmsg_size = req->rq_reqlen; reqmsg_size = req->rq_reqlen;
if (reqmsg_size != 0) { if (reqmsg_size != 0) {
reqmsg = libcfs_kvzalloc(reqmsg_size, GFP_NOFS); reqmsg = kvzalloc(reqmsg_size, GFP_NOFS);
if (!reqmsg) if (!reqmsg)
return -ENOMEM; return -ENOMEM;
memcpy(reqmsg, req->rq_reqmsg, reqmsg_size); memcpy(reqmsg, req->rq_reqmsg, reqmsg_size);
...@@ -1089,7 +1089,7 @@ int sptlrpc_cli_unwrap_early_reply(struct ptlrpc_request *req, ...@@ -1089,7 +1089,7 @@ int sptlrpc_cli_unwrap_early_reply(struct ptlrpc_request *req,
early_size = req->rq_nob_received; early_size = req->rq_nob_received;
early_bufsz = size_roundup_power2(early_size); early_bufsz = size_roundup_power2(early_size);
early_buf = libcfs_kvzalloc(early_bufsz, GFP_NOFS); early_buf = kvzalloc(early_bufsz, GFP_NOFS);
if (!early_buf) { if (!early_buf) {
rc = -ENOMEM; rc = -ENOMEM;
goto err_req; goto err_req;
......
...@@ -375,7 +375,7 @@ static inline void enc_pools_alloc(void) ...@@ -375,7 +375,7 @@ static inline void enc_pools_alloc(void)
{ {
LASSERT(page_pools.epp_max_pools); LASSERT(page_pools.epp_max_pools);
page_pools.epp_pools = page_pools.epp_pools =
libcfs_kvzalloc(page_pools.epp_max_pools * kvzalloc(page_pools.epp_max_pools *
sizeof(*page_pools.epp_pools), sizeof(*page_pools.epp_pools),
GFP_NOFS); GFP_NOFS);
} }
......
...@@ -158,7 +158,7 @@ int null_alloc_reqbuf(struct ptlrpc_sec *sec, ...@@ -158,7 +158,7 @@ int null_alloc_reqbuf(struct ptlrpc_sec *sec,
int alloc_size = size_roundup_power2(msgsize); int alloc_size = size_roundup_power2(msgsize);
LASSERT(!req->rq_pool); LASSERT(!req->rq_pool);
req->rq_reqbuf = libcfs_kvzalloc(alloc_size, GFP_NOFS); req->rq_reqbuf = kvzalloc(alloc_size, GFP_NOFS);
if (!req->rq_reqbuf) if (!req->rq_reqbuf)
return -ENOMEM; return -ENOMEM;
...@@ -201,7 +201,7 @@ int null_alloc_repbuf(struct ptlrpc_sec *sec, ...@@ -201,7 +201,7 @@ int null_alloc_repbuf(struct ptlrpc_sec *sec,
msgsize = size_roundup_power2(msgsize); msgsize = size_roundup_power2(msgsize);
req->rq_repbuf = libcfs_kvzalloc(msgsize, GFP_NOFS); req->rq_repbuf = kvzalloc(msgsize, GFP_NOFS);
if (!req->rq_repbuf) if (!req->rq_repbuf)
return -ENOMEM; return -ENOMEM;
...@@ -246,7 +246,7 @@ int null_enlarge_reqbuf(struct ptlrpc_sec *sec, ...@@ -246,7 +246,7 @@ int null_enlarge_reqbuf(struct ptlrpc_sec *sec,
if (req->rq_reqbuf_len < newmsg_size) { if (req->rq_reqbuf_len < newmsg_size) {
alloc_size = size_roundup_power2(newmsg_size); alloc_size = size_roundup_power2(newmsg_size);
newbuf = libcfs_kvzalloc(alloc_size, GFP_NOFS); newbuf = kvzalloc(alloc_size, GFP_NOFS);
if (!newbuf) if (!newbuf)
return -ENOMEM; return -ENOMEM;
...@@ -317,7 +317,7 @@ int null_alloc_rs(struct ptlrpc_request *req, int msgsize) ...@@ -317,7 +317,7 @@ int null_alloc_rs(struct ptlrpc_request *req, int msgsize)
/* pre-allocated */ /* pre-allocated */
LASSERT(rs->rs_size >= rs_size); LASSERT(rs->rs_size >= rs_size);
} else { } else {
rs = libcfs_kvzalloc(rs_size, GFP_NOFS); rs = kvzalloc(rs_size, GFP_NOFS);
if (!rs) if (!rs)
return -ENOMEM; return -ENOMEM;
......
...@@ -562,7 +562,7 @@ int plain_alloc_reqbuf(struct ptlrpc_sec *sec, ...@@ -562,7 +562,7 @@ int plain_alloc_reqbuf(struct ptlrpc_sec *sec,
LASSERT(!req->rq_pool); LASSERT(!req->rq_pool);
alloc_len = size_roundup_power2(alloc_len); alloc_len = size_roundup_power2(alloc_len);
req->rq_reqbuf = libcfs_kvzalloc(alloc_len, GFP_NOFS); req->rq_reqbuf = kvzalloc(alloc_len, GFP_NOFS);
if (!req->rq_reqbuf) if (!req->rq_reqbuf)
return -ENOMEM; return -ENOMEM;
...@@ -620,7 +620,7 @@ int plain_alloc_repbuf(struct ptlrpc_sec *sec, ...@@ -620,7 +620,7 @@ int plain_alloc_repbuf(struct ptlrpc_sec *sec,
alloc_len = size_roundup_power2(alloc_len); alloc_len = size_roundup_power2(alloc_len);
req->rq_repbuf = libcfs_kvzalloc(alloc_len, GFP_NOFS); req->rq_repbuf = kvzalloc(alloc_len, GFP_NOFS);
if (!req->rq_repbuf) if (!req->rq_repbuf)
return -ENOMEM; return -ENOMEM;
...@@ -671,7 +671,7 @@ int plain_enlarge_reqbuf(struct ptlrpc_sec *sec, ...@@ -671,7 +671,7 @@ int plain_enlarge_reqbuf(struct ptlrpc_sec *sec,
if (req->rq_reqbuf_len < newbuf_size) { if (req->rq_reqbuf_len < newbuf_size) {
newbuf_size = size_roundup_power2(newbuf_size); newbuf_size = size_roundup_power2(newbuf_size);
newbuf = libcfs_kvzalloc(newbuf_size, GFP_NOFS); newbuf = kvzalloc(newbuf_size, GFP_NOFS);
if (!newbuf) if (!newbuf)
return -ENOMEM; return -ENOMEM;
...@@ -808,7 +808,7 @@ int plain_alloc_rs(struct ptlrpc_request *req, int msgsize) ...@@ -808,7 +808,7 @@ int plain_alloc_rs(struct ptlrpc_request *req, int msgsize)
/* pre-allocated */ /* pre-allocated */
LASSERT(rs->rs_size >= rs_size); LASSERT(rs->rs_size >= rs_size);
} else { } else {
rs = libcfs_kvzalloc(rs_size, GFP_NOFS); rs = kvzalloc(rs_size, GFP_NOFS);
if (!rs) if (!rs)
return -ENOMEM; return -ENOMEM;
......
...@@ -1068,7 +1068,7 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req) ...@@ -1068,7 +1068,7 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req)
reqcopy = ptlrpc_request_cache_alloc(GFP_NOFS); reqcopy = ptlrpc_request_cache_alloc(GFP_NOFS);
if (!reqcopy) if (!reqcopy)
return -ENOMEM; return -ENOMEM;
reqmsg = libcfs_kvzalloc(req->rq_reqlen, GFP_NOFS); reqmsg = kvzalloc(req->rq_reqlen, GFP_NOFS);
if (!reqmsg) { if (!reqmsg) {
rc = -ENOMEM; rc = -ENOMEM;
goto out_free; goto out_free;
...@@ -2077,7 +2077,7 @@ static int ptlrpc_main(void *arg) ...@@ -2077,7 +2077,7 @@ static int ptlrpc_main(void *arg)
} }
/* Alloc reply state structure for this one */ /* Alloc reply state structure for this one */
rs = libcfs_kvzalloc(svc->srv_max_reply_size, GFP_NOFS); rs = kvzalloc(svc->srv_max_reply_size, GFP_NOFS);
if (!rs) { if (!rs) {
rc = -ENOMEM; rc = -ENOMEM;
goto out_srv_fini; goto out_srv_fini;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment