Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3043470pxu; Tue, 8 Dec 2020 01:49:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJy/kUExX+mGl9rN6abkyc//wAeXZP3ogRq7PYONqYnLO5dR8TcqYVeEmfKIZc+pVCxzZvKN X-Received: by 2002:a05:6402:8d9:: with SMTP id d25mr23451789edz.278.1607420944961; Tue, 08 Dec 2020 01:49:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607420944; cv=none; d=google.com; s=arc-20160816; b=GC7Xx10SDKt5z/62FXEtfrRsbQSBmiUu29uYQAEnkuR/fUhoYxYOv+sIit1nGXt/LK WJThGr8Gk8zguLo7aEeIWEd7eHR2I+/qrYvlGuEFhFEjUDUaWvgoqB6IzjWC9Jg5/RRP TFAmhvHhl3CHDk0xMYdiqMLroyDcrLXaAx121dT37V9QftnJlcif5PDnG0AAoLNKwUug jynqrOHsfe/mpurtgnHR/12XF6+lXlopxI1uYlXX4AeH3UB+meyQ2FXWRLoyoummtyMs 5NbK28rqhtJ33JkQpdfGWfQ/E0T7EOEeE/jNOlLZv2bvNcqP/7yiL+aDD25u8z0G2ofo tl6g== 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=zw/JE9mdFxipC5U73AeWdp8NJm8/28HSgSp98CWi9oo=; b=OXN/iKOlZuY+UMKJywyXL2XhJN/7rn6uJ9V7UIXVmGooBUO+rXSS7qC0F7nQGbCrEq Is+ft7SHJ+KTZTNduvvOWNejvIHS2y9oyvTSxs0SZbJbQ1AcizCzEMbwlwdUetFcvyCo 4PrbqyV6ypwAADZVCL86Qrkv8MOjw+R/YPozD9BIVmpk4TFN1ypayBcGv6LmXK7r1w6y fb/ZDyJLC+cTxRHqrSMzsaq4SiZjiTk52G6rHhAdeMgY8IxEORbJxaTnBlW+dIdewFD8 z4JBQ2Q+cMXbbPYoBywNe68fdADQEIlQbrci7NtPSi23RCiRFank9coGBCVgvgKoKmI/ Vnag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=lpsTTzSY; 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 a16si10195388edn.109.2020.12.08.01.48.42; Tue, 08 Dec 2020 01:49: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=lpsTTzSY; 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 S1728131AbgLHJrJ (ORCPT + 99 others); Tue, 8 Dec 2020 04:47:09 -0500 Received: from smtp-fw-9103.amazon.com ([207.171.188.200]:6735 "EHLO smtp-fw-9103.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726299AbgLHJrB (ORCPT ); Tue, 8 Dec 2020 04:47:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1607420820; x=1638956820; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=zw/JE9mdFxipC5U73AeWdp8NJm8/28HSgSp98CWi9oo=; b=lpsTTzSY4XltETly8YpavmljkqvLz2NHJkt0+GkmgI6y9/T48aHoAdYu 1LahFftzPwX9WoUisrUaGlyYmlRWociOATGZ/jS71taZXh3a3QgOBpXDO Bs8pFiwALpKb3zffTOoNp5fw+ayh0Gr4Mj/naOB4a17Xj5tYRzIxNzrYM k=; X-IronPort-AV: E=Sophos;i="5.78,402,1599523200"; d="scan'208";a="901360427" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-538b0bfb.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9103.sea19.amazon.com with ESMTP; 08 Dec 2020 09:46:14 +0000 Received: from EX13D31EUA001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-2a-538b0bfb.us-west-2.amazon.com (Postfix) with ESMTPS id A5759A1C02; Tue, 8 Dec 2020 09:46:13 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.160.67) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Dec 2020 09:45:53 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , Subject: [PATCH 1/1] net/ipv4/inet_fragment: Batch fqdir destroy works Date: Tue, 8 Dec 2020 10:45:29 +0100 Message-ID: <20201208094529.23266-2-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201208094529.23266-1-sjpark@amazon.com> References: <20201208094529.23266-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.160.67] X-ClientProxiedBy: EX13D47UWA002.ant.amazon.com (10.43.163.30) 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 destruction of the 'fqdir' is enqueued. The work function, 'fqdir_work_fn()', calls 'rcu_barrier()'. In case of intensive 'fqdir_exit()' (e.g., frequent 'unshare(CLONE_NEWNET)' systemcalls), this increased contention could result in unacceptably high latency of 'rcu_barrier()'. This commit avoids such contention by doing the destruction 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..796b559137c5 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; + struct inet_frags *f; + + /* Atomically snapshot the list of fqdirs to destroy */ + kill_list = llist_del_all(&destroy_list); - rhashtable_free_and_destroy(&fqdir->rhashtable, inet_frags_free_cb, NULL); + 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(fqdir, 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