From patchwork Wed May 31 09:57:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13261855 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 A5F44C77B73 for ; Wed, 31 May 2023 09:58:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3DA3E8E0006; Wed, 31 May 2023 05:58:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 389A88E0002; Wed, 31 May 2023 05:58:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 29FAD8E0006; Wed, 31 May 2023 05:58:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 1E6C38E0002 for ; Wed, 31 May 2023 05:58:36 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DB554802E6 for ; Wed, 31 May 2023 09:58:35 +0000 (UTC) X-FDA: 80850100590.13.49745A4 Received: from out-45.mta0.migadu.com (out-45.mta0.migadu.com [91.218.175.45]) by imf04.hostedemail.com (Postfix) with ESMTP id 158B840010 for ; Wed, 31 May 2023 09:58:33 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=pME7V5sg; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf04.hostedemail.com: domain of qi.zheng@linux.dev designates 91.218.175.45 as permitted sender) smtp.mailfrom=qi.zheng@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685527114; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+ES1OZTmJM6HPZiOufnJqkIPYyFHG+uxk+XMAxdW/H0=; b=Zhqnq4e104SbjChie6x5L34CG9AZz582gpHjEPJjx6m9iBP8HGiecjCbS9sNbVlQcIb6+l CXjlkmGL6Z53GgNvpIJqU3g4GGAjCMnU4wbxpJ8yB0p5N3bz6hDNFGyuHEa7kpF4E04XSD 0fq29teiN0zEsltVznO4PCV4vmaD8Y4= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=pME7V5sg; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf04.hostedemail.com: domain of qi.zheng@linux.dev designates 91.218.175.45 as permitted sender) smtp.mailfrom=qi.zheng@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685527114; a=rsa-sha256; cv=none; b=ReOHWBQZVhWIViWGrYOiv9D/V8FCYKQuXFhmYE+AtocIVCoZX6M8nE6qmCJcLN8nGBstYB +2VTRVBexzQq4RXkGqZc6EKJTR3e8UmBIVfFESUge1iBEYkkqCX7NATNp1UKM4TUiTXCzQ yIOWN06GH+peDNp8t9QgJ6ikFqmFBlo= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1685527112; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+ES1OZTmJM6HPZiOufnJqkIPYyFHG+uxk+XMAxdW/H0=; b=pME7V5sghWDhiBYKlYhlIGGcd+I8ZIhtp+E9A11aBMxPx6kduDLdGh2+5uOlz/UhrC8USH AInETjEYhvnYApFG/QCWzh1ONDgIapx8Zsu0DP7P6tbY+y9jVOZnflKJtLkCkwkXmah55p +X/uwLrssbh7WgAqh01669o0MFk+pHM= From: Qi Zheng To: akpm@linux-foundation.org, tkhai@ya.ru, roman.gushchin@linux.dev, vbabka@suse.cz, viro@zeniv.linux.org.uk, brauner@kernel.org, djwong@kernel.org, hughd@google.com, paulmck@kernel.org, muchun.song@linux.dev Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, Qi Zheng Subject: [PATCH 4/8] fs: shrink only (SB_ACTIVE|SB_BORN) superblocks in super_cache_scan() Date: Wed, 31 May 2023 09:57:38 +0000 Message-Id: <20230531095742.2480623-5-qi.zheng@linux.dev> In-Reply-To: <20230531095742.2480623-1-qi.zheng@linux.dev> References: <20230531095742.2480623-1-qi.zheng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 158B840010 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: zq7wh4qfhnctfc85ju7k7m9obsqa7ycd X-HE-Tag: 1685527113-750613 X-HE-Meta: U2FsdGVkX1/DFJXsDYSvD2UiPhORaq67zEcMFJgRlSniYHtqI+lEVhr49RwDeB9SLRPfvpDTxQY1xYgFTekqwiidG8OUhl5WCEzuTnvUoqEqYZN/gGtGhyZx4/dmKluX6kbjr5Wh159hH8F7Vdz9tT48gKk2CqywWHHcrado01mfvlmsih1jmL70BEPF8azF0qBW9DdyA/qGBNv/QbBTIFIoLwB34kZ9NWu5D5sMVmN2v3K9N5uUQ1/wW+ZOqSZcbump8Zwspzt+82J43C1cW8LZmCp0gM3ltQEpKK1y2KeTlzZyDuQidVcSw3C9JASllcWPgONidRP5RJufe0caTT3ejSh2maUIqvpMRfWfdoHqmbC8YozoqLrTle7j4mecgC8lNfp3YgFe3K8SNFRMf+pW6+Q1MUQWIYLwNGOEsqadcDyG4DsUeIPuw9Ee/Xo1SJaCaL+wean+vr1znSJaRYXplwBLfjmUW6JGxcoDj2DiumX5E2CrqsRtnQMzx6JmiL8wXBevVyVIyiOFe9SaoIpfufOXRsnYfC/EOqvm+T0gmwmj4IANMxITIf4ClC0O7fbTuBPaWgJ4b0u09RtldjsdNkkkiYmBcelPxlBzBgBPghe0A5J7P4w5i7npWfEvsW+8HH2f43Affy0AyvVPAsHzNTGY+WupynkMQAP7ckZ1tqWcSbCS36L8S7FnwLzstMH2lAO01oJ5QNFerCJ6mfDr9uWOmj4gtzc3zltd+Fm87x9otzEQNhiJiNUN1n0mfG3Zre77C4Q8Lo1C5zYSLIPpd8zIOM4LIxVb0/fwSr+oRcYsS2GCGc9/Exi17myD5BRWNGaA5GnB57c6CmFgFRiwEe3BYbihEjHbOphM5fMSm7Gd73hfRCaMoW+TD70BwdZsZzYEMMCtCSSU2lVD7xlXMvxBnnUp2AyMnclE2QNj7G+p9k5y93abFLx84jzdRqwKLX0s3C9VbpBhR1R G7z4Xuvs 8Ha4daFk36oi81zbBuNi6k+CZko/+flybDF40fHUJtMorU3kEUMj/iOT5eHX0OHeAPoR5ok0M7dzW/wOc4o5jvF4JgmwxzFFFv2U9TEXO5MNVTBUzerDrxgokyKqnIX0L7P2T5mYFb1m5dHxQ81uRYXVAt5nzHGXog9Cb6K72vl5tHfNwuOvwjeXsuCVAm2zLQ5D6hm2bS9zi/K2cf9KbRpOYDJpJh40s4o9FpcbaAUB3YMQklwSFl1wh2w== 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: From: Kirill Tkhai This patch prepares superblock shrinker for delayed unregistering. It makes super_cache_scan() avoid shrinking of not active superblocks. SB_ACTIVE is used as such the indicator. In case of superblock is not active, super_cache_scan() just exits with SHRINK_STOP as result. Note, that SB_ACTIVE is cleared in generic_shutdown_super() and this is made under the write lock of s_umount. Function super_cache_scan() also takes the read lock of s_umount, so it can't skip this flag cleared. SB_BORN check is added to super_cache_scan() just for uniformity with super_cache_count(), while super_cache_count() received SB_ACTIVE check just for uniformity with super_cache_scan(). After this patch super_cache_scan() becomes to ignore unregistering superblocks, so this function is OK with splitting unregister_shrinker(). Next patches prepare super_cache_count() to follow this way. Signed-off-by: Kirill Tkhai Signed-off-by: Qi Zheng --- fs/super.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/super.c b/fs/super.c index 2ce4c72720f3..2ce54561e82e 100644 --- a/fs/super.c +++ b/fs/super.c @@ -79,6 +79,11 @@ static unsigned long super_cache_scan(struct shrinker *shrink, if (!trylock_super(sb)) return SHRINK_STOP; + if ((sb->s_flags & (SB_BORN|SB_ACTIVE)) != (SB_BORN|SB_ACTIVE)) { + freed = SHRINK_STOP; + goto unlock; + } + if (sb->s_op->nr_cached_objects) fs_objects = sb->s_op->nr_cached_objects(sb, sc); @@ -110,6 +115,7 @@ static unsigned long super_cache_scan(struct shrinker *shrink, freed += sb->s_op->free_cached_objects(sb, sc); } +unlock: up_read(&sb->s_umount); return freed; } @@ -136,7 +142,7 @@ static unsigned long super_cache_count(struct shrinker *shrink, * avoid this situation, so do the same here. The memory barrier is * matched with the one in mount_fs() as we don't hold locks here. */ - if (!(sb->s_flags & SB_BORN)) + if ((sb->s_flags & (SB_BORN|SB_ACTIVE)) != (SB_BORN|SB_ACTIVE)) return 0; smp_rmb();