From patchwork Mon Sep 11 09:44:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379107 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 4FCB0EE57DF for ; Mon, 11 Sep 2023 09:49:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E6A286B024C; Mon, 11 Sep 2023 05:49:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E1AB26B024D; Mon, 11 Sep 2023 05:49:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE28D6B024E; Mon, 11 Sep 2023 05:49:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C05336B024C for ; Mon, 11 Sep 2023 05:49:55 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A51B0A0951 for ; Mon, 11 Sep 2023 09:49:55 +0000 (UTC) X-FDA: 81223845150.13.0AFC3AF Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by imf24.hostedemail.com (Postfix) with ESMTP id D15D0180012 for ; Mon, 11 Sep 2023 09:49:53 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=dy7fH+AA; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf24.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.177 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=1694425793; 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=vZpBnX4Z9eqEuCcIq983vZteHkZX7uUM6cDHYd9irL8=; b=6u0Xs5USg/iacZIUvF49YMoLVAfdp1brHV2stllQh7da6he5olhpPa5wo81Bu7u6Zfmoax i6KDkwwuaGok2AovifFJFXX3GESHjYC/pFMVZvdDrrpzK1ohMVFFHXWrrhE+5PhPAkDTPi PsphVKsZvAJl1faGgTUxaYA+ofCozZM= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=dy7fH+AA; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf24.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425793; a=rsa-sha256; cv=none; b=jbBiU9nxKVrcdMA/bD+kHvbsarICNeQJz+VfgnU8LNhmQTLxJIy7exJxiiiCRpx+RUtNMz 1IIyiHxbtKMBFccV7Si3CSF/o4I/RmxWMSVx760KmHNaRgiHunEdUkgOYmAZRxyhc8naY8 mldwi68xztk764gU1qdy+IRajz7SYRc= Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1befe39630bso9368855ad.0 for ; Mon, 11 Sep 2023 02:49:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425793; x=1695030593; 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=vZpBnX4Z9eqEuCcIq983vZteHkZX7uUM6cDHYd9irL8=; b=dy7fH+AAyfnS3G46hkXwzVFLtSNmJGuE1tNjOhO7jQogD62tsEv5v7q7Tq68cFvUtc Q4K4jv68JxsD59ytGcDP2cuiyv6cUk2t4bZQNAdowlmNBpz+NJ1Stm1jUfCgBAzlYykm 2PVFdOiSTM2OUMdr3YdkFIHeU04+kzKR1+eLzIQC5t2nhpzG42gEECNJzSrBkIqV/QZx 0GxQ5gdAhsomgHrDLc8P8WyN34yjfK+dIzHfT9Gg9RsbVFp10p7VfeRze9y6WwxrRDAY X0BRb/j/tAQ/HbA7eMnWOdfgYEeVagvblWyJ+FmLO5VeGR+ZwdRFm9HsdNSW2ZQ2yVuI 6chQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425793; x=1695030593; 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=vZpBnX4Z9eqEuCcIq983vZteHkZX7uUM6cDHYd9irL8=; b=xCzUPnS8/m/r17MljQfccJbxysV5NJ5iWUm+BASHIkzSLeciXUzzkVNPbUETbmo20G W36GiZh35ei9utvbLeoPvxNVG4Ji8rf/Ojv5icICZoZ6/4PNLfQMF8w4p/v0pO62OVgM VJ8oS/Jivg26RS165+puRnni6pfbQDYt4P3r3LZkj6W/4IGabP5igcn95TF/65eadhwt yx6y0ruV44EeDqh6wronimJyhqcNlTocbdwAs/68vlYbzMYPEynAYuhOFxBEgceUgsqh l3h2G1kubkbLM41fwTLNHxOZkeSUv5arLqy68GNGT1k2F9dEZ20Kc6mrjh1tzJsr/ZKc 9zAA== X-Gm-Message-State: AOJu0YwpV4j3MaTZ1iB5miNQkZ2mouLwyTkfw7L/OyKF3DKlggiIvcfE BSm7dk4TK/GbmXsqHkbvZD/T1Q== X-Google-Smtp-Source: AGHT+IFvqXY+jnOST4BZIc6AyFCejSJWSQ6rLQGam1YrCI9mLJF9ktChTLGkYjxBiW6SC49Zt3tINQ== X-Received: by 2002:a17:902:ced1:b0:1b8:a469:53d8 with SMTP id d17-20020a170902ced100b001b8a46953d8mr11187928plg.0.1694425792768; Mon, 11 Sep 2023 02:49:52 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:49:52 -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 , Jan Kara , linux-ext4@vger.kernel.org Subject: [PATCH v6 31/45] jbd2,ext4: dynamically allocate the jbd2-journal shrinker Date: Mon, 11 Sep 2023 17:44:30 +0800 Message-Id: <20230911094444.68966-32-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: D15D0180012 X-Stat-Signature: x4s558iannzghzoj9ppe6f9954dp9eps X-Rspam-User: X-HE-Tag: 1694425793-991989 X-HE-Meta: U2FsdGVkX1+j5l1jqwh6+mYSHRhJh70uFgBspNhatyYUrRDyra09OyqqRVDwz1ODLTCdOiI3pWtMsqnA8ynNQ4ritxB7yFjg3mR+bCHzKqgGTCwWOZwdS1cbmKrAct4acXBsN/X5I/xrzhuY/hl6CCC8YX0ojD5z8wPO1QTuxXW4pESNa5htmycgNW4smgMOwTbZxWQbAVR6OObpKgcKEnlS0St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7AdQzeLjzGrnsQb9WukteiNG6ma68O25mV/gbE++xW2TTBIwu/mHIxh3Y38HXZF/rSO0AhOhBPhOU2Z5bPHD2UB30yhvHWw20xo71UvhuyyRaaHWZTOGqIXwaQPAGD5E5hk/aD8dT1Yby9bFGlcuUSBkl3K6ySP+5oLWkiOHpX 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 jbd2-journal 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 journal_s. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song Acked-by: Jan Kara CC: "Theodore Ts'o" CC: linux-ext4@vger.kernel.org --- fs/jbd2/journal.c | 29 ++++++++++++++++++----------- include/linux/jbd2.h | 2 +- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index 768fa05bcbed..0ae19d527b22 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -1290,7 +1290,7 @@ static int jbd2_min_tag_size(void) static unsigned long jbd2_journal_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) { - journal_t *journal = container_of(shrink, journal_t, j_shrinker); + journal_t *journal = shrink->private_data; unsigned long nr_to_scan = sc->nr_to_scan; unsigned long nr_shrunk; unsigned long count; @@ -1316,7 +1316,7 @@ static unsigned long jbd2_journal_shrink_scan(struct shrinker *shrink, static unsigned long jbd2_journal_shrink_count(struct shrinker *shrink, struct shrink_control *sc) { - journal_t *journal = container_of(shrink, journal_t, j_shrinker); + journal_t *journal = shrink->private_data; unsigned long count; count = percpu_counter_read_positive(&journal->j_checkpoint_jh_count); @@ -1588,14 +1588,21 @@ static journal_t *journal_init_common(struct block_device *bdev, goto err_cleanup; journal->j_shrink_transaction = NULL; - journal->j_shrinker.scan_objects = jbd2_journal_shrink_scan; - journal->j_shrinker.count_objects = jbd2_journal_shrink_count; - journal->j_shrinker.seeks = DEFAULT_SEEKS; - journal->j_shrinker.batch = journal->j_max_transaction_buffers; - err = register_shrinker(&journal->j_shrinker, "jbd2-journal:(%u:%u)", - MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev)); - if (err) + + journal->j_shrinker = shrinker_alloc(0, "jbd2-journal:(%u:%u)", + MAJOR(bdev->bd_dev), + MINOR(bdev->bd_dev)); + if (!journal->j_shrinker) { + err = -ENOMEM; goto err_cleanup; + } + + journal->j_shrinker->scan_objects = jbd2_journal_shrink_scan; + journal->j_shrinker->count_objects = jbd2_journal_shrink_count; + journal->j_shrinker->batch = journal->j_max_transaction_buffers; + journal->j_shrinker->private_data = journal; + + shrinker_register(journal->j_shrinker); return journal; @@ -2170,9 +2177,9 @@ int jbd2_journal_destroy(journal_t *journal) brelse(journal->j_sb_buffer); } - if (journal->j_shrinker.flags & SHRINKER_REGISTERED) { + if (journal->j_shrinker) { percpu_counter_destroy(&journal->j_checkpoint_jh_count); - unregister_shrinker(&journal->j_shrinker); + shrinker_free(journal->j_shrinker); } if (journal->j_proc_entry) jbd2_stats_proc_exit(journal); diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h index 52772c826c86..6dcbb4eb80fb 100644 --- a/include/linux/jbd2.h +++ b/include/linux/jbd2.h @@ -886,7 +886,7 @@ struct journal_s * Journal head shrinker, reclaim buffer's journal head which * has been written back. */ - struct shrinker j_shrinker; + struct shrinker *j_shrinker; /** * @j_checkpoint_jh_count: