]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
staging: lustre: lnet-lib: opencode some alloc/free functions.
authorNeilBrown <neilb@suse.com>
Mon, 18 Dec 2017 00:46:30 +0000 (11:46 +1100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 8 Jan 2018 15:03:45 +0000 (16:03 +0100)
These functions just call LIBCFS_ALLOC() which in-turn
calls kvmalloc().
In none of these cases is the 'vmalloc' option needed.

LIBCFS_ALLOC also produces a warning if NULL is returned,
but that can be provided with CONFIG_SLAB_DEBUG.

LIBCFS_ALLOC zeros the memory, so we need to use
__GFP_ZERO too.

So with one exception where the alloc function is not trivial,
open-code the alloc and free functions using kmalloc and kfree.

Note that the 'size' used in lnet_md_alloc() is limited and less than
a page because LNET_MAX_IOV is 256, so kvmalloc is not needed.

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/include/linux/lnet/lib-lnet.h
drivers/staging/lustre/lnet/lnet/api-ni.c
drivers/staging/lustre/lnet/lnet/lib-eq.c
drivers/staging/lustre/lnet/lnet/lib-md.c
drivers/staging/lustre/lnet/lnet/lib-me.c
drivers/staging/lustre/lnet/lnet/lib-move.c
drivers/staging/lustre/lnet/lnet/lib-msg.c
drivers/staging/lustre/lnet/lnet/lib-ptl.c

index c1626726fa05517e787a5275887cecae53d6001e..df4c72507a15cddc77d32ea4fcb4ac0264ec223f 100644 (file)
@@ -181,21 +181,6 @@ lnet_net_lock_current(void)
 
 #define MAX_PORTALS            64
 
-static inline struct lnet_eq *
-lnet_eq_alloc(void)
-{
-       struct lnet_eq *eq;
-
-       LIBCFS_ALLOC(eq, sizeof(*eq));
-       return eq;
-}
-
-static inline void
-lnet_eq_free(struct lnet_eq *eq)
-{
-       LIBCFS_FREE(eq, sizeof(*eq));
-}
-
 static inline struct lnet_libmd *
 lnet_md_alloc(struct lnet_md *umd)
 {
@@ -211,7 +196,7 @@ lnet_md_alloc(struct lnet_md *umd)
                size = offsetof(struct lnet_libmd, md_iov.iov[niov]);
        }
 
-       LIBCFS_ALLOC(md, size);
+       md = kzalloc(size, GFP_NOFS);
 
        if (md) {
                /* Set here in case of early free */
@@ -223,52 +208,6 @@ lnet_md_alloc(struct lnet_md *umd)
        return md;
 }
 
-static inline void
-lnet_md_free(struct lnet_libmd *md)
-{
-       unsigned int size;
-
-       if (md->md_options & LNET_MD_KIOV)
-               size = offsetof(struct lnet_libmd, md_iov.kiov[md->md_niov]);
-       else
-               size = offsetof(struct lnet_libmd, md_iov.iov[md->md_niov]);
-
-       LIBCFS_FREE(md, size);
-}
-
-static inline struct lnet_me *
-lnet_me_alloc(void)
-{
-       struct lnet_me *me;
-
-       LIBCFS_ALLOC(me, sizeof(*me));
-       return me;
-}
-
-static inline void
-lnet_me_free(struct lnet_me *me)
-{
-       LIBCFS_FREE(me, sizeof(*me));
-}
-
-static inline struct lnet_msg *
-lnet_msg_alloc(void)
-{
-       struct lnet_msg *msg;
-
-       LIBCFS_ALLOC(msg, sizeof(*msg));
-
-       /* no need to zero, LIBCFS_ALLOC does for us */
-       return msg;
-}
-
-static inline void
-lnet_msg_free(struct lnet_msg *msg)
-{
-       LASSERT(!msg->msg_onactivelist);
-       LIBCFS_FREE(msg, sizeof(*msg));
-}
-
 struct lnet_libhandle *lnet_res_lh_lookup(struct lnet_res_container *rec,
                                          __u64 cookie);
 void lnet_res_lh_initialize(struct lnet_res_container *rec,
index 7caff290c146a4c72768f515a82da671ea2cf3cf..30d0999118c7954c7bee6db371d829ab1a5dbd5d 100644 (file)
@@ -384,10 +384,10 @@ lnet_res_container_cleanup(struct lnet_res_container *rec)
 
                list_del_init(e);
                if (rec->rec_type == LNET_COOKIE_TYPE_EQ) {
-                       lnet_eq_free(list_entry(e, struct lnet_eq, eq_list));
+                       kfree(list_entry(e, struct lnet_eq, eq_list));
 
                } else if (rec->rec_type == LNET_COOKIE_TYPE_MD) {
-                       lnet_md_free(list_entry(e, struct lnet_libmd, md_list));
+                       kfree(list_entry(e, struct lnet_libmd, md_list));
 
                } else { /* NB: Active MEs should be attached on portals */
                        LBUG();
index daf74427700315127a664ac154979e1f84999db5..7a4d1f7a693eb845675d71a1e4af012066d7aa01 100644 (file)
@@ -90,7 +90,7 @@ LNetEQAlloc(unsigned int count, lnet_eq_handler_t callback,
        if (!count && callback == LNET_EQ_HANDLER_NONE)
                return -EINVAL;
 
-       eq = lnet_eq_alloc();
+       eq = kzalloc(sizeof(*eq), GFP_NOFS);
        if (!eq)
                return -ENOMEM;
 
@@ -138,7 +138,7 @@ LNetEQAlloc(unsigned int count, lnet_eq_handler_t callback,
        if (eq->eq_refs)
                cfs_percpt_free(eq->eq_refs);
 
-       lnet_eq_free(eq);
+       kfree(eq);
        return -ENOMEM;
 }
 EXPORT_SYMBOL(LNetEQAlloc);
@@ -197,7 +197,7 @@ LNetEQFree(struct lnet_handle_eq eqh)
 
        lnet_res_lh_invalidate(&eq->eq_lh);
        list_del(&eq->eq_list);
-       lnet_eq_free(eq);
+       kfree(eq);
  out:
        lnet_eq_wait_unlock();
        lnet_res_unlock(LNET_LOCK_EX);
index ac5b9593d59716b7e92a15b23c36cf87a5701469..8a22514aaf713ab7c00dfc71114c250de71d8cfb 100644 (file)
@@ -81,7 +81,7 @@ lnet_md_unlink(struct lnet_libmd *md)
 
        LASSERT(!list_empty(&md->md_list));
        list_del_init(&md->md_list);
-       lnet_md_free(md);
+       kfree(md);
 }
 
 static int
@@ -173,7 +173,7 @@ lnet_md_link(struct lnet_libmd *md, struct lnet_handle_eq eq_handle, int cpt)
        /*
         * NB we are passed an allocated, but inactive md.
         * if we return success, caller may lnet_md_unlink() it.
-        * otherwise caller may only lnet_md_free() it.
+        * otherwise caller may only kfree() it.
         */
        /*
         * This implementation doesn't know how to create START events or
@@ -329,7 +329,7 @@ LNetMDAttach(struct lnet_handle_me meh, struct lnet_md umd,
 out_unlock:
        lnet_res_unlock(cpt);
 out_free:
-       lnet_md_free(md);
+       kfree(md);
        return rc;
 }
 EXPORT_SYMBOL(LNetMDAttach);
@@ -390,7 +390,7 @@ LNetMDBind(struct lnet_md umd, enum lnet_unlink unlink,
 out_unlock:
        lnet_res_unlock(cpt);
 out_free:
-       lnet_md_free(md);
+       kfree(md);
 
        return rc;
 }
index dd5d3cf6d3e22e2db46a65d5041cde411c8087e7..672e37bdd045c443e3dace6b9081f60621d81d54 100644 (file)
@@ -90,7 +90,7 @@ LNetMEAttach(unsigned int portal,
        if (!mtable) /* can't match portal type */
                return -EPERM;
 
-       me = lnet_me_alloc();
+       me = kzalloc(sizeof(*me), GFP_NOFS);
        if (!me)
                return -ENOMEM;
 
@@ -157,7 +157,7 @@ LNetMEInsert(struct lnet_handle_me current_meh,
        if (pos == LNET_INS_LOCAL)
                return -EPERM;
 
-       new_me = lnet_me_alloc();
+       new_me = kzalloc(sizeof(*new_me), GFP_NOFS);
        if (!new_me)
                return -ENOMEM;
 
@@ -167,7 +167,7 @@ LNetMEInsert(struct lnet_handle_me current_meh,
 
        current_me = lnet_handle2me(&current_meh);
        if (!current_me) {
-               lnet_me_free(new_me);
+               kfree(new_me);
 
                lnet_res_unlock(cpt);
                return -ENOENT;
@@ -178,7 +178,7 @@ LNetMEInsert(struct lnet_handle_me current_meh,
        ptl = the_lnet.ln_portals[current_me->me_portal];
        if (lnet_ptl_is_unique(ptl)) {
                /* nosense to insertion on unique portal */
-               lnet_me_free(new_me);
+               kfree(new_me);
                lnet_res_unlock(cpt);
                return -EPERM;
        }
@@ -270,5 +270,5 @@ lnet_me_unlink(struct lnet_me *me)
        }
 
        lnet_res_lh_invalidate(&me->me_lh);
-       lnet_me_free(me);
+       kfree(me);
 }
index 68d16ffec980e98dc4c4e5d672a005e157ad8b57..137e3ab970dc7d8c36c05e62e81ac41e88a2e0c2 100644 (file)
@@ -1769,7 +1769,7 @@ lnet_parse(struct lnet_ni *ni, struct lnet_hdr *hdr, lnet_nid_t from_nid,
                goto drop;
        }
 
-       msg = lnet_msg_alloc();
+       msg = kzalloc(sizeof(*msg), GFP_NOFS);
        if (!msg) {
                CERROR("%s, src %s: Dropping %s (out of memory)\n",
                       libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
@@ -1777,7 +1777,7 @@ lnet_parse(struct lnet_ni *ni, struct lnet_hdr *hdr, lnet_nid_t from_nid,
                goto drop;
        }
 
-       /* msg zeroed in lnet_msg_alloc;
+       /* msg zeroed by kzalloc()
         * i.e. flags all clear, pointers NULL etc
         */
        msg->msg_type = type;
@@ -1812,7 +1812,7 @@ lnet_parse(struct lnet_ni *ni, struct lnet_hdr *hdr, lnet_nid_t from_nid,
                CERROR("%s, src %s: Dropping %s (error %d looking up sender)\n",
                       libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
                       lnet_msgtyp2str(type), rc);
-               lnet_msg_free(msg);
+               kfree(msg);
                if (rc == -ESHUTDOWN)
                        /* We are shutting down. Don't do anything more */
                        return 0;
@@ -2010,7 +2010,7 @@ LNetPut(lnet_nid_t self, struct lnet_handle_md mdh, enum lnet_ack_req ack,
                return -EIO;
        }
 
-       msg = lnet_msg_alloc();
+       msg = kzalloc(sizeof(*msg), GFP_NOFS);
        if (!msg) {
                CERROR("Dropping PUT to %s: ENOMEM on struct lnet_msg\n",
                       libcfs_id2str(target));
@@ -2031,7 +2031,7 @@ LNetPut(lnet_nid_t self, struct lnet_handle_md mdh, enum lnet_ack_req ack,
                               md->md_me->me_portal);
                lnet_res_unlock(cpt);
 
-               lnet_msg_free(msg);
+               kfree(msg);
                return -ENOENT;
        }
 
@@ -2086,7 +2086,7 @@ lnet_create_reply_msg(struct lnet_ni *ni, struct lnet_msg *getmsg)
         * CAVEAT EMPTOR: 'getmsg' is the original GET, which is freed when
         * lnet_finalize() is called on it, so the LND must call this first
         */
-       struct lnet_msg *msg = lnet_msg_alloc();
+       struct lnet_msg *msg = kzalloc(sizeof(*msg), GFP_NOFS);
        struct lnet_libmd *getmd = getmsg->msg_md;
        struct lnet_process_id peer_id = getmsg->msg_target;
        int cpt;
@@ -2147,7 +2147,7 @@ lnet_create_reply_msg(struct lnet_ni *ni, struct lnet_msg *getmsg)
        lnet_net_unlock(cpt);
 
        if (msg)
-               lnet_msg_free(msg);
+               kfree(msg);
 
        return NULL;
 }
@@ -2215,7 +2215,7 @@ LNetGet(lnet_nid_t self, struct lnet_handle_md mdh,
                return -EIO;
        }
 
-       msg = lnet_msg_alloc();
+       msg = kzalloc(sizeof(*msg), GFP_NOFS);
        if (!msg) {
                CERROR("Dropping GET to %s: ENOMEM on struct lnet_msg\n",
                       libcfs_id2str(target));
@@ -2236,7 +2236,7 @@ LNetGet(lnet_nid_t self, struct lnet_handle_md mdh,
 
                lnet_res_unlock(cpt);
 
-               lnet_msg_free(msg);
+               kfree(msg);
                return -ENOENT;
        }
 
index c72ef05b242000c4a5055c35f55983d04ce140bf..ff6c43323fb5f5a0e9b9c6238ae182586ae35867 100644 (file)
@@ -433,7 +433,7 @@ lnet_complete_msg_locked(struct lnet_msg *msg, int cpt)
        }
 
        lnet_msg_decommit(msg, cpt, status);
-       lnet_msg_free(msg);
+       kfree(msg);
        return 0;
 }
 
@@ -466,7 +466,7 @@ lnet_finalize(struct lnet_ni *ni, struct lnet_msg *msg, int status)
        if (!msg->msg_tx_committed && !msg->msg_rx_committed) {
                /* not committed to network yet */
                LASSERT(!msg->msg_onactivelist);
-               lnet_msg_free(msg);
+               kfree(msg);
                return;
        }
 
@@ -546,7 +546,7 @@ lnet_msg_container_cleanup(struct lnet_msg_container *container)
                LASSERT(msg->msg_onactivelist);
                msg->msg_onactivelist = 0;
                list_del(&msg->msg_activelist);
-               lnet_msg_free(msg);
+               kfree(msg);
                count++;
        }
 
index 8ae93bf6fd1baf05ea5dc8bb7882661ccc312a20..519cfebaaa8850d431b2f51c93550a3eaca40f23 100644 (file)
@@ -771,7 +771,7 @@ lnet_ptl_cleanup(struct lnet_portal *ptl)
                                                struct lnet_me, me_list);
                                CERROR("Active ME %p on exit\n", me);
                                list_del(&me->me_list);
-                               lnet_me_free(me);
+                               kfree(me);
                        }
                }
                /* the extra entry is for MEs with ignore bits */