From patchwork Mon Sep 11 09:44:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379106 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 444CFEE7FF4 for ; Mon, 11 Sep 2023 09:49:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCDF96B024A; Mon, 11 Sep 2023 05:49:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D7E316B024B; Mon, 11 Sep 2023 05:49:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C463D6B024C; Mon, 11 Sep 2023 05:49:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B39466B024A for ; Mon, 11 Sep 2023 05:49:46 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8D85C1A0902 for ; Mon, 11 Sep 2023 09:49:46 +0000 (UTC) X-FDA: 81223844772.15.4CB204B Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf08.hostedemail.com (Postfix) with ESMTP id A769316001B for ; Mon, 11 Sep 2023 09:49:44 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=EPNSA7iK; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.179 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=1694425784; 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=Jp6alE9W8p4SLI20jnJ2OSu/Y8SjbH33H7WP/Pdn6m8=; b=f3Il6vRyXdfK6MCl2yrcJ6yMk95fVtzD6pfrlrFOHcKg6D1+BfzkoefDCOBYz9vBmQJ/N6 a8n7zREBMCEfEb2FKTwzzig4dgCEdag2x9Kg8tO9+NHpk17s4MtW9+7iV97dCU0KMp+CBK IxEtxsw2lOaGIPnyDKUHu1x2nQW3vaY= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=EPNSA7iK; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425784; a=rsa-sha256; cv=none; b=8MyCNqjX3b/cxpj9EaKq8LaqJfwDhLv/eQS/NHoFP8IYt3WzKxa6jDcePsQ1NIpPQ2Ke/s TLvDJGaWAVB71GyQdtMep72DCZ0rQAMbExxdXjiQUnOmv85zjxo66MGHY5ukNTLTJt3+Qi 9W771AV7x2HdsuifzZ9+Oj80Qo8Nu4A= Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1c3c4eafe95so468845ad.1 for ; Mon, 11 Sep 2023 02:49:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425783; x=1695030583; 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=Jp6alE9W8p4SLI20jnJ2OSu/Y8SjbH33H7WP/Pdn6m8=; b=EPNSA7iKJPAIlzZCSmjh4aNN189BhfFREiSD88wKXqXuC1YsGjf46/8ep1V+OzfQqH de7Y/TA8l/VqsS1lbqSa5R4SC6Bvp+TgGcRVLp/5CyTasEnChYZ/TZAbZt6vYmDYSDEq r/zD0/3es7Vo4nrD6enoEiVJctgmsrfTpJyQAdz04iqfkvKrgO80yEXFTY9coLC6fLJW PawzhHlRyiFxmvBp/Llnk3ahM4G7WQnoE2eqdyLkzY/mR3O4eFMA+y39Yl4NazPkrM2j w/shCiKvG7PX142DZuBEUpW88O86QHcbxtj8Fs2yo15/wS80BTSTBxl5sckrNJWnX8O7 SVYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425783; x=1695030583; 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=Jp6alE9W8p4SLI20jnJ2OSu/Y8SjbH33H7WP/Pdn6m8=; b=uj9BPP0fQWGp+OvnLG8zkIl0T5bFI1Mm/F0gucQmVgC4r+W/7gh6SUtFI+eZb1bE1j ejfeiia/U8CW48QyKAFjhJ/JfktDv38nnfgs8Tv9yb5uF6FmSTX4p70BNPasaNBOr9H6 c/0qh1l8oiHHdu+kaaiMt8xQeE+0RLIziFDSFv78VUfPWCCT/br3CFxRIuL+CrzWJWo4 OCVdooXkLo6vJ8aW00jJaMSQDpamaYp++usJPYdOQnhGxJqsVjDJG+FhI2bPZbydR3QR U1XxrYALgk+DwJR7C0nCFt0FRf50AcPMdoGJ6YwJt18SSefKWzVtSRL1H8qvvQAV6hum 5RwA== X-Gm-Message-State: AOJu0YyDwlPNaL+YlY5iR8ectpPUKWhXnj/TLJVpzgRrMG92U4FkvXw6 JPzsjQ4M890O2mwBSSKK/dGqpw== X-Google-Smtp-Source: AGHT+IEjw6f3kkK4YeAJ1yQh6xNTwLMG2bfCuz4XubHO4qI41qrhKwsBTZY5Hpn7PFnzgf8StICGRQ== X-Received: by 2002:a17:902:d645:b0:1c3:c687:478a with SMTP id y5-20020a170902d64500b001c3c687478amr331484plh.2.1694425783678; Mon, 11 Sep 2023 02:49:43 -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.49.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:49:43 -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 , Andreas Dilger , linux-ext4@vger.kernel.org Subject: [PATCH v6 30/45] ext4: dynamically allocate the ext4-es shrinker Date: Mon, 11 Sep 2023 17:44:29 +0800 Message-Id: <20230911094444.68966-31-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-Server: rspam09 X-Rspamd-Queue-Id: A769316001B X-Stat-Signature: ppgto8p5isi8mqfntoaiwgn8u59xjjgc X-Rspam-User: X-HE-Tag: 1694425784-242409 X-HE-Meta: U2FsdGVkX1/tmc8ZvYy0VKAuwaomDgy+mB89+EnFGJnPfwY3nh/g/i+ddQIFqI29l8HSO68oH/2EpklOKx+WQhDgVv4NoW/16ef2Iz5ghJlkkcaUcLXCOMX3x5aCjbRvmCVtwSMJqvISDGoj346j7PCZKXyB/5NPd821xgvhLkj67aqvOFvDoGR9X8Oe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n9Y7FSZg9cZnqAtbMpoytHzSqNefNkImC9ykRimCoAOSCoZ2g0+LwZ/KtV/D/KPU/PhNUzil6CUbDGG8qA9upbznwfsciSRxfO06LFNq3mZHumIbz7fZFVVhiMNu4Bi9S0PlsODxePg961eyBDAVfsCtYwJmbAXm04tz3BeMPd0rtPozwcgM92t4V4KR/T4psdmugWMkmFGCzL3OseB74++PKi1aQq5J8TtAX/j33vM/2Dm6PA0ZX4l8/gJw== 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 ext4-es shrinker, 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 ext4_sb_info. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: "Theodore Ts'o" CC: Andreas Dilger CC: linux-ext4@vger.kernel.org --- fs/ext4/ext4.h | 2 +- fs/ext4/extents_status.c | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 9418359b1d9d..8eeff770992c 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1653,7 +1653,7 @@ struct ext4_sb_info { __u32 s_csum_seed; /* Reclaim extents from extent status tree */ - struct shrinker s_es_shrinker; + struct shrinker *s_es_shrinker; struct list_head s_es_list; /* List of inodes with reclaimable extents */ long s_es_nr_inode; struct ext4_es_stats s_es_stats; diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 6f7de14c0fa8..deec7d1f4e50 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -1606,7 +1606,7 @@ static unsigned long ext4_es_count(struct shrinker *shrink, unsigned long nr; struct ext4_sb_info *sbi; - sbi = container_of(shrink, struct ext4_sb_info, s_es_shrinker); + sbi = shrink->private_data; nr = percpu_counter_read_positive(&sbi->s_es_stats.es_stats_shk_cnt); trace_ext4_es_shrink_count(sbi->s_sb, sc->nr_to_scan, nr); return nr; @@ -1615,8 +1615,7 @@ static unsigned long ext4_es_count(struct shrinker *shrink, static unsigned long ext4_es_scan(struct shrinker *shrink, struct shrink_control *sc) { - struct ext4_sb_info *sbi = container_of(shrink, - struct ext4_sb_info, s_es_shrinker); + struct ext4_sb_info *sbi = shrink->private_data; int nr_to_scan = sc->nr_to_scan; int ret, nr_shrunk; @@ -1700,13 +1699,17 @@ int ext4_es_register_shrinker(struct ext4_sb_info *sbi) if (err) goto err3; - sbi->s_es_shrinker.scan_objects = ext4_es_scan; - sbi->s_es_shrinker.count_objects = ext4_es_count; - sbi->s_es_shrinker.seeks = DEFAULT_SEEKS; - err = register_shrinker(&sbi->s_es_shrinker, "ext4-es:%s", - sbi->s_sb->s_id); - if (err) + sbi->s_es_shrinker = shrinker_alloc(0, "ext4-es:%s", sbi->s_sb->s_id); + if (!sbi->s_es_shrinker) { + err = -ENOMEM; goto err4; + } + + sbi->s_es_shrinker->scan_objects = ext4_es_scan; + sbi->s_es_shrinker->count_objects = ext4_es_count; + sbi->s_es_shrinker->private_data = sbi; + + shrinker_register(sbi->s_es_shrinker); return 0; err4: @@ -1726,7 +1729,7 @@ void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi) percpu_counter_destroy(&sbi->s_es_stats.es_stats_cache_misses); percpu_counter_destroy(&sbi->s_es_stats.es_stats_all_cnt); percpu_counter_destroy(&sbi->s_es_stats.es_stats_shk_cnt); - unregister_shrinker(&sbi->s_es_shrinker); + shrinker_free(sbi->s_es_shrinker); } /*