OSDN Git Service

staging: lustre: discard libcfs_kvzalloc and linux-mem.c
authorNeilBrown <neilb@suse.com>
Tue, 20 Feb 2018 02:23:37 +0000 (13:23 +1100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 22 Feb 2018 14:06:36 +0000 (15:06 +0100)
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: NeilBrown <neilb@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
20 files changed:
drivers/staging/lustre/include/linux/libcfs/libcfs.h
drivers/staging/lustre/lnet/libcfs/Makefile
drivers/staging/lustre/lnet/libcfs/linux/linux-mem.c [deleted file]
drivers/staging/lustre/lustre/llite/file.c
drivers/staging/lustre/lustre/lmv/lmv_obd.c
drivers/staging/lustre/lustre/lov/lov_ea.c
drivers/staging/lustre/lustre/lov/lov_io.c
drivers/staging/lustre/lustre/lov/lov_lock.c
drivers/staging/lustre/lustre/lov/lov_object.c
drivers/staging/lustre/lustre/lov/lov_pack.c
drivers/staging/lustre/lustre/mdc/mdc_locks.c
drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
drivers/staging/lustre/lustre/obdclass/llog.c
drivers/staging/lustre/lustre/obdclass/lustre_handles.c
drivers/staging/lustre/lustre/ptlrpc/client.c
drivers/staging/lustre/lustre/ptlrpc/sec.c
drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
drivers/staging/lustre/lustre/ptlrpc/sec_null.c
drivers/staging/lustre/lustre/ptlrpc/sec_plain.c
drivers/staging/lustre/lustre/ptlrpc/service.c

index 0392057..3927935 100644 (file)
@@ -112,8 +112,6 @@ static inline void *__container_of(void *ptr, unsigned long shift)
 
 #define _LIBCFS_H
 
-void *libcfs_kvzalloc(size_t size, gfp_t flags);
-
 extern struct miscdevice libcfs_dev;
 /**
  * The path of debug log dump upcall script.
index a51a8b0..b7dc7ac 100644 (file)
@@ -9,7 +9,6 @@ libcfs-linux-objs += linux-cpu.o
 libcfs-linux-objs += linux-module.o
 libcfs-linux-objs += linux-crypto.o
 libcfs-linux-objs += linux-crypto-adler.o
-libcfs-linux-objs += linux-mem.o
 
 libcfs-linux-objs := $(addprefix linux/,$(libcfs-linux-objs))
 
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-mem.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-mem.c
deleted file mode 100644 (file)
index f2c001b..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-// 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);
index 002a567..ca5faea 100644 (file)
@@ -3361,7 +3361,7 @@ static int ll_layout_fetch(struct inode *inode, struct ldlm_lock *lock)
                goto out;
        }
 
-       lvbdata = libcfs_kvzalloc(lmmsize, GFP_NOFS);
+       lvbdata = kvzalloc(lmmsize, GFP_NOFS);
        if (!lvbdata) {
                rc = -ENOMEM;
                goto out;
index c2c57f6..1796515 100644 (file)
@@ -1035,7 +1035,7 @@ static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
                                reqlen = offsetof(typeof(*hur),
                                                  hur_user_item[nr])
                                         + hur->hur_request.hr_data_len;
-                               req = libcfs_kvzalloc(reqlen, GFP_NOFS);
+                               req = kvzalloc(reqlen, GFP_NOFS);
                                if (!req)
                                        return -ENOMEM;
 
@@ -2733,7 +2733,7 @@ static int lmv_unpackmd(struct obd_export *exp, struct lmv_stripe_md **lsmp,
                lsm_size = lmv_stripe_md_size(0);
 
        if (!lsm) {
-               lsm = libcfs_kvzalloc(lsm_size, GFP_NOFS);
+               lsm = kvzalloc(lsm_size, GFP_NOFS);
                if (!lsm)
                        return -ENOMEM;
                allocated = true;
index d563dd7..c56a971 100644 (file)
@@ -89,7 +89,7 @@ struct lov_stripe_md *lsm_alloc_plain(u16 stripe_count)
        oinfo_ptrs_size = sizeof(struct lov_oinfo *) * stripe_count;
        lsm_size = sizeof(*lsm) + oinfo_ptrs_size;
 
-       lsm = libcfs_kvzalloc(lsm_size, GFP_NOFS);
+       lsm = kvzalloc(lsm_size, GFP_NOFS);
        if (!lsm)
                return NULL;
 
index c5f5d1b..c0dbf6c 100644 (file)
@@ -243,7 +243,7 @@ static int lov_io_subio_init(const struct lu_env *env, struct lov_io *lio,
         * when writing a page. -jay
         */
        lio->lis_subs =
-               libcfs_kvzalloc(lsm->lsm_stripe_count *
+               kvzalloc(lsm->lsm_stripe_count *
                                sizeof(lio->lis_subs[0]),
                                GFP_NOFS);
        if (lio->lis_subs) {
index 2fcdeb7..b029210 100644 (file)
@@ -145,7 +145,7 @@ static struct lov_lock *lov_lock_sub_init(const struct lu_env *env,
                        nr++;
        }
        LASSERT(nr > 0);
-       lovlck = libcfs_kvzalloc(offsetof(struct lov_lock, lls_sub[nr]),
+       lovlck = kvzalloc(offsetof(struct lov_lock, lls_sub[nr]),
                                 GFP_NOFS);
        if (!lovlck)
                return ERR_PTR(-ENOMEM);
index 86cd4f9..16cf9d5 100644 (file)
@@ -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;
        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);
        if (r0->lo_sub) {
                int psz = 0;
@@ -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)
                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) {
                rc = -ENOMEM;
                goto out;
index e5b11c4..b1060d0 100644 (file)
@@ -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 = libcfs_kvzalloc(lmmk_size, GFP_NOFS);
+       lmmk = kvzalloc(lmmk_size, GFP_NOFS);
        if (!lmmk) {
                rc = -ENOMEM;
                goto out;
index 3114907..695ef44 100644 (file)
@@ -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_it2str(it->it_op), lvb_len);
 
-               lmm = libcfs_kvzalloc(lvb_len, GFP_NOFS);
+               lmm = kvzalloc(lvb_len, GFP_NOFS);
                if (!lmm) {
                        LDLM_LOCK_PUT(lock);
                        return -ENOMEM;
index f8967fd..7bceee7 100644 (file)
@@ -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
         * 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) {
                CERROR("Cannot allocate control buffer of len %d\n",
                       hdr.ioc_len);
index ed31069..693e112 100644 (file)
@@ -155,7 +155,7 @@ int llog_init_handle(const struct lu_env *env, struct llog_handle *handle,
        LASSERT(!handle->lgh_hdr);
 
        LASSERT(chunk_size >= LLOG_MIN_CHUNK_SIZE);
-       llh = libcfs_kvzalloc(sizeof(*llh), GFP_KERNEL);
+       llh = kvzalloc(sizeof(*llh), GFP_KERNEL);
        if (!llh)
                return -ENOMEM;
        handle->lgh_hdr = llh;
@@ -240,7 +240,7 @@ static int llog_process_thread(void *arg)
        /* expect chunk_size to be power of two */
        LASSERT(is_power_of_2(chunk_size));
 
-       buf = libcfs_kvzalloc(chunk_size, GFP_NOFS);
+       buf = kvzalloc(chunk_size, GFP_NOFS);
        if (!buf) {
                lpi->lpi_rc = -ENOMEM;
                return 0;
index 9a63775..f53b1a3 100644 (file)
@@ -184,7 +184,7 @@ int class_handle_init(void)
 
        LASSERT(!handle_hash);
 
-       handle_hash = libcfs_kvzalloc(sizeof(*bucket) * HANDLE_HASH_SIZE,
+       handle_hash = kvzalloc(sizeof(*bucket) * HANDLE_HASH_SIZE,
                                      GFP_KERNEL);
        if (!handle_hash)
                return -ENOMEM;
index 7814626..d4c641d 100644 (file)
@@ -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);
                if (!req)
                        return i;
-               msg = libcfs_kvzalloc(size, GFP_KERNEL);
+               msg = kvzalloc(size, GFP_KERNEL);
                if (!msg) {
                        ptlrpc_request_cache_free(req);
                        return i;
index 90e3b30..f152ba1 100644 (file)
@@ -442,7 +442,7 @@ int sptlrpc_req_ctx_switch(struct ptlrpc_request *req,
        /* save request message */
        reqmsg_size = req->rq_reqlen;
        if (reqmsg_size != 0) {
-               reqmsg = libcfs_kvzalloc(reqmsg_size, GFP_NOFS);
+               reqmsg = kvzalloc(reqmsg_size, GFP_NOFS);
                if (!reqmsg)
                        return -ENOMEM;
                memcpy(reqmsg, req->rq_reqmsg, reqmsg_size);
@@ -1089,7 +1089,7 @@ int sptlrpc_cli_unwrap_early_reply(struct ptlrpc_request *req,
 
        early_size = req->rq_nob_received;
        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) {
                rc = -ENOMEM;
                goto err_req;
index 134ee72..2184022 100644 (file)
@@ -375,7 +375,7 @@ static inline void enc_pools_alloc(void)
 {
        LASSERT(page_pools.epp_max_pools);
        page_pools.epp_pools =
-               libcfs_kvzalloc(page_pools.epp_max_pools *
+               kvzalloc(page_pools.epp_max_pools *
                                sizeof(*page_pools.epp_pools),
                                GFP_NOFS);
 }
index 80cea0b..ecc387d 100644 (file)
@@ -158,7 +158,7 @@ int null_alloc_reqbuf(struct ptlrpc_sec *sec,
                int alloc_size = size_roundup_power2(msgsize);
 
                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)
                        return -ENOMEM;
 
@@ -201,7 +201,7 @@ int null_alloc_repbuf(struct ptlrpc_sec *sec,
 
        msgsize = size_roundup_power2(msgsize);
 
-       req->rq_repbuf = libcfs_kvzalloc(msgsize, GFP_NOFS);
+       req->rq_repbuf = kvzalloc(msgsize, GFP_NOFS);
        if (!req->rq_repbuf)
                return -ENOMEM;
 
@@ -246,7 +246,7 @@ int null_enlarge_reqbuf(struct ptlrpc_sec *sec,
        if (req->rq_reqbuf_len < newmsg_size) {
                alloc_size = size_roundup_power2(newmsg_size);
 
-               newbuf = libcfs_kvzalloc(alloc_size, GFP_NOFS);
+               newbuf = kvzalloc(alloc_size, GFP_NOFS);
                if (!newbuf)
                        return -ENOMEM;
 
@@ -317,7 +317,7 @@ int null_alloc_rs(struct ptlrpc_request *req, int msgsize)
                /* pre-allocated */
                LASSERT(rs->rs_size >= rs_size);
        } else {
-               rs = libcfs_kvzalloc(rs_size, GFP_NOFS);
+               rs = kvzalloc(rs_size, GFP_NOFS);
                if (!rs)
                        return -ENOMEM;
 
index 44e3405..ec3d9af 100644 (file)
@@ -562,7 +562,7 @@ int plain_alloc_reqbuf(struct ptlrpc_sec *sec,
                LASSERT(!req->rq_pool);
 
                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)
                        return -ENOMEM;
 
@@ -620,7 +620,7 @@ int plain_alloc_repbuf(struct ptlrpc_sec *sec,
 
        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)
                return -ENOMEM;
 
@@ -671,7 +671,7 @@ int plain_enlarge_reqbuf(struct ptlrpc_sec *sec,
        if (req->rq_reqbuf_len < newbuf_size) {
                newbuf_size = size_roundup_power2(newbuf_size);
 
-               newbuf = libcfs_kvzalloc(newbuf_size, GFP_NOFS);
+               newbuf = kvzalloc(newbuf_size, GFP_NOFS);
                if (!newbuf)
                        return -ENOMEM;
 
@@ -808,7 +808,7 @@ int plain_alloc_rs(struct ptlrpc_request *req, int msgsize)
                /* pre-allocated */
                LASSERT(rs->rs_size >= rs_size);
        } else {
-               rs = libcfs_kvzalloc(rs_size, GFP_NOFS);
+               rs = kvzalloc(rs_size, GFP_NOFS);
                if (!rs)
                        return -ENOMEM;
 
index 57e41e2..79d9f38 100644 (file)
@@ -1068,7 +1068,7 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req)
        reqcopy = ptlrpc_request_cache_alloc(GFP_NOFS);
        if (!reqcopy)
                return -ENOMEM;
-       reqmsg = libcfs_kvzalloc(req->rq_reqlen, GFP_NOFS);
+       reqmsg = kvzalloc(req->rq_reqlen, GFP_NOFS);
        if (!reqmsg) {
                rc = -ENOMEM;
                goto out_free;
@@ -2077,7 +2077,7 @@ static int ptlrpc_main(void *arg)
        }
 
        /* 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) {
                rc = -ENOMEM;
                goto out_srv_fini;