Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp10593339rwd; Thu, 22 Jun 2023 02:00:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5hsxQkBRjjsa1aRhUlqbwlKWWxF8u2Y6qGvg26q2hsNwRx7Xn6ixyLC1Yayr748DqAE9Yc X-Received: by 2002:a05:6830:39d9:b0:6b2:dc79:5870 with SMTP id bt25-20020a05683039d900b006b2dc795870mr15312067otb.36.1687424442246; Thu, 22 Jun 2023 02:00:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687424442; cv=none; d=google.com; s=arc-20160816; b=HWimtIWtGC+53rn+UbeMRAtFT4SLE3KKgGgZUCbvkAU2hAH8rJlHu7+sx0snoJ4Ou+ oR4qd5s5Ovthp6+vihGgMT2elFO7x0Cgkixarg8lLmH4ouV9+Ooe4j60M+gQmcx9PEby AUwepFC/Q47cem9wW2ISM6FdhwjfAAh90+E0Uyb9E3bxCoaYJkZCJqTP7yKdH8hnXFDj 5SqbbdhigH/MXXmYE3pL3Smcxs7e0Cqg67Cul2VDtz3AcwdtywYOc06lS7sLukbWTfnr lPEgOIHydV/gxjYNqdsSp1Alfb5PA7VC0SEKCWs2OKocFCBvH6xVC4iL3DiSKgKNHCJq MhXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YV1TxBHonYX3pT+e4dDoFW63Wrih64tWAHWeaspLQMY=; b=t/nGtc4jNMDSV7oxlzLRBkjgZ6ps4LXmERrEQGa9UmNE+HTWwnLZ8NzU5ydtm6/EbY RV7jWxuRGL/hoNADHx+bz6JiWgss4G1M0XDTl1HbQp+1xw6xmhLNQl7PcPOiYrVwvc1j A4l2SZyCMP+X6Om1KkAiLUbL9KNkpArvWs+rv83mYKUV05bGqvoATHbNjCakuOeOAbTt ZxTF7wPI8P8mN6RfY0i+BDCEelChmQgZBbVnPSDQaN7FTn/uI57qIrchiQ8WvVoMpSVc NRVNLugB5coaRYIXp1H36HDmGAuRJI/rqhCnVvFx7Wi3yvR8FwNlBzuEQ/DWsDGX2YLk 7WoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=IN1IoI2u; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m9-20020a654389000000b0055388b7ddcasi6082020pgp.317.2023.06.22.02.00.29; Thu, 22 Jun 2023 02:00:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=IN1IoI2u; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231624AbjFVI7l (ORCPT + 99 others); Thu, 22 Jun 2023 04:59:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231630AbjFVI7H (ORCPT ); Thu, 22 Jun 2023 04:59:07 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFA97297A for ; Thu, 22 Jun 2023 01:55:56 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1b5585e84b4so6828185ad.0 for ; Thu, 22 Jun 2023 01:55:56 -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=RqBlmkTXj0z077+gZ3q7qd+aUtBsX+JO/GqHGRfMKIRA9qYiOnzick3ECZqGjv8YJj UNgQqBqKyAE119+NM+UETuvhwNvBRJRXk2yUTi9woc2QvyJhrALTUXnNZOt01wH6CIHM +7exgCO5TTCYuB+UiseGY/b2ZHydJzR7ld54nMcijkwtc8hwl0ceytZFWDOXLeqELiDg ao/Y1SWyCO4ZHVnlkld53aLaPzVzz6Kgl5JAN77i7eFsdXGzNAeZigVnvv9yIs+pS0l0 oxdVqI4BaUrF5HmFoybRNaos+NBP8GjE38+2buHJhs/FcW0L/m6NYBL7b1ah3U1c2GBI MOag== X-Gm-Message-State: AC+VfDyx8Xsugv5yGCvU1IjrfuOMoKkOZcriNpMDs9pTGQQfFlPJCea3 myPkSqxibB6dmvcVfdoTxSSchQ== 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org 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: -- 2.30.2