From patchwork Wed May 31 09:57:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13261876 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB846C7EE24 for ; Wed, 31 May 2023 10:04:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235786AbjEaKE2 (ORCPT ); Wed, 31 May 2023 06:04:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235771AbjEaKEV (ORCPT ); Wed, 31 May 2023 06:04:21 -0400 X-Greylist: delayed 361 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 31 May 2023 03:04:18 PDT Received: from out-51.mta0.migadu.com (out-51.mta0.migadu.com [91.218.175.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3095A10B for ; Wed, 31 May 2023 03:04:18 -0700 (PDT) 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=1685527099; 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=lnzxWyBrjsXVofp7h2XNt51t4g+fsU+gJXs/ea1cFR8=; b=sxRHWVlLu+rreVBFxwIJMsPglUs7BP6JtCkUt3t8Jj4/N9ua1Q2/SjbYdZXtKFG7R9C7pt 2t9WN+oDIJxf1PqTSf920IDKgkWQRBFGYeyKYjIsrWLrD8tL2dxfTRirVmdU/LhybNhnyd QK69UVOEAmxZHnZIIPi+vT1ngAY56cU= 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 1/8] mm: vmscan: move shrinker_debugfs_remove() before synchronize_srcu() Date: Wed, 31 May 2023 09:57:35 +0000 Message-Id: <20230531095742.2480623-2-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 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Qi Zheng The debugfs_remove_recursive() will wait for debugfs_file_put() to return, so there is no need to put it after synchronize_srcu() to wait for the rcu read-side critical section to exit. Just move it before synchronize_srcu(), which is also convenient to put the heavy synchronize_srcu() in the delayed work later. Signed-off-by: Qi Zheng --- mm/vmscan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index eeca83e28c9b..a773e97e152e 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -818,11 +818,11 @@ void unregister_shrinker(struct shrinker *shrinker) debugfs_entry = shrinker_debugfs_detach(shrinker, &debugfs_id); mutex_unlock(&shrinker_mutex); + shrinker_debugfs_remove(debugfs_entry, debugfs_id); + atomic_inc(&shrinker_srcu_generation); synchronize_srcu(&shrinker_srcu); - shrinker_debugfs_remove(debugfs_entry, debugfs_id); - kfree(shrinker->nr_deferred); shrinker->nr_deferred = NULL; } From patchwork Wed May 31 09:57:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13261881 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC14BC77B7C for ; Wed, 31 May 2023 10:04:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235787AbjEaKEe (ORCPT ); Wed, 31 May 2023 06:04:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235797AbjEaKEX (ORCPT ); Wed, 31 May 2023 06:04:23 -0400 Received: from out-30.mta0.migadu.com (out-30.mta0.migadu.com [IPv6:2001:41d0:1004:224b::1e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D02612E for ; Wed, 31 May 2023 03:04:19 -0700 (PDT) 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=1685527104; 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=ZzyzkXd70pYEdWJhGutN+U1hmZmD/p5d/wpcM6Ajy+8=; b=ZihWgnR2scrQOnB2k5nDPiR/oFSAGcE5oxTl8DJZlC6c35SkDHP860/TT0nEoqYq/lrcq1 d6CKRaCpb2dkgODgBX/qkpML3eCN0n5h1kziLNHv4ErGYZOVxBG6L8XG40g2Y8QxSO+u0s Pr9f8hmxkoCyCfWi4RAZ5pmhxQ/yWCA= 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 2/8] mm: vmscan: split unregister_shrinker() Date: Wed, 31 May 2023 09:57:36 +0000 Message-Id: <20230531095742.2480623-3-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 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Kirill Tkhai This and the next patches in this series aim to make time effect of synchronize_srcu() invisible for user. The patch splits unregister_shrinker() in two functions: unregister_shrinker_delayed_initiate() unregister_shrinker_delayed_finalize() and shrinker users may make the second of them to be called asynchronous (e.g., from workqueue). Next patches make superblock shrinker to follow this way, so user-visible umount() time won't contain delays from synchronize_srcu(). Signed-off-by: Kirill Tkhai Signed-off-by: Qi Zheng --- include/linux/shrinker.h | 2 ++ mm/vmscan.c | 22 ++++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index 224293b2dd06..e9d5a19d83fe 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -102,6 +102,8 @@ extern void register_shrinker_prepared(struct shrinker *shrinker); extern int __printf(2, 3) register_shrinker(struct shrinker *shrinker, const char *fmt, ...); extern void unregister_shrinker(struct shrinker *shrinker); +extern void unregister_shrinker_delayed_initiate(struct shrinker *shrinker); +extern void unregister_shrinker_delayed_finalize(struct shrinker *shrinker); extern void free_prealloced_shrinker(struct shrinker *shrinker); extern void synchronize_shrinkers(void); diff --git a/mm/vmscan.c b/mm/vmscan.c index a773e97e152e..baf8d2327d70 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -799,10 +799,7 @@ int register_shrinker(struct shrinker *shrinker, const char *fmt, ...) #endif EXPORT_SYMBOL(register_shrinker); -/* - * Remove one - */ -void unregister_shrinker(struct shrinker *shrinker) +void unregister_shrinker_delayed_initiate(struct shrinker *shrinker) { struct dentry *debugfs_entry; int debugfs_id; @@ -819,6 +816,13 @@ void unregister_shrinker(struct shrinker *shrinker) mutex_unlock(&shrinker_mutex); shrinker_debugfs_remove(debugfs_entry, debugfs_id); +} +EXPORT_SYMBOL(unregister_shrinker_delayed_initiate); + +void unregister_shrinker_delayed_finalize(struct shrinker *shrinker) +{ + if (!shrinker->nr_deferred) + return; atomic_inc(&shrinker_srcu_generation); synchronize_srcu(&shrinker_srcu); @@ -826,6 +830,16 @@ void unregister_shrinker(struct shrinker *shrinker) kfree(shrinker->nr_deferred); shrinker->nr_deferred = NULL; } +EXPORT_SYMBOL(unregister_shrinker_delayed_finalize); + +/* + * Remove one + */ +void unregister_shrinker(struct shrinker *shrinker) +{ + unregister_shrinker_delayed_initiate(shrinker); + unregister_shrinker_delayed_finalize(shrinker); +} EXPORT_SYMBOL(unregister_shrinker); /** From patchwork Wed May 31 09:57:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13261874 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED6ABC77B73 for ; Wed, 31 May 2023 10:04:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235814AbjEaKEZ (ORCPT ); Wed, 31 May 2023 06:04:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235776AbjEaKEW (ORCPT ); Wed, 31 May 2023 06:04:22 -0400 Received: from out-18.mta0.migadu.com (out-18.mta0.migadu.com [91.218.175.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41A2A11D for ; Wed, 31 May 2023 03:04:19 -0700 (PDT) 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=1685527108; 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=E+T6MU8ntbBOvHLVHWyWd2NDGkscltn2p+HVjRapVkY=; b=aqACCvCWYJ0Y4210xFVIKOz1nuLZMkNqtH4dgIpFYFS1UqcYGGT2q8rSFyFjyZK7Pydu3w AuV1qecNPdxf4ytiJQpoRe0LH1oNWMkq+SrmRCO9rTKGu8v6q1BZVpGwerN8shJucy3Wif OiE0gEWmKmuhpBJRVVQpYf7vzkydq24= 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 3/8] fs: move list_lru_destroy() to destroy_super_work() Date: Wed, 31 May 2023 09:57:37 +0000 Message-Id: <20230531095742.2480623-4-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 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Kirill Tkhai The patch makes s_dentry_lru and s_inode_lru be destroyed later from the workqueue. This is preparation to split unregister_shrinker(super_block::s_shrink) in two stages, and to call finalize stage from destroy_super_work(). Note, that generic filesystem shrinker unregistration is safe to be split in two stages right after this patch, since super_cache_count() and super_cache_scan() have a deal with s_dentry_lru and s_inode_lru only. But there are two exceptions: XFS and SHMEM, which define .nr_cached_objects() and .free_cached_objects() callbacks. These two do not allow us to do the splitting right after this patch. They touch fs-specific data, which is destroyed earlier, than destroy_super_work(). So, we can't call unregister_shrinker_delayed_finalize() from destroy_super_work() because of them, and next patches make preparations to make this possible. Signed-off-by: Kirill Tkhai Signed-off-by: Qi Zheng --- fs/super.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/fs/super.c b/fs/super.c index 8d8d68799b34..2ce4c72720f3 100644 --- a/fs/super.c +++ b/fs/super.c @@ -159,6 +159,11 @@ static void destroy_super_work(struct work_struct *work) destroy_work); int i; + WARN_ON(list_lru_count(&s->s_dentry_lru)); + WARN_ON(list_lru_count(&s->s_inode_lru)); + list_lru_destroy(&s->s_dentry_lru); + list_lru_destroy(&s->s_inode_lru); + for (i = 0; i < SB_FREEZE_LEVELS; i++) percpu_free_rwsem(&s->s_writers.rw_sem[i]); kfree(s); @@ -177,8 +182,6 @@ static void destroy_unused_super(struct super_block *s) if (!s) return; up_write(&s->s_umount); - list_lru_destroy(&s->s_dentry_lru); - list_lru_destroy(&s->s_inode_lru); security_sb_free(s); put_user_ns(s->s_user_ns); kfree(s->s_subtype); @@ -287,8 +290,6 @@ static void __put_super(struct super_block *s) { if (!--s->s_count) { list_del_init(&s->s_list); - WARN_ON(s->s_dentry_lru.node); - WARN_ON(s->s_inode_lru.node); WARN_ON(!list_empty(&s->s_mounts)); security_sb_free(s); put_user_ns(s->s_user_ns); @@ -330,14 +331,6 @@ void deactivate_locked_super(struct super_block *s) unregister_shrinker(&s->s_shrink); fs->kill_sb(s); - /* - * Since list_lru_destroy() may sleep, we cannot call it from - * put_super(), where we hold the sb_lock. Therefore we destroy - * the lru lists right now. - */ - list_lru_destroy(&s->s_dentry_lru); - list_lru_destroy(&s->s_inode_lru); - put_filesystem(fs); put_super(s); } else { 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: 13261875 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A9F3C7EE33 for ; Wed, 31 May 2023 10:04:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235807AbjEaKE0 (ORCPT ); Wed, 31 May 2023 06:04:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235769AbjEaKEV (ORCPT ); Wed, 31 May 2023 06:04:21 -0400 Received: from out-7.mta0.migadu.com (out-7.mta0.migadu.com [IPv6:2001:41d0:1004:224b::7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0386E5 for ; Wed, 31 May 2023 03:04:18 -0700 (PDT) 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 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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(); From patchwork Wed May 31 09:57:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13261879 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 920F4C7EE24 for ; Wed, 31 May 2023 10:04:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235822AbjEaKEc (ORCPT ); Wed, 31 May 2023 06:04:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235785AbjEaKEX (ORCPT ); Wed, 31 May 2023 06:04:23 -0400 Received: from out-32.mta0.migadu.com (out-32.mta0.migadu.com [91.218.175.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41FAA124 for ; Wed, 31 May 2023 03:04:19 -0700 (PDT) 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=1685527116; 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=TtT/YiPGcEdmTG9OAN3DQ5AumhKObXT9/Vj+qIl0WEg=; b=PlSv9IPmuSHjdrKvEPl7w4TEiIOKkc/t+uD+8kCUMyQjVkWRlPkNzabQJ7hHCOKGaBYK7W bUUNx1CrZkZITlDuz0x6psukNLY7bBJ0k/0MQR2aKvy2s33NxB3JNm4Ms6dXTNpvioEckI QgaCfDLB4ZAFsh5XY9kozVeBEH/jkVw= 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 5/8] fs: introduce struct super_operations::destroy_super() callback Date: Wed, 31 May 2023 09:57:39 +0000 Message-Id: <20230531095742.2480623-6-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 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Kirill Tkhai The patch introduces a new callback, which will be called asynchronous from delayed work. This will allows to make ::nr_cached_objects() safe to be called on destroying superblock in next patches, and to split unregister_shrinker() into two primitives. Signed-off-by: Kirill Tkhai Signed-off-by: Qi Zheng --- fs/super.c | 3 +++ include/linux/fs.h | 1 + 2 files changed, 4 insertions(+) diff --git a/fs/super.c b/fs/super.c index 2ce54561e82e..4e9d08224f86 100644 --- a/fs/super.c +++ b/fs/super.c @@ -170,6 +170,9 @@ static void destroy_super_work(struct work_struct *work) list_lru_destroy(&s->s_dentry_lru); list_lru_destroy(&s->s_inode_lru); + if (s->s_op->destroy_super) + s->s_op->destroy_super(s); + for (i = 0; i < SB_FREEZE_LEVELS; i++) percpu_free_rwsem(&s->s_writers.rw_sem[i]); kfree(s); diff --git a/include/linux/fs.h b/include/linux/fs.h index 0b54ac1d331b..30b46d0facfc 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1910,6 +1910,7 @@ struct super_operations { int (*drop_inode) (struct inode *); void (*evict_inode) (struct inode *); void (*put_super) (struct super_block *); + void (*destroy_super) (struct super_block *); int (*sync_fs)(struct super_block *sb, int wait); int (*freeze_super) (struct super_block *); int (*freeze_fs) (struct super_block *); From patchwork Wed May 31 09:57:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13261873 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DA8FC77B7C for ; Wed, 31 May 2023 10:04:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235803AbjEaKEY (ORCPT ); Wed, 31 May 2023 06:04:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235666AbjEaKEU (ORCPT ); Wed, 31 May 2023 06:04:20 -0400 X-Greylist: delayed 359 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 31 May 2023 03:04:18 PDT Received: from out-58.mta0.migadu.com (out-58.mta0.migadu.com [IPv6:2001:41d0:1004:224b::3a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1DA7E2 for ; Wed, 31 May 2023 03:04:18 -0700 (PDT) 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=1685527121; 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=E1v6Nmr+iDUp1so91WjqnHTNpH9v5OnKQ0PJi2AfGq4=; b=rS4mRe4LmeoSOb/mL2JDcthPretqgBkrv8Kq1Nka9fPmRIXJQ4mg/9Wg8Bj9SViBUA7yr6 PoZXbDH9wstFXz3FQzUyM1geHY3OxQh815EPwbi4X/Zntio/xy3pCNOacpjQfTALY9gKYI zTMcUPF8nNFvCOF+ZtfaP9t9mQ6pBAk= 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 6/8] xfs: introduce xfs_fs_destroy_super() Date: Wed, 31 May 2023 09:57:40 +0000 Message-Id: <20230531095742.2480623-7-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 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Kirill Tkhai xfs_fs_nr_cached_objects() touches sb->s_fs_info, and this patch makes it to be destructed later. After this patch xfs_fs_nr_cached_objects() is safe for splitting unregister_shrinker(): mp->m_perag_tree is stable till destroy_super_work(), while iteration over it is already RCU-protected by internal XFS business. Signed-off-by: Kirill Tkhai Signed-off-by: Qi Zheng --- fs/xfs/xfs_super.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 7e706255f165..694616524c76 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -743,11 +743,18 @@ xfs_fs_drop_inode( } static void -xfs_mount_free( +xfs_free_names( struct xfs_mount *mp) { kfree(mp->m_rtname); kfree(mp->m_logname); +} + +static void +xfs_mount_free( + struct xfs_mount *mp) +{ + xfs_free_names(mp); kmem_free(mp); } @@ -1136,8 +1143,19 @@ xfs_fs_put_super( xfs_destroy_mount_workqueues(mp); xfs_close_devices(mp); - sb->s_fs_info = NULL; - xfs_mount_free(mp); + xfs_free_names(mp); +} + +static void +xfs_fs_destroy_super( + struct super_block *sb) +{ + if (sb->s_fs_info) { + struct xfs_mount *mp = XFS_M(sb); + + kmem_free(mp); + sb->s_fs_info = NULL; + } } static long @@ -1165,6 +1183,7 @@ static const struct super_operations xfs_super_operations = { .dirty_inode = xfs_fs_dirty_inode, .drop_inode = xfs_fs_drop_inode, .put_super = xfs_fs_put_super, + .destroy_super = xfs_fs_destroy_super, .sync_fs = xfs_fs_sync_fs, .freeze_fs = xfs_fs_freeze, .unfreeze_fs = xfs_fs_unfreeze, From patchwork Wed May 31 09:57:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13261880 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91D47C77B73 for ; Wed, 31 May 2023 10:04:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235785AbjEaKEd (ORCPT ); Wed, 31 May 2023 06:04:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235787AbjEaKEX (ORCPT ); Wed, 31 May 2023 06:04:23 -0400 Received: from out-41.mta0.migadu.com (out-41.mta0.migadu.com [IPv6:2001:41d0:1004:224b::29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0542B129 for ; Wed, 31 May 2023 03:04:19 -0700 (PDT) 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=1685527125; 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=cNetM4XBa/Gbuqkaq6l+2vD89eQsIgmLTdtu3cv7dk8=; b=lvO7SWW0g6amQil27w7Ch1WvlKqI4Syaj9ZKVX28hbNP7t8j4/5bAKuiTPnmEYRwcznnpM FC4tcITydxIA3hqHO31xf6p70DR7WKVF4bsUNWyhiAhBcj85YqAuj7QvPpCBdGQUEYFJeW 8/DXDI12VzN61sf4+h1P/9MfcFO1sIc= 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 7/8] shmem: implement shmem_destroy_super() Date: Wed, 31 May 2023 09:57:41 +0000 Message-Id: <20230531095742.2480623-8-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 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Kirill Tkhai Similar to xfs_fs_destroy_super() implement the method for shmem. shmem_unused_huge_count() just touches sb->s_fs_info. After such the later freeing it will be safe for unregister_shrinker() splitting (which is made in next patch). Signed-off-by: Kirill Tkhai Signed-off-by: Qi Zheng --- mm/shmem.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/shmem.c b/mm/shmem.c index 71e6c9855770..a4c3fdf23838 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3930,6 +3930,12 @@ static void shmem_put_super(struct super_block *sb) free_percpu(sbinfo->ino_batch); percpu_counter_destroy(&sbinfo->used_blocks); mpol_put(sbinfo->mpol); +} + +static void shmem_destroy_super(struct super_block *sb) +{ + struct shmem_sb_info *sbinfo = SHMEM_SB(sb); + kfree(sbinfo); sb->s_fs_info = NULL; } @@ -4018,6 +4024,7 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) failed: shmem_put_super(sb); + shmem_destroy_super(sb); return -ENOMEM; } @@ -4182,6 +4189,7 @@ static const struct super_operations shmem_ops = { .evict_inode = shmem_evict_inode, .drop_inode = generic_delete_inode, .put_super = shmem_put_super, + .destroy_super = shmem_destroy_super, #ifdef CONFIG_TRANSPARENT_HUGEPAGE .nr_cached_objects = shmem_unused_huge_count, .free_cached_objects = shmem_unused_huge_scan, From patchwork Wed May 31 09:57:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13261877 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8A6AC7EE32 for ; Wed, 31 May 2023 10:04:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235808AbjEaKE3 (ORCPT ); Wed, 31 May 2023 06:04:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235781AbjEaKEX (ORCPT ); Wed, 31 May 2023 06:04:23 -0400 Received: from out-60.mta0.migadu.com (out-60.mta0.migadu.com [91.218.175.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31135113 for ; Wed, 31 May 2023 03:04:19 -0700 (PDT) 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=1685527129; 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=mjcsinqX7KwTJ40/JcL+JgGM2W0swatrtd18npIFtVk=; b=baMB2GLVbbUmgLTp+CUXyhhVv/9x56bQV3iqZ8MjrGpSa7p5jatJsXPULpCV9EV8+jBrYl PchelLFH6ZF8vYpgvhoNebbx99TRM79XB4NftLwSZ90r/JoVrRMdf+o3xlQ1brouvtCBtm EjXCENjNIePsNVRgiPye7pdqlsEyPGs= 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 8/8] fs: use unregister_shrinker_delayed_{initiate, finalize} for super_block shrinker Date: Wed, 31 May 2023 09:57:42 +0000 Message-Id: <20230531095742.2480623-9-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 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Kirill Tkhai Previous patches made all the data, which is touched from super_cache_count(), destroyed from destroy_super_work(): s_dentry_lru, s_inode_lru and super_block::s_fs_info. super_cache_scan() can't be called after SB_ACTIVE is cleared in generic_shutdown_super(). So, it safe to move heavy unregister_shrinker_delayed_finalize() part to delayed work, i.e. it's safe for parallel do_shrink_slab() to be executed between unregister_shrinker_delayed_initiate() and destroy_super_work()->unregister_shrinker_delayed_finalize(). This makes the heavy synchronize_srcu() to do not affect on user-visible unregistration speed (since now it's executed from workqueue). All further time-critical for unregistration places may be written in the same conception. Signed-off-by: Kirill Tkhai Signed-off-by: Qi Zheng --- fs/super.c | 4 +++- include/linux/fs.h | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/super.c b/fs/super.c index 4e9d08224f86..c61efb74fa7f 100644 --- a/fs/super.c +++ b/fs/super.c @@ -165,6 +165,8 @@ static void destroy_super_work(struct work_struct *work) destroy_work); int i; + unregister_shrinker_delayed_finalize(&s->s_shrink); + WARN_ON(list_lru_count(&s->s_dentry_lru)); WARN_ON(list_lru_count(&s->s_inode_lru)); list_lru_destroy(&s->s_dentry_lru); @@ -337,7 +339,7 @@ void deactivate_locked_super(struct super_block *s) { struct file_system_type *fs = s->s_type; if (atomic_dec_and_test(&s->s_active)) { - unregister_shrinker(&s->s_shrink); + unregister_shrinker_delayed_initiate(&s->s_shrink); fs->kill_sb(s); put_filesystem(fs); diff --git a/include/linux/fs.h b/include/linux/fs.h index 30b46d0facfc..869dd8de91a5 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1929,6 +1929,11 @@ struct super_operations { ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t); struct dquot **(*get_dquots)(struct inode *); #endif + /* + * Shrinker may call these two function on destructing super_block + * till unregister_shrinker_delayed_finalize() has completed + * in destroy_super_work(), and they must care about that. + */ long (*nr_cached_objects)(struct super_block *, struct shrink_control *); long (*free_cached_objects)(struct super_block *,