From patchwork Mon Sep 11 09:44: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: 13379114 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 A9FB0EEB57E for ; Mon, 11 Sep 2023 09:51:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F5846B025F; Mon, 11 Sep 2023 05:51:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A63F6B0260; Mon, 11 Sep 2023 05:51:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 394EC6B0261; Mon, 11 Sep 2023 05:51:02 -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 2A0286B025F for ; Mon, 11 Sep 2023 05:51:02 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 01E301CA405 for ; Mon, 11 Sep 2023 09:51:01 +0000 (UTC) X-FDA: 81223847964.26.AF236CC Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf17.hostedemail.com (Postfix) with ESMTP id 0FC5740019 for ; Mon, 11 Sep 2023 09:50:59 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=hm52fbCO; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf17.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694425860; 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=UwQSoSJR+jSGtu7F9A/uGElinPV2h0dmFylLKakGH3E=; b=nFqC6Bnc8NkxpCUeT1lBHCHusLjlBZwN2X9BwbTZn/UJO+nm3l218LKs3gIVWmu4eV3bOt HtzD9741FB0LY/lXhBa/2fMpb76EwNyeEvh8sZJSVPuKeyCFH7ptTIRmenwpbFA/FBDjY8 huWHpL5flBggqGtKh/7qD3WveTBaSAU= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=hm52fbCO; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf17.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425860; a=rsa-sha256; cv=none; b=yZAIqGBgjZMSFAFbmhe6kJfATBll7JeFv0aZlPkz5I40pg4G/0JczgrbBGxoEHdIYTVA1L g5xiGg9kR5bKzntO93W9f2g2JRylw1P1Saf++zx00SBqed+UY1HdGr5RKk/Qos1AK5Qphw YEKQB/gEJ1gh0uic3f77GBb/lKchv34= Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1c39500767aso6237815ad.0 for ; Mon, 11 Sep 2023 02:50:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425859; x=1695030659; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UwQSoSJR+jSGtu7F9A/uGElinPV2h0dmFylLKakGH3E=; b=hm52fbCO6XAeWqboYIdMIRuZiN6rFafLWaBmhejB45IHN7IFTyEM4NYON9i2z6Cm2k Swe19SPr0rZ1s3NkBAPXSucQPMduzcnLd7tMXgEyIM7awVJttyWegqiuH5PTPetu7E5q Tgd+AfAKLABNtnu8xTeivoLvd96IkC0znuKIrFdps509Gol7dWJHAzoovtFhO1hKFlB0 lWtStc1v2ForK+d3KNicDgYzBDDW3QN1IJsnU6XHPIjdDHPX3RivZmVAIMp7Jh1rN3MA To9DKJpafl/WAwcGWgaiWIWe0fFj3YbWkRPnESuuZ/y9xVfV51Hc29MVNAfBLu2emM4e dPOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425859; x=1695030659; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UwQSoSJR+jSGtu7F9A/uGElinPV2h0dmFylLKakGH3E=; b=eb9L2U4ZyGgySn17F1s/Pabw23mmgTsT/vwboLQ78kwqId86sOmStpuMaS8TAtX+R1 BH3iqP3xwGy5MsIItvKUqmxiG8ykJOxFF64Jpd5040IXn5K945uMI61QVYmWdjxJWi0v TLRHYJnh/GHRYfbyxk5oBw47jWFWjjWe3WUMtbVnEsi+3jo9O6EA7mqszIvJq6mAS/Lx 1SdRoN1Vo5JrTU1VQ9tybtfpk+bgj3XhRjgkn7K0PWIlBA1UPLdJCGIIV9zy9tr3M3rj GUFZ/NVmkUgzv25Cor3ZBW1XFjuS2InxFGasQZNRAZ5W7Cfk71YURds6y92WuhEldB50 VOcA== X-Gm-Message-State: AOJu0Yxd9rMUFjfvJyT9epb+K4eygRILD6Wqqx9NbUqLLoa/StI5BJQT lH9cf8fAifweoHFhk/L/H6quFQ== X-Google-Smtp-Source: AGHT+IFK0C5cGs7QePEp9uLcPywDnGod8IFfwet3Jfbl6uzPvoZmscAh5Bx6Hmh6im2BgxS0qDp7eg== X-Received: by 2002:a05:6a20:4425:b0:14d:4ab5:5e3c with SMTP id ce37-20020a056a20442500b0014d4ab55e3cmr13477043pzb.1.1694425858977; Mon, 11 Sep 2023 02:50:58 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id az7-20020a170902a58700b001bdc2fdcf7esm5988188plb.129.2023.09.11.02.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:50:58 -0700 (PDT) From: Qi Zheng To: akpm@linux-foundation.org, david@fromorbit.com, tkhai@ya.ru, vbabka@suse.cz, roman.gushchin@linux.dev, djwong@kernel.org, brauner@kernel.org, paulmck@kernel.org, tytso@mit.edu, steven.price@arm.com, cel@kernel.org, senozhatsky@chromium.org, yujie.liu@intel.com, gregkh@linuxfoundation.org, muchun.song@linux.dev Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Qi Zheng , Muchun Song , Chris Mason , Josef Bacik , David Sterba , Alexander Viro , linux-btrfs@vger.kernel.org Subject: [PATCH v6 38/45] fs: super: dynamically allocate the s_shrink Date: Mon, 11 Sep 2023 17:44:37 +0800 Message-Id: <20230911094444.68966-39-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230911094444.68966-1-zhengqi.arch@bytedance.com> References: <20230911094444.68966-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 0FC5740019 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: p9qt9anqfpxyuq9byap1uj6sd9xk6sr3 X-HE-Tag: 1694425859-445677 X-HE-Meta: U2FsdGVkX1+R/zkkSPFLZKgegR9Q6KzP9+Bco3yyUstMdkmXRTgG11yEtMe5a1laaCF1tD1aMSVrT48vqR2W1tyz8Yrt0A0D9f+f4LKoSJCaWnW1cDrfLEoNFXwBhGskS0P9IOQbrpLNCL39aSHudCphV0Lskzpvr76/rXcMXiKa50A5NJmYWQp9vtkHqRCea+mrM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G5cEzyXO+vSvd/fo+QjxNNpe5CbeDBYjZIVGlbZtSAXINQ2bh3UIhDtFAnuk/vXUpz0ZiLxzdSwPH70AOHSbFqabaAIHgjxyC8pkv/5ZZuvVzUWnDJAz1fllQOGRG/cOn6g86ajYYtImXgh6I4E29x/qqX9mNFLd0QJQoRNZMtZimMshghEwqKa4dAzJm676/FpIUxMXB33td5Fd0gj8GJvNTvrsmaol3/XzT9pnWgjdj5gLcAQqGQGS3JFaOdc/4G5p3UPSYOCekj+Unti9qQC5fY8elxtv9EpSug2xoPbIA721k59E9G1yPz7kMAbVjQH/DdH+nZ5bjUQNv04DOd4uP56TPUMW8qTPaqKPD8sMf6AUt97uQYz3y8MKP6LytvxEIIBWm7qC1T6ecvskZ7gAtvnaE3m+miNN+aAqpbaRSPg4cOyddDyD+nHJv67EKTGxxRsuZVlVdXyYabeHFSf5ek 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: In preparation for implementing lockless slab shrink, use new APIs to dynamically allocate the s_shrink, so that it can be freed asynchronously via RCU. Then it doesn't need to wait for RCU read-side critical section when releasing the struct super_block. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Chris Mason CC: Josef Bacik CC: David Sterba CC: Alexander Viro CC: Christian Brauner CC: linux-btrfs@vger.kernel.org Acked-by: David Sterba --- fs/btrfs/super.c | 2 +- fs/kernfs/mount.c | 2 +- fs/proc/root.c | 2 +- fs/super.c | 33 ++++++++++++++++++--------------- include/linux/fs.h | 2 +- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 09bfe68d2ea3..3b165d9967bb 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1519,7 +1519,7 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type, error = -EBUSY; } else { snprintf(s->s_id, sizeof(s->s_id), "%pg", bdev); - shrinker_debugfs_rename(&s->s_shrink, "sb-%s:%s", fs_type->name, + shrinker_debugfs_rename(s->s_shrink, "sb-%s:%s", fs_type->name, s->s_id); btrfs_sb(s)->bdev_holder = fs_type; error = btrfs_fill_super(s, fs_devices, data); diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c index c4bf26142eec..79b96e74a8a0 100644 --- a/fs/kernfs/mount.c +++ b/fs/kernfs/mount.c @@ -265,7 +265,7 @@ static int kernfs_fill_super(struct super_block *sb, struct kernfs_fs_context *k sb->s_time_gran = 1; /* sysfs dentries and inodes don't require IO to create */ - sb->s_shrink.seeks = 0; + sb->s_shrink->seeks = 0; /* get root inode, initialize and unlock it */ down_read(&kf_root->kernfs_rwsem); diff --git a/fs/proc/root.c b/fs/proc/root.c index 9191248f2dac..b55dbc70287b 100644 --- a/fs/proc/root.c +++ b/fs/proc/root.c @@ -188,7 +188,7 @@ static int proc_fill_super(struct super_block *s, struct fs_context *fc) s->s_stack_depth = FILESYSTEM_MAX_STACK_DEPTH; /* procfs dentries and inodes don't require IO to create */ - s->s_shrink.seeks = 0; + s->s_shrink->seeks = 0; pde_get(&proc_root); root_inode = proc_get_inode(s, &proc_root); diff --git a/fs/super.c b/fs/super.c index 2d762ce67f6e..adadf6689611 100644 --- a/fs/super.c +++ b/fs/super.c @@ -191,7 +191,7 @@ static unsigned long super_cache_scan(struct shrinker *shrink, long dentries; long inodes; - sb = container_of(shrink, struct super_block, s_shrink); + sb = shrink->private_data; /* * Deadlock avoidance. We may hold various FS locks, and we don't want @@ -244,7 +244,7 @@ static unsigned long super_cache_count(struct shrinker *shrink, struct super_block *sb; long total_objects = 0; - sb = container_of(shrink, struct super_block, s_shrink); + sb = shrink->private_data; /* * We don't call super_trylock_shared() here as it is a scalability @@ -306,7 +306,7 @@ static void destroy_unused_super(struct super_block *s) security_sb_free(s); put_user_ns(s->s_user_ns); kfree(s->s_subtype); - free_prealloced_shrinker(&s->s_shrink); + shrinker_free(s->s_shrink); /* no delays needed */ destroy_super_work(&s->destroy_work); } @@ -383,16 +383,19 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags, s->s_time_min = TIME64_MIN; s->s_time_max = TIME64_MAX; - s->s_shrink.seeks = DEFAULT_SEEKS; - s->s_shrink.scan_objects = super_cache_scan; - s->s_shrink.count_objects = super_cache_count; - s->s_shrink.batch = 1024; - s->s_shrink.flags = SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE; - if (prealloc_shrinker(&s->s_shrink, "sb-%s", type->name)) + s->s_shrink = shrinker_alloc(SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE, + "sb-%s", type->name); + if (!s->s_shrink) goto fail; - if (list_lru_init_memcg(&s->s_dentry_lru, &s->s_shrink)) + + s->s_shrink->scan_objects = super_cache_scan; + s->s_shrink->count_objects = super_cache_count; + s->s_shrink->batch = 1024; + s->s_shrink->private_data = s; + + if (list_lru_init_memcg(&s->s_dentry_lru, s->s_shrink)) goto fail; - if (list_lru_init_memcg(&s->s_inode_lru, &s->s_shrink)) + if (list_lru_init_memcg(&s->s_inode_lru, s->s_shrink)) goto fail; return s; @@ -477,7 +480,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); + shrinker_free(s->s_shrink); fs->kill_sb(s); kill_super_notify(s); @@ -818,7 +821,7 @@ struct super_block *sget_fc(struct fs_context *fc, hlist_add_head(&s->s_instances, &s->s_type->fs_supers); spin_unlock(&sb_lock); get_filesystem(s->s_type); - register_shrinker_prepared(&s->s_shrink); + shrinker_register(s->s_shrink); return s; share_extant_sb: @@ -901,7 +904,7 @@ struct super_block *sget(struct file_system_type *type, hlist_add_head(&s->s_instances, &type->fs_supers); spin_unlock(&sb_lock); get_filesystem(type); - register_shrinker_prepared(&s->s_shrink); + shrinker_register(s->s_shrink); return s; } EXPORT_SYMBOL(sget); @@ -1522,7 +1525,7 @@ int setup_bdev_super(struct super_block *sb, int sb_flags, mutex_unlock(&bdev->bd_fsfreeze_mutex); snprintf(sb->s_id, sizeof(sb->s_id), "%pg", bdev); - shrinker_debugfs_rename(&sb->s_shrink, "sb-%s:%s", sb->s_type->name, + shrinker_debugfs_rename(sb->s_shrink, "sb-%s:%s", sb->s_type->name, sb->s_id); sb_set_blocksize(sb, block_size(bdev)); return 0; diff --git a/include/linux/fs.h b/include/linux/fs.h index 4aeb3fa11927..801ff3d66caa 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1265,7 +1265,7 @@ struct super_block { const struct dentry_operations *s_d_op; /* default d_op for dentries */ - struct shrinker s_shrink; /* per-sb shrinker handle */ + struct shrinker *s_shrink; /* per-sb shrinker handle */ /* Number of inodes with nlink == 0 but still referenced */ atomic_long_t s_remove_count;