Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4809804pxu; Thu, 10 Dec 2020 06:08:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJyW2E/Yf9StfvPqK8piWgMW72D6eeQUrhZ7Qqly461+XaL81hW3d+rYKwE74VynxeP7I1sK X-Received: by 2002:aa7:d54b:: with SMTP id u11mr6912962edr.341.1607609284458; Thu, 10 Dec 2020 06:08:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607609284; cv=none; d=google.com; s=arc-20160816; b=QS3CqeJa619DKaIC8luE+yA2/5a+Ho1BVHdiCPaDwDkqScayjqXaJG03UW+F6R2anC LH5TE8UAWsJF8wNC2oQgUznfT2dfn7lbhHYKvRXQ13osytoSBqkfVUGo9OyFmNXIHL50 QgrQemG2vYNIT5l6xZ42/d5TttqLfNDXb3saPX5FHlqDDqntwTLzEvjqRforVK4yN/yA FeRddEzhuxYevN70bCrstD6P9tuX4NsjB3U+B7Zhq++D2ewcyVW7lS0XcxOuudhnYvPa MzYGejArxsjbeOoVFsTYTuuDL2fgOb9okjYHyBY3DPh2FefKdL3tL14SV/bMPdLtZW8E p1kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=RaitfIFfdpp6jtfUPGRbEOUja/qNHha6jb1uqJ7pyaU=; b=lNwwHHOoW4ID4bElm8plmxrgokA+eT9HrKNUq0n1M7crpkOdNEJh9QAW4HwGo1flIb TWPFfF4RktInbjrp111SeV39TWHehLeaKAOVlT+JvbvGmw0oECQKxd2BLv8g1YIyvz3i 5Ohqnnm3kZXvbkP6+2vP6gf6xsxEsZVxFvbo7nrpaJupS9EZZRpZDWcG1YM+7BmQdW7W 9B9na5sm6M6sGhLIpIaioHdEWcKhuHvdg3njOvcfhRq9VxPw3TqJsBRRsls2IWz7FSw8 kb7c5stxkLpF+tpDTD0a2Wa8otmC+XqPDwHdO/8xJFwxZz01850/pBGRw7cZLc2Kr7JP 5ihA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b="X/hhDI4R"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j24si2469173ejd.743.2020.12.10.06.07.41; Thu, 10 Dec 2020 06:08:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b="X/hhDI4R"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387582AbgLJIKL (ORCPT + 99 others); Thu, 10 Dec 2020 03:10:11 -0500 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:61287 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725896AbgLJIKG (ORCPT ); Thu, 10 Dec 2020 03:10:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1607587805; x=1639123805; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=RaitfIFfdpp6jtfUPGRbEOUja/qNHha6jb1uqJ7pyaU=; b=X/hhDI4R06IYr22SqJWXE9JvBlwWHN+poYZOOaHORuCF0b/h1LOHJ00w +uEfP4kTkpfbN5JS+KRS6WfX1RCTSqVnBx5CC9Va+ENxHl0zKh+Zf5RAo 03Cl8ZidrhP151mtOOHeEohKDYq3dES9scny5nqgqIJXG21USwu+4lwtT 8=; X-IronPort-AV: E=Sophos;i="5.78,407,1599523200"; d="scan'208";a="103145938" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1e-c7c08562.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 10 Dec 2020 08:09:16 +0000 Received: from EX13D31EUA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-1e-c7c08562.us-east-1.amazon.com (Postfix) with ESMTPS id 609FF240BFB; Thu, 10 Dec 2020 08:09:14 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.161.102) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 10 Dec 2020 08:09:09 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , Subject: [PATCH v2 1/1] net/ipv4/inet_fragment: Batch fqdir destroy works Date: Thu, 10 Dec 2020 09:08:44 +0100 Message-ID: <20201210080844.23741-2-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201210080844.23741-1-sjpark@amazon.com> References: <20201210080844.23741-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.161.102] X-ClientProxiedBy: EX13D16UWB004.ant.amazon.com (10.43.161.170) To EX13D31EUA001.ant.amazon.com (10.43.165.15) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: SeongJae Park In 'fqdir_exit()', a work for destroy of the 'fqdir' is enqueued. The work function, 'fqdir_work_fn()', calls 'rcu_barrier()'. In case of intensive 'fqdir_exit()' (e.g., frequent 'unshare()' systemcalls), this increased contention could result in unacceptably high latency of 'rcu_barrier()'. This commit avoids such contention by doing the destroy work in batched manner, as similar to that of 'cleanup_net()'. Signed-off-by: SeongJae Park --- include/net/inet_frag.h | 2 +- net/ipv4/inet_fragment.c | 28 ++++++++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/include/net/inet_frag.h b/include/net/inet_frag.h index bac79e817776..558893d8810c 100644 --- a/include/net/inet_frag.h +++ b/include/net/inet_frag.h @@ -20,7 +20,7 @@ struct fqdir { /* Keep atomic mem on separate cachelines in structs that include it */ atomic_long_t mem ____cacheline_aligned_in_smp; - struct work_struct destroy_work; + struct llist_node destroy_list; }; /** diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c index 10d31733297d..d5c40386a764 100644 --- a/net/ipv4/inet_fragment.c +++ b/net/ipv4/inet_fragment.c @@ -145,12 +145,19 @@ static void inet_frags_free_cb(void *ptr, void *arg) inet_frag_destroy(fq); } +static LLIST_HEAD(destroy_list); + static void fqdir_work_fn(struct work_struct *work) { - struct fqdir *fqdir = container_of(work, struct fqdir, destroy_work); - struct inet_frags *f = fqdir->f; + struct llist_node *kill_list; + struct fqdir *fqdir, *tmp; + struct inet_frags *f; - rhashtable_free_and_destroy(&fqdir->rhashtable, inet_frags_free_cb, NULL); + /* Atomically snapshot the list of fqdirs to destroy */ + kill_list = llist_del_all(&destroy_list); + + llist_for_each_entry(fqdir, kill_list, destroy_list) + rhashtable_free_and_destroy(&fqdir->rhashtable, inet_frags_free_cb, NULL); /* We need to make sure all ongoing call_rcu(..., inet_frag_destroy_rcu) * have completed, since they need to dereference fqdir. @@ -158,10 +165,13 @@ static void fqdir_work_fn(struct work_struct *work) */ rcu_barrier(); - if (refcount_dec_and_test(&f->refcnt)) - complete(&f->completion); + llist_for_each_entry_safe(fqdir, tmp, kill_list, destroy_list) { + f = fqdir->f; + if (refcount_dec_and_test(&f->refcnt)) + complete(&f->completion); - kfree(fqdir); + kfree(fqdir); + } } int fqdir_init(struct fqdir **fqdirp, struct inet_frags *f, struct net *net) @@ -184,10 +194,12 @@ int fqdir_init(struct fqdir **fqdirp, struct inet_frags *f, struct net *net) } EXPORT_SYMBOL(fqdir_init); +static DECLARE_WORK(fqdir_destroy_work, fqdir_work_fn); + void fqdir_exit(struct fqdir *fqdir) { - INIT_WORK(&fqdir->destroy_work, fqdir_work_fn); - queue_work(system_wq, &fqdir->destroy_work); + if (llist_add(&fqdir->destroy_list, &destroy_list)) + queue_work(system_wq, &fqdir_destroy_work); } EXPORT_SYMBOL(fqdir_exit); -- 2.17.1