From patchwork Mon Aug 7 11:09:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13343511 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 94853EB64DD for ; Mon, 7 Aug 2023 11:17:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 321F96B0074; Mon, 7 Aug 2023 07:17:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F7F56B007B; Mon, 7 Aug 2023 07:17:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E6C18D0002; Mon, 7 Aug 2023 07:17:16 -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 0EDFB6B0074 for ; Mon, 7 Aug 2023 07:17:16 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D962A140486 for ; Mon, 7 Aug 2023 11:17:15 +0000 (UTC) X-FDA: 81097057230.12.E349466 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by imf23.hostedemail.com (Postfix) with ESMTP id 0E006140005 for ; Mon, 7 Aug 2023 11:17:13 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=IF5FMf6v; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf23.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.50 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691407034; a=rsa-sha256; cv=none; b=WGjr73Ut6Yf+8CiUDR0XNutYKKYg5iAvkN+8Ma8HxwgMSFWhQlP6E+oDvV/QecgWBkZwZE cIDxGK5OJTOuHu34V3ISNCOSTIe0XMcbH6tgCHfF2SuLaveOQgEvyi8E9ISTNa7gwM/cJy jqe8AUN9riCd5s4lhayuZP17pmssNiA= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=IF5FMf6v; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf23.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.50 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=1691407034; 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=48waxWZGd1WUnLYaDrTSxvJywKXLcopaiUkWgt7j5Rg=; b=vM2Z4rwYWwGig33w19yUIR3sI7fNIjF7YDpm1CkLsXYdaCKpSU22XJr8w8ain8nYHrmlIT Zw3M+zgMI2u+V08K3avWK8r2sL6rvMhJgV8k85kPeghxPZNw6mCN8Yy0eqo7rAxq3SzCF8 qirko70DO480XGSdWu3yS6lohJpkSU0= Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-2690803a368so591204a91.1 for ; Mon, 07 Aug 2023 04:17:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1691407033; x=1692011833; 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=48waxWZGd1WUnLYaDrTSxvJywKXLcopaiUkWgt7j5Rg=; b=IF5FMf6vfUKWXKquwpCQEDXlMw21VPTq0vQh30bzDQAe43NcnPpm7+3Lc8a3CIJRpA 3D5+DTGp/GVVz7K0qnRkJHp3ElWCuX/V5mJLE2CMMPVLrH696jMkWhUZV5knoMheDkE7 LNxcBFVMjsAliYNw3/qsjltVAMCexO3SFZuMneEunxblALcqU49wFlwUCGkH4chcrTm+ Mu+nFly5hda7TWhSn6s/LaVQ5cZernQQxFJBPj8H2QEyQDfBEaIAKgcH8kpChkzLsY8n h49b3nM+GUF7t0uuu7NHoFu5rdBXy5wqqQ2n0YE+hiJT0Y6kOYKfZmJPFvsrDsGv9xrG NHZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691407033; x=1692011833; 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=48waxWZGd1WUnLYaDrTSxvJywKXLcopaiUkWgt7j5Rg=; b=T2Qrj/qqgm3KYRjZD6gBBoKv5SYkWBcxKgHdLlbGWZqlm89RUS2SDSnJdhn/WyUZHB Dh5yhlY15KrHzqwdpINJ5h54lCwy5MbDeEXfKX7dJHX+13/HWBi4InbKquLl9qdP/n4P Sl87pack6jFUGilHh7swqbsmmHk9fuN0pMdPzLSm7UNod3wx1fsjz0Cy/9niRRByV2Bz hRymullbFsOnBR0Lfo3TlnPGxoQIxFNbwWnRM2GsKxZFYf4gl0+96RzFo1KmffIibhiu dabWvRGkvGkW9Rc/GXiCF6ldto54ZAcLdErmZiT0AVgGzrnGIdnutDbP0zQZPhT3DIgm WQFg== X-Gm-Message-State: ABy/qLYQ9DKnevaaLviM21Bx0Ou7tRsqRIpL0+CZGHM2chR950Kfu3FT oU5YWbiQULLc9pDRSN+s2n/F+w== X-Google-Smtp-Source: APBJJlHbn14CvO5TR8loNSEkHloCg3xrbjPIwtza5v7TtzUnsc09AI3fvHMVCyYd3DTpdbD1pcNBzw== X-Received: by 2002:a17:90a:4104:b0:25c:1ad3:a4a1 with SMTP id u4-20020a17090a410400b0025c1ad3a4a1mr24600948pjf.1.1691407032801; Mon, 07 Aug 2023 04:17:12 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id y13-20020a17090aca8d00b0025be7b69d73sm5861191pjt.12.2023.08.07.04.17.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 04:17:12 -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, simon.horman@corigine.com, dlemoal@kernel.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org, linux-erofs@lists.ozlabs.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-nfs@vger.kernel.org, linux-mtd@lists.infradead.org, rcu@vger.kernel.org, netdev@vger.kernel.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-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, Qi Zheng , Muchun Song Subject: [PATCH v4 34/48] jbd2,ext4: dynamically allocate the jbd2-journal shrinker Date: Mon, 7 Aug 2023 19:09:22 +0800 Message-Id: <20230807110936.21819-35-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230807110936.21819-1-zhengqi.arch@bytedance.com> References: <20230807110936.21819-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 0E006140005 X-Stat-Signature: th631eueco9hn7msmn9qge3gfys71335 X-HE-Tag: 1691407033-771350 X-HE-Meta: U2FsdGVkX1+3byK8tHC5FZXvDoAikkt4MnCr+CUJizKNSahb+6j44Lo+wghUT6H6CSpiL1xc4xVKLI8i0IkswB3FDhSCyYlh/cSwabZw4faNQSLcXoa2o4JSPX+FtvoAeurfkB1kzr2yTXE9epd2NRdqz0D0k0hCq1eHXYG9xFptS4q6KRGq2yURG+fgP22h34hBvtjdvJ1ahPF2km2gnb+uj3avUNpDZYZ40EZAWRNpqBnecWvm2GqR2YnfV8EIYRBFfk7Gd3XUF6boYfM5CaHmLWwmSi17kHlIj2magNrxckmLq5NYrwK4iF/3RU2kvihFRV+OvyLHrAKEEE65ALKHekIo+gRymJnXKhMroBTuoWUgF11iaVINTLWIjlZKjakCRdCMZvUr7LGBgiqRccVbTw8Pawv+9FitZQ6NrMVxCFMvxyotRTi7VMgbiI3704iRVuIv4y0vkzcvuGuETCZz3Miel4WY273N3Js5fwLGsHWcegwc4hkMd7Usbl64KCdAFSPM1A3ammV9YX9TI6wSYyLndHIzXRJpUFDRsqe4AkMCavAs5pkyqnTw25A1kb6vwtKdV6CeOKG4GVgZFFJ64Xz2cRJZdVe5rL2baU/1MUveqa5sYYZ5r1PM61La9HQwBo0qpqYp1QPPVhYcNB7vub11+LEvNOGqoux9n/9HbkQQF+M7tCPxdMYTDgdpFNVRm6O3B0Pr2JRVtqzJZZK5UZVAvw9D7gzxw4Vl3s7n7eYKCjLiPWMNmrAb+A8f6U6qPGEp9xG1EWIraKFl2QYVous9Ef5rCVh7l+He6PyvHmnZmofq1lQFFgrVl9fOMsex4IeYCNY35DHoDcoW4fQexPiOWKDkmUC1AOJUy2ysg0W2ZBP+X9rCWoMWjgVGobXzM2s6hlXF/ewHTjLPqHAPAOynlrFtgzoIil97x8qw/xgpBZe53gTtl0E6Hodmo0HZpPQlRvxKRG7NEht 626pb1rC jrMedwU+9sD2zAUiFCKwXrQDzhcZ9c15v95yq/cyrwukQ6J7VA/qa2+fWlumzqFQJEh0obdRRqrCnbxOElkNE3Pn+BvRCogYRWIGqLMTenCnCxAMbRFdTzQz0OEOLlbSLdAHSJry8ydjDtDkmcduQvDTUed+CqO24rx+crex9q5qW5Rr20jGAbklc24R1AkM9VZGGn8q2Y51aUI9liauW97b+C4pE+ZYF5BTHzmJ79GD7SVCzJU4bApP9t/BsL16DU9nXYYG7mMR2cy2y8INydaDY46KbELu9k6OFnIxUWmyKs52JeQLPUCQxGbxG1TFCsQS5rnz6BUX3WCW+uzXuV0kFLOPULkvlQwS/fI4ZbW3vjtXtIzLrJDoWW/jfWv848kLVLh65SHyfabR2pFNLey1bgsjd8VLxkAkx 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 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 Reviewed-by: Muchun Song --- fs/jbd2/journal.c | 27 +++++++++++++++++---------- include/linux/jbd2.h | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index 1b5a45ab62b0..4c421da03fee 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -1298,7 +1298,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; @@ -1324,7 +1324,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); @@ -1412,19 +1412,26 @@ 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))) { + journal->j_shrinker = shrinker_alloc(0, "jbd2-journal:(%u:%u)", + MAJOR(bdev->bd_dev), + MINOR(bdev->bd_dev)); + if (!journal->j_shrinker) { percpu_counter_destroy(&journal->j_checkpoint_jh_count); goto err_cleanup; } + + 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; + journal->j_shrinker->private_data = journal; + + shrinker_register(journal->j_shrinker); + return journal; err_cleanup: @@ -2187,9 +2194,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 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: