From patchwork Thu Jun 22 08:53:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13288593 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 E2E11EB64DA for ; Thu, 22 Jun 2023 08:55:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 831968D0006; Thu, 22 Jun 2023 04:55:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E1E28D0001; Thu, 22 Jun 2023 04:55:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 682E78D0006; Thu, 22 Jun 2023 04:55:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 5A6A78D0001 for ; Thu, 22 Jun 2023 04:55:59 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 3EDD4A016C for ; Thu, 22 Jun 2023 08:55:59 +0000 (UTC) X-FDA: 80929776438.02.ED6CB78 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by imf14.hostedemail.com (Postfix) with ESMTP id 5BF5B100006 for ; Thu, 22 Jun 2023 08:55:57 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=IN1IoI2u; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf14.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.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=1687424157; 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=YV1TxBHonYX3pT+e4dDoFW63Wrih64tWAHWeaspLQMY=; b=hZHLMw7olA49iICfqpmkhRhZVGahJU88KpJenO0s4wI0nUtKIkILcpj6z226djoTGmmUPh tRtLLvvVbL+QDNKQPtrzqXqPzpDKMSljnpCYOb1nXDRxM28+6AtkUYNNMD0RlZAGu0CHX/ KeiWJnMZW15Gvg0k1mR3z5fpUdiMQEw= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=IN1IoI2u; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf14.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.177 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687424157; a=rsa-sha256; cv=none; b=fpagBVdbP5Bb5fhx2GB3uX/NLABpnT8NsPvl2bi2MlWV5LkECo2yhk9GSRSDzk+3A+8Lhi IXQKOuAFA4tqoy4PFv88F4mnOSNB6LtSvZ3yUm1xq0dXFqPci/R599XzXu3Oyfz+pKQORf nUQ+OQLZ1HLkRItqSBet/MGBViGrPbg= Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-54f73ef19e5so678893a12.0 for ; Thu, 22 Jun 2023 01:55:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1687424156; x=1690016156; 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=YV1TxBHonYX3pT+e4dDoFW63Wrih64tWAHWeaspLQMY=; b=IN1IoI2uOCQQeS9Pc7yMEYFtdbTKp2FDPBFMAyikkB3bBw/FCEgPQpTXBrLGJxS9op OYz9dXXM6oULWR3l3wYKXb5/BI9AkFpryZP4yoepCwR6hfyyNUOfJ8hsO4sBRwfJ49YX gUV9lDqFE5hQ/d7HdmIIwZSFFlm7MsgfCCmjn2SzIPpkrW6AhbhGMDaDZJJIRMhzbnyY 28028P9U8PoGDzKdCZpYkcFtSyvZMpWWRxH6zTertHKnPVPdcLDGdjwoWDesvLV0LnN9 TRCiB1NZo1an6jc3DcyUcaVRTuirz1I2fp4pQQgMnnutBNGuXTEGp5MRQRxr/+etF0+R bUJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687424156; x=1690016156; 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=YV1TxBHonYX3pT+e4dDoFW63Wrih64tWAHWeaspLQMY=; b=VmGVxAYJk5TN8umf1oLMRexWQojMGxbUGYG8IJ9HNej2GZcjylyrpthtHVwBrXOwku cp+MAwp5rkSy3SxebXZ8Q8EZXy8AwoSXEwgGnT6+NfGcswj66WIw5x4FqtnTKXl//0m1 kE6wafwRRlsgTeXsQwoTldpNaAhHqwxCIV/y6C+kfkiZzq+CvAI16nJXDPB22XVjLJ21 QmsxuYHE/9mocyiJjNa9/n9n6jqAK4MrjghRkiTPE8OVO2J5AhgFpNE4a9DJ/qe9Bgh4 N/vkP/ATAWYhBEm/Z6PcWjGyvlolCb+8JEIpaBBOY5lpATL1XNrJWz/Gh1GPM8rcOJ5P fHyA== X-Gm-Message-State: AC+VfDxnXyAgWkr8hZl8by58WcVhb62BRvFDxZF7R1z0XzltMFbH+Lhw l9VN50lHQA0c5funJWgMQX8/5A== X-Google-Smtp-Source: ACHHUZ6yC2snRIv6FqrsdGDMg/3uXpE9V6V7JpWahZzREljgaxmC3AuzAW6pVJNk/nQXbwoLHaAThg== X-Received: by 2002:a17:903:2451:b0:1b0:34c6:3bf2 with SMTP id l17-20020a170903245100b001b034c63bf2mr21540756pls.5.1687424156178; Thu, 22 Jun 2023 01:55:56 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.254]) by smtp.gmail.com with ESMTPSA id h2-20020a170902f7c200b001b549fce345sm4806971plw.230.2023.06.22.01.55.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jun 2023 01:55:55 -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 Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, dm-devel@redhat.com, linux-raid@vger.kernel.org, linux-bcache@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-nfs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, Qi Zheng Subject: [PATCH 14/29] jbd2,ext4: dynamically allocate the jbd2-journal shrinker Date: Thu, 22 Jun 2023 16:53:20 +0800 Message-Id: <20230622085335.77010-15-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230622085335.77010-1-zhengqi.arch@bytedance.com> References: <20230622085335.77010-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: hsk4888ynrmdnemk8hxaxzhgb3wz6fc4 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 5BF5B100006 X-HE-Tag: 1687424157-420243 X-HE-Meta: U2FsdGVkX1/FyaokULEyFhqEDE819xrH1LDIvELu3fVIo/UuEQv118EuHmaliwtpAa+djznYFPoDZ3TXrddnx5gKtLjCLUOFG4owVr+cc5QhvNFcgdkTQzm/etaO0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0DqGEms7SbFZ57PuPqJHR2EVvFCu+EMQozeg4Ob86C/0lGpcbHSs1kK/Yvv2bxBS3NsptgWO45Ilpvzpbx9FdBq/61WK5Z9Jhd3l0tNaJHQNdgx11CWZKwWATXJxhR9fIDXqfMfYPZT0e0BTansSwdR+TaPwc9Cy+ucrXLVVg/8IU6zs/iDf6KEpmVwYd5Z/PDUrFLAK7 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, we need to dynamically allocate the jbd2-journal shrinker, so that it can be freed asynchronously using kfree_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 --- fs/jbd2/journal.c | 32 +++++++++++++++++++------------- include/linux/jbd2.h | 2 +- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index eee3c0ae349a..92a2f4360b5f 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -1301,7 +1301,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; @@ -1327,7 +1327,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); @@ -1415,21 +1415,27 @@ static journal_t *journal_init_common(struct block_device *bdev, journal->j_superblock = (journal_superblock_t *)bh->b_data; 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; if (percpu_counter_init(&journal->j_checkpoint_jh_count, 0, GFP_KERNEL)) goto err_cleanup; - if (register_shrinker(&journal->j_shrinker, "jbd2-journal:(%u:%u)", - MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev))) { - percpu_counter_destroy(&journal->j_checkpoint_jh_count); - goto err_cleanup; - } + journal->j_shrinker = shrinker_alloc_and_init(jbd2_journal_shrink_count, + jbd2_journal_shrink_scan, + journal->j_max_transaction_buffers, + DEFAULT_SEEKS, 0, journal); + if (!journal->j_shrinker) + goto err_shrinker; + + if (register_shrinker(journal->j_shrinker, "jbd2-journal:(%u:%u)", + MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev))) + goto err_register; + return journal; +err_register: + shrinker_free(journal->j_shrinker); +err_shrinker: + percpu_counter_destroy(&journal->j_checkpoint_jh_count); err_cleanup: brelse(journal->j_sb_buffer); kfree(journal->j_wbuf); @@ -2190,9 +2196,9 @@ int jbd2_journal_destroy(journal_t *journal) brelse(journal->j_sb_buffer); } - if (journal->j_shrinker.flags & SHRINKER_REGISTERED) { + if (journal->j_shrinker->flags & SHRINKER_REGISTERED) { percpu_counter_destroy(&journal->j_checkpoint_jh_count); - unregister_shrinker(&journal->j_shrinker); + unregister_and_free_shrinker(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 44c298aa58d4..beb4c4586320 100644 --- a/include/linux/jbd2.h +++ b/include/linux/jbd2.h @@ -891,7 +891,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: