Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4602439pxu; Thu, 10 Dec 2020 00:12:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJzEylCOcl18sv4Khijndd1GxOcLQ9Vm3kHpW/HeLxPDjBagRKPaTc7h1+mO1tAW1pH3uEGY X-Received: by 2002:a17:906:12cf:: with SMTP id l15mr5276123ejb.540.1607587967418; Thu, 10 Dec 2020 00:12:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607587967; cv=none; d=google.com; s=arc-20160816; b=ZGr8SbIuGWZKXRhBAqZj/GLp0z5QXL0hYeqGZSb+iy5l+2MeI5X7tbX1miAJs055nL fqTnACJJbymwh2gHfhDiNPGtF94CVgUJ0lIzxBrRCXSHN+q+yhaWiVYUk3S/TQ+XMGrb FNaiBLF66jazZLRRXdCj0AY5sjxSROVAjnzFs56EuUsW9L2g03EMX84cxAIvxatkLD7v KiTKEOMMip+blNfqv3cpiLA/KTGcl0/be4ZenoW4NqR8YeCvrPEiBpelRxf9vWJonkI9 /mPCXFcvCXRdRtTuTEUu0+02CkMd3w6x+UvtumsI9drtsi+PdwxqNsRCy3n31HV9Ln4y eYlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=aEJzy3+FKb9u4xePy0sLXdWn5xOn3WQ9Rfk09qhrQYk=; b=j5m/iVfVBUP1PakTwl4uWxTxOfkSHNQ/6/A1B3dZ8CPaVAzwrwys9cZzXk5gLzdxD2 BmgatH9x0urxDC47B1UJcdPoKElTvy7iC09Mv4QEOUNKyaX/mHQI250BB/WSZBhlzyZg P2VDvYXCEeS7yztDWrcR5b2eb/AEfMZretVWPU+ikt25huIHRfwXXOZfqMQj8OsofCsZ cHxYElGZ+nxmzz1r1iw+JNWB6IyYHiW4SSrdE4GhCRr+owcZmDvg8tE+Kjbps1pcYJu4 8ccOdvSndcVeyBOPn3ve4M3Ljn8KeaHVjYQJcVIgTv/ZJze4JXb+06TXqkCCUHdlXGFC J9AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=KEdZGycv; 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 i18si2110306ejf.223.2020.12.10.00.12.24; Thu, 10 Dec 2020 00:12:47 -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=KEdZGycv; 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 S1733155AbgLJIJ5 (ORCPT + 99 others); Thu, 10 Dec 2020 03:09:57 -0500 Received: from smtp-fw-6001.amazon.com ([52.95.48.154]:58786 "EHLO smtp-fw-6001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725896AbgLJIJ5 (ORCPT ); Thu, 10 Dec 2020 03:09:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1607587796; x=1639123796; h=from:to:cc:subject:date:message-id:mime-version; bh=aEJzy3+FKb9u4xePy0sLXdWn5xOn3WQ9Rfk09qhrQYk=; b=KEdZGycvm1b326PFi92VZyT9la9OZgCStrhOvoboi7XEVNSMPWHE+jiK JV94u/VUvz6DYPqXNOTUky3MpGsjZD/zbBF2h6Q39xL/DyyQoAVIqqG60 ztv3R93F0HmqtRUHzZ3ZxJAUT0sO0fg8tyPc5bKaUdcMrOK2Su/dI48wW 0=; X-IronPort-AV: E=Sophos;i="5.78,407,1599523200"; d="scan'208";a="71701030" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1a-af6a10df.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 10 Dec 2020 08:09:09 +0000 Received: from EX13D31EUA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-1a-af6a10df.us-east-1.amazon.com (Postfix) with ESMTPS id 6BDBFA18C4; Thu, 10 Dec 2020 08:09:07 +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:02 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , Subject: [PATCH v2 0/1] net: Reduce rcu_barrier() contentions from 'unshare(CLONE_NEWNET)' Date: Thu, 10 Dec 2020 09:08:43 +0100 Message-ID: <20201210080844.23741-1-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 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 On a few of our systems, I found frequent 'unshare(CLONE_NEWNET)' calls make the number of active slab objects including 'sock_inode_cache' type rapidly and continuously increase. As a result, memory pressure occurs. In more detail, I made an artificial reproducer that resembles the workload that we found the problem and reproduce the problem faster. It merely repeats 'unshare(CLONE_NEWNET)' 50,000 times in a loop. It takes about 2 minutes. On 40 CPU cores, 70GB DRAM machine, it reduced about 15GB of available memory in total. Note that the issue don't reproduce on every machine. On my 6 CPU cores machine, the problem didn't reproduce. 'cleanup_net()' and 'fqdir_work_fn()' are functions that deallocate the relevant memory objects. They are asynchronously invoked by the work queues and internally use 'rcu_barrier()' to ensure safe destructions. 'cleanup_net()' works in a batched maneer in a single thread worker, while 'fqdir_work_fn()' works for each 'fqdir_exit()' call in the 'system_wq'. Therefore, 'fqdir_work_fn()' called frequently under the workload and made the contention for 'rcu_barrier()' high. In more detail, the global mutex, 'rcu_state.barrier_mutex' became the bottleneck. I tried making 'fqdir_work_fn()' batched and confirmed it works. The following patch is for the change. I think this is the right solution for point fix of this issue, but someone might blame different parts. 1. User: Frequent 'unshare()' calls From some point of view, such frequent 'unshare()' calls might seem only insane. 2. Global mutex in 'rcu_barrier()' Because of the global mutex, 'rcu_barrier()' callers could wait long even after the callbacks started before the call finished. Therefore, similar issues could happen in another 'rcu_barrier()' usages. Maybe we can use some wait queue like mechanism to notify the waiters when the desired time came. I personally believe applying the point fix for now and making 'rcu_barrier()' improvement in longterm make sense. If I'm missing something or you have different opinion, please feel free to let me know. Patch History ------------- Changes from v1 (https://lore.kernel.org/netdev/20201208094529.23266-1-sjpark@amazon.com/) - Keep xmas tree variable ordering (Jakub Kicinski) - Add more numbers (Eric Dumazet) - Use 'llist_for_each_entry_safe()' (Eric Dumazet) SeongJae Park (1): net/ipv4/inet_fragment: Batch fqdir destroy works include/net/inet_frag.h | 2 +- net/ipv4/inet_fragment.c | 28 ++++++++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) -- 2.17.1