From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60DE8C678D5 for ; Wed, 8 Mar 2023 15:02:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CFC54280002; Wed, 8 Mar 2023 10:02:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CAC9C280001; Wed, 8 Mar 2023 10:02:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B4D2A280002; Wed, 8 Mar 2023 10:02:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id A2F27280001 for ; Wed, 8 Mar 2023 10:02:24 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1B983160FE2 for ; Wed, 8 Mar 2023 15:02:24 +0000 (UTC) X-FDA: 80546047008.23.DD4F62E Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf10.hostedemail.com (Postfix) with ESMTP id 3DCFCC004B for ; Wed, 8 Mar 2023 15:02:19 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=pazgCUja; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=KzBly1+k; spf=pass (imf10.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678287740; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=qke6c4FNpksj98MCMFsMjlwbe2riF8y0VuNVU0Y/MjU=; b=BqFFMrpR7O9iyq2lRgN4gaEbQE6KJOD+Sdcjthz3IRiuLe9BeDySiwi4R4w48XsMUKl9QO IVV6OGlOhCQGsRWyENZZYMbOuRtmaRVJ45gs/X6aOhu1BWNPaM72ZEk019eFOAc27c2uzN zNSrL1u7HTVfM1VgeWWjml8P7k0rw/I= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=pazgCUja; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=KzBly1+k; spf=pass (imf10.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678287740; a=rsa-sha256; cv=none; b=8cwlj6w8W9M4D1w2a3796dRakOIRVNxYgTKAWc4CRBL+ez7hLs6VdqMyXCOx43i/li6nbj 6cikOqz2pxvSSthdSFH9+tToSdINcT1e4Nk879eUWVRj2CEJya2Ncepum7QN3HcVB139LF DqSTbW3lsfyi3t08fKaf/cGtZbVFavc= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 8E0881FE46; Wed, 8 Mar 2023 15:02:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1678287738; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qke6c4FNpksj98MCMFsMjlwbe2riF8y0VuNVU0Y/MjU=; b=pazgCUjazbs4Pn0ATSbRP0d4O3WG00T3SQO0LceNi0FbAJ9o5rbIhi0Ux+5uJApBvSfuGW +j0d7mt20XSh/2/fGzaW/XYKej3slnF0LktaTFiZi25jH/UqaMJNHCokFwOLIMbK1Q2Cou 4ZkeF7qlVD2iIB/uGxL9JMLAIodsRPU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1678287738; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qke6c4FNpksj98MCMFsMjlwbe2riF8y0VuNVU0Y/MjU=; b=KzBly1+kuo4cnGUeDfenR6tqsLrdgvw+e1Cwam5hXM6MYxkqYmLx1PoXuCGU/RN9/IRlqa jqdDJikUI++wZZBg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2EA1B1348D; Wed, 8 Mar 2023 15:02:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id N51BCnqjCGSnAwAAMHmgww (envelope-from ); Wed, 08 Mar 2023 15:02:18 +0000 Message-ID: Date: Wed, 8 Mar 2023 16:02:38 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH v4 2/8] mm: vmscan: make global slab shrink lockless Content-Language: en-US To: Qi Zheng , akpm@linux-foundation.org, tkhai@ya.ru, hannes@cmpxchg.org, shakeelb@google.com, mhocko@kernel.org, roman.gushchin@linux.dev, muchun.song@linux.dev, david@redhat.com, shy828301@gmail.com, rppt@kernel.org Cc: sultan@kerneltoast.com, dave@stgolabs.net, penguin-kernel@I-love.SAKURA.ne.jp, paulmck@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20230307065605.58209-1-zhengqi.arch@bytedance.com> <20230307065605.58209-3-zhengqi.arch@bytedance.com> From: Vlastimil Babka In-Reply-To: <20230307065605.58209-3-zhengqi.arch@bytedance.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 3DCFCC004B X-Stat-Signature: oyz86eogjkew3pnp7otogjb7zk7i49kf X-Rspam-User: X-HE-Tag: 1678287739-840855 X-HE-Meta: U2FsdGVkX19jXDSwkq/uTqjVR1StBOcSWhB23ZLrM6qWvIft6r8SxHEPCVaEdRRlUU1ucZ6qmyxa2VAVqjWer8kM1v3cV5D2BYVT2VyRHThUGvaMzWR4Q/EThP3N8cFprSI3RdbpMwz0NhhUCgmnI0g56cQq5Wvz1DRZt0oRJUKuilFakiM1eIAgL4oHCyni3LXGXaJtLeIcgECo+qon6PwinfCHgoFGyabBIWn9Yb5hYQT3OnUoAUJJnVXXrzR2GL+YhZYtWxjW8rNrT0ec/MipDnfMFi/s/VaLzCnxFkzetXlfk+mqXAYQk3wv8dH6rthW9PiJ9r4bW4N2XNTEof2xYMVEwQ1sCsupRmpKRg3TLcp4yqmmr6F9y7fnWxspFcjY/tly2tMJtJfGI8Obn3Rskr9ab/5ybQhw7f9xKQ/MJMO7gJcvvWKGvgU9gihXJfrz1aqThozTkCCzrdDfWtEswYNREGtGfp2+JJQ8A3VWN2saUBnTibZkwQI1wHa7Tma2et3Edzu5awJPvBXXdDyemzgrSBL9Knnus86uFPxUKLMZNNAq0jpCwwJ7ooDh3TaZVjSjfCFcZ3cbs6ecglUZgqSlkIvLpPXF1SYElWAioPqGg06RnBLDKRw+62h8FNLmP7J5QrvsJoVDOl/o35YJUnuJJ2G4NHZOY60YXPB8QuIYrGR5mZOkNK2znlvOUmDbYyxRUHgWUB7TueBDn6/EN6NDu3Np84Y5ZM5xvJ7Si1U2O8yfi4fKvqnjOdHHMESPrB2zNGTp02AGqBKwUE8ZS7qzTcnzyUlBXUXSpci2Ew6Q8H07jWCLkeafGgATq4KSs1WNM4XVFdbpgE3fOrSJu3BIJQ5ZArjXlPCp1wG9kSNfJnm+BJ89nWkDdLOFW+aUWSam+yJsayfJPsdWNYryc5VhlUpVe5LPFiigI8FwVxD0K+LaiFS/j6e8ZvAmDthP4mUhYFnZkJsxc7g d8IqA002 jJi9Xf5agjEosmeF85DyTMk2y6Vczj2K2v5z2GLhE9eMNflqGjFOLfqgw3Upg0i16KIsy+iTdie2iX68umMM5a39iz7r6FuuRz2fCH7goQfH8xHpBlF0RSgZ8HF+fc1q6AVJHPTbT+X8jpv643YsSlvOSZu+30KnrUeGFv6w1YnFD3YXE3gC5ATj2Ak1Bb2e7+gO4RWrRRaUgv1rCRr7js7uHIv7V6TwCG2gmhA2nyH2UZ0/MfzbX2XMrSe7CxnF36RtVvgvGSXZgWTZNzOQN088OgM6gn7Txb3U2i9LxfEXvMmxNodVEIBqGfMgXpb2eBGayZKgD0NxQg75XKNQhpxlCDrLhnTwNrokVhFzAyhXBAJDHscC1tkh92PfFwdc8tKE2HtVMsO3hkzkF7KRcOBFXs7T141oCCzx7S6FiYJCLwnftH+G5CEBed6eI1YqF72AwCS23FH4yQsl3G9L4rMmLVZBA2g089JsjawI4AKgFU00EVvV03RE1hB3dbFUW8A/k X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 3/7/23 07:55, Qi Zheng wrote: > The shrinker_rwsem is a global read-write lock in > shrinkers subsystem, which protects most operations > such as slab shrink, registration and unregistration > of shrinkers, etc. This can easily cause problems in > the following cases. > > 1) When the memory pressure is high and there are many > filesystems mounted or unmounted at the same time, > slab shrink will be affected (down_read_trylock() > failed). > > Such as the real workload mentioned by Kirill Tkhai: > > ``` > One of the real workloads from my experience is start > of an overcommitted node containing many starting > containers after node crash (or many resuming containers > after reboot for kernel update). In these cases memory > pressure is huge, and the node goes round in long reclaim. > ``` > > 2) If a shrinker is blocked (such as the case mentioned > in [1]) and a writer comes in (such as mount a fs), > then this writer will be blocked and cause all > subsequent shrinker-related operations to be blocked. > > Even if there is no competitor when shrinking slab, there > may still be a problem. If we have a long shrinker list > and we do not reclaim enough memory with each shrinker, > then the down_read_trylock() may be called with high > frequency. Because of the poor multicore scalability of > atomic operations, this can lead to a significant drop > in IPC (instructions per cycle). > > So many times in history ([2],[3],[4],[5]), some people > wanted to replace shrinker_rwsem trylock with SRCU in > the slab shrink, but all these patches were abandoned > because SRCU was not unconditionally enabled. > > But now, since commit 1cd0bd06093c ("rcu: Remove CONFIG_SRCU"), > the SRCU is unconditionally enabled. So it's time to use > SRCU to protect readers who previously held shrinker_rwsem. > > This commit uses SRCU to make global slab shrink lockless, > the memcg slab shrink is handled in the subsequent patch. > > [1]. https://lore.kernel.org/lkml/20191129214541.3110-1-ptikhomirov@virtuozzo.com/ > [2]. https://lore.kernel.org/all/1437080113.3596.2.camel@stgolabs.net/ > [3]. https://lore.kernel.org/lkml/1510609063-3327-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp/ > [4]. https://lore.kernel.org/lkml/153365347929.19074.12509495712735843805.stgit@localhost.localdomain/ > [5]. https://lore.kernel.org/lkml/20210927074823.5825-1-sultan@kerneltoast.com/ > > Signed-off-by: Qi Zheng Acked-by: Vlastimil Babka