From patchwork Thu Feb 27 21:17:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Simmons X-Patchwork-Id: 11410869 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8B819924 for ; Thu, 27 Feb 2020 21:48:57 +0000 (UTC) Received: from pdx1-mailman02.dreamhost.com (pdx1-mailman02.dreamhost.com [64.90.62.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7414824690 for ; Thu, 27 Feb 2020 21:48:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7414824690 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lustre-devel-bounces@lists.lustre.org Received: from pdx1-mailman02.dreamhost.com (localhost [IPv6:::1]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 4761034A543; Thu, 27 Feb 2020 13:39:21 -0800 (PST) X-Original-To: lustre-devel@lists.lustre.org Delivered-To: lustre-devel-lustre.org@pdx1-mailman02.dreamhost.com Received: from smtp3.ccs.ornl.gov (smtp3.ccs.ornl.gov [160.91.203.39]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id C13BA21FC75 for ; Thu, 27 Feb 2020 13:21:27 -0800 (PST) Received: from star.ccs.ornl.gov (star.ccs.ornl.gov [160.91.202.134]) by smtp3.ccs.ornl.gov (Postfix) with ESMTP id 64BD8A159; Thu, 27 Feb 2020 16:18:20 -0500 (EST) Received: by star.ccs.ornl.gov (Postfix, from userid 2004) id 63B9746A; Thu, 27 Feb 2020 16:18:20 -0500 (EST) From: James Simmons To: Andreas Dilger , Oleg Drokin , NeilBrown Date: Thu, 27 Feb 2020 16:17:54 -0500 Message-Id: <1582838290-17243-607-git-send-email-jsimmons@infradead.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1582838290-17243-1-git-send-email-jsimmons@infradead.org> References: <1582838290-17243-1-git-send-email-jsimmons@infradead.org> Subject: [lustre-devel] [PATCH 606/622] lnet: avoid extra memory consumption X-BeenThere: lustre-devel@lists.lustre.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "For discussing Lustre software development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexey Lyashkov , Lustre Development List MIME-Version: 1.0 Errors-To: lustre-devel-bounces@lists.lustre.org Sender: "lustre-devel" From: Alexey Lyashkov use slab allocation for the rsp_tracker and lnet_message structs to avoid memory fragmnetation. Cray-bug-id: LUS-8190 WC-bug-id: https://jira.whamcloud.com/browse/LU-13036 Lustre-commit: a3ce59ae2c62 ("LU-13036 lnet: avoid extra memory consumption") Signed-off-by: Alexey Lyashkov Reviewed-on: https://review.whamcloud.com/36897 Reviewed-by: Alexandr Boyko Reviewed-by: Alexander Zarochentsev Reviewed-by: Chris Horn Reviewed-by: Neil Brown Reviewed-by: Oleg Drokin Signed-off-by: James Simmons --- include/linux/lnet/lib-lnet.h | 13 ++++++++++--- net/lnet/lnet/api-ni.c | 28 ++++++++++++++++++++++++---- net/lnet/lnet/lib-move.c | 11 ++++++----- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/include/linux/lnet/lib-lnet.h b/include/linux/lnet/lib-lnet.h index a8051fe..de0cef0 100644 --- a/include/linux/lnet/lib-lnet.h +++ b/include/linux/lnet/lib-lnet.h @@ -83,13 +83,17 @@ /* default timeout */ #define DEFAULT_PEER_TIMEOUT 180 +#define LNET_LND_DEFAULT_TIMEOUT 5 + +bool lnet_is_route_alive(struct lnet_route *route); #define LNET_SMALL_MD_SIZE offsetof(struct lnet_libmd, md_iov.iov[1]) extern struct kmem_cache *lnet_mes_cachep; /* MEs kmem_cache */ extern struct kmem_cache *lnet_small_mds_cachep; /* <= LNET_SMALL_MD_SIZE bytes * MDs kmem_cache */ -#define LNET_LND_DEFAULT_TIMEOUT 5 +extern struct kmem_cache *lnet_rspt_cachep; +extern struct kmem_cache *lnet_msg_cachep; bool lnet_is_route_alive(struct lnet_route *route); bool lnet_is_gateway_alive(struct lnet_peer *gw); @@ -417,19 +421,22 @@ void lnet_res_lh_initialize(struct lnet_res_container *rec, { struct lnet_rsp_tracker *rspt; - rspt = kzalloc(sizeof(*rspt), GFP_NOFS); + rspt = kmem_cache_zalloc(lnet_rspt_cachep, GFP_NOFS); if (rspt) { lnet_net_lock(cpt); the_lnet.ln_counters[cpt]->lct_health.lch_rst_alloc++; lnet_net_unlock(cpt); } + CDEBUG(D_MALLOC, "rspt alloc %p\n", rspt); return rspt; } static inline void lnet_rspt_free(struct lnet_rsp_tracker *rspt, int cpt) { - kfree(rspt); + CDEBUG(D_MALLOC, "rspt free %p\n", rspt); + + kmem_cache_free(lnet_rspt_cachep, rspt); lnet_net_lock(cpt); the_lnet.ln_counters[cpt]->lct_health.lch_rst_alloc--; lnet_net_unlock(cpt); diff --git a/net/lnet/lnet/api-ni.c b/net/lnet/lnet/api-ni.c index 852bb0c..b9c38f3 100644 --- a/net/lnet/lnet/api-ni.c +++ b/net/lnet/lnet/api-ni.c @@ -494,9 +494,11 @@ static int lnet_discover(struct lnet_process_id id, u32 force, struct kmem_cache *lnet_small_mds_cachep; /* <= LNET_SMALL_MD_SIZE bytes * MDs kmem_cache */ +struct kmem_cache *lnet_rspt_cachep; /* response tracker cache */ +struct kmem_cache *lnet_msg_cachep; static int -lnet_descriptor_setup(void) +lnet_slab_setup(void) { /* create specific kmem_cache for MEs and small MDs (i.e., originally * allocated in kmem_cache). @@ -512,12 +514,30 @@ static int lnet_discover(struct lnet_process_id id, u32 force, if (!lnet_small_mds_cachep) return -ENOMEM; + lnet_rspt_cachep = kmem_cache_create("lnet_rspt", + sizeof(struct lnet_rsp_tracker), + 0, 0, NULL); + if (!lnet_rspt_cachep) + return -ENOMEM; + + lnet_msg_cachep = kmem_cache_create("lnet_msg", + sizeof(struct lnet_msg), + 0, 0, NULL); + if (!lnet_msg_cachep) + return -ENOMEM; + return 0; } static void -lnet_descriptor_cleanup(void) +lnet_slab_cleanup(void) { + kmem_cache_destroy(lnet_msg_cachep); + lnet_msg_cachep = NULL; + + kmem_cache_destroy(lnet_rspt_cachep); + lnet_rspt_cachep = NULL; + kmem_cache_destroy(lnet_small_mds_cachep); lnet_small_mds_cachep = NULL; @@ -1081,7 +1101,7 @@ struct list_head ** LNetInvalidateEQHandle(&the_lnet.ln_mt_eqh); init_completion(&the_lnet.ln_started); - rc = lnet_descriptor_setup(); + rc = lnet_slab_setup(); if (rc != 0) goto failed; @@ -1188,7 +1208,7 @@ struct list_head ** the_lnet.ln_counters = NULL; } lnet_destroy_remote_nets_table(); - lnet_descriptor_cleanup(); + lnet_slab_cleanup(); return 0; } diff --git a/net/lnet/lnet/lib-move.c b/net/lnet/lnet/lib-move.c index 47d5389..cd36d52 100644 --- a/net/lnet/lnet/lib-move.c +++ b/net/lnet/lnet/lib-move.c @@ -4186,7 +4186,7 @@ void lnet_monitor_thr_stop(void) } } - msg = kzalloc(sizeof(*msg), GFP_NOFS); + msg = kmem_cache_zalloc(lnet_msg_cachep, GFP_NOFS); if (!msg) { CERROR("%s, src %s: Dropping %s (out of memory)\n", libcfs_nid2str(from_nid), libcfs_nid2str(src_nid), @@ -4194,7 +4194,7 @@ void lnet_monitor_thr_stop(void) goto drop; } - /* msg zeroed by kzalloc() + /* msg zeroed by kmem_cache_zalloc(). * i.e. flags all clear, pointers NULL etc */ msg->msg_type = type; @@ -4475,7 +4475,7 @@ void lnet_monitor_thr_stop(void) return -EIO; } - msg = kzalloc(sizeof(*msg), GFP_NOFS); + msg = kmem_cache_zalloc(lnet_msg_cachep, GFP_NOFS); if (!msg) { CERROR("Dropping PUT to %s: ENOMEM on struct lnet_msg\n", libcfs_id2str(target)); @@ -4571,7 +4571,7 @@ struct lnet_msg * * 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 = kzalloc(sizeof(*msg), GFP_NOFS); + struct lnet_msg *msg; struct lnet_libmd *getmd = getmsg->msg_md; struct lnet_process_id peer_id = getmsg->msg_target; int cpt; @@ -4579,6 +4579,7 @@ struct lnet_msg * LASSERT(!getmsg->msg_target_is_router); LASSERT(!getmsg->msg_routing); + msg = kmem_cache_zalloc(lnet_msg_cachep, GFP_NOFS); if (!msg) { CERROR("%s: Dropping REPLY from %s: can't allocate msg\n", libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id)); @@ -4708,7 +4709,7 @@ struct lnet_msg * return -EIO; } - msg = kzalloc(sizeof(*msg), GFP_NOFS); + msg = kmem_cache_zalloc(lnet_msg_cachep, GFP_NOFS); if (!msg) { CERROR("Dropping GET to %s: ENOMEM on struct lnet_msg\n", libcfs_id2str(target));