Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp2074381rwb; Thu, 27 Jul 2023 01:21:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlFHq2P1SaPCmqencVqbrbfXnr5rfEqsM7B7+eLT54a+HClprYmQqQwt3tD5Qz3yWfXkLXEb X-Received: by 2002:a17:902:c94f:b0:1bb:59da:77f8 with SMTP id i15-20020a170902c94f00b001bb59da77f8mr5519268pla.48.1690446104210; Thu, 27 Jul 2023 01:21:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690446104; cv=none; d=google.com; s=arc-20160816; b=uDDhE9UCCaus+89oq5lPQrdJtSRy1DlROit87b+hHin5GGwp+vjgYNDWHhqr4gpX6/ Jn8iVkneRnkRucg+lpXpd1ujfAfA08uRjEQ67lj0gq/69Dzq4JeiafJ2qMHDC4tQ91Fv RyLPMJkU6VQH6/C7yIovqH1Q3IZFxTjkFZsV7rJNxjkmsrpi7EaEp4ReZjXWAkCiR2Qu 3FiG3rLFbFEi3pOEjsCAaA8Bpy5Ka+fC3b6fpyfzAj3tsjPIThTDNdPcoPmwU8YhuGQU tNtKTplrfzMdV8tfjRzAigMjf1NOM8UM3qg1IUzlsPTuuG5oYcjaSjkOvsA+WJoeyOjg tuVw== 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=f+zNYaRC7WOrXvS9MeEiQUBTAQfjLjc/pgN/esuhj34=; fh=NxkGAd430gburLVd9IjvP+jLcLBa8IzZa5IqPWgCN1g=; b=jETrbh8nq5tFbM/Wdhy48AjenEZnfH1bdi+3112VWOWv4Z/q4TOiFlghzFIvsU+oLh TZkKMNc5lLsUAN/f2cIDWtxl4X/8oAz8gLsppInHVCIYtSv1T4ysEwXQhX1qM5xV14EV 8r1CXtNqqVF6Ff8MK4YZ5sDsxHWWgdCVyvMP7BD0b9vl1c29cEVFY1+CJkGxNlw5Mb+J 7h2/hMJjxyqiUiAuNeQbcFzBmWqPSKL0T2yP3chwEDWxxJApi5xxW2rPboH/NTK7hpqz QLDiuFvAX8zNrEIo2MWPPtyYMu05r98wGFzwDMxCQqSUMu6pLE+XEbjEipmGfV2J03gH 5vhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=abLX7f3+; 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 d14-20020a170902654e00b001b83fd5130asi939849pln.24.2023.07.27.01.21.29; Thu, 27 Jul 2023 01:21:44 -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=abLX7f3+; 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 S233944AbjG0IOl (ORCPT + 99 others); Thu, 27 Jul 2023 04:14:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234378AbjG0IOC (ORCPT ); Thu, 27 Jul 2023 04:14:02 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9DAB5594 for ; Thu, 27 Jul 2023 01:09:25 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-686f6231bdeso112595b3a.1 for ; Thu, 27 Jul 2023 01:09:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445284; x=1691050084; 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=f+zNYaRC7WOrXvS9MeEiQUBTAQfjLjc/pgN/esuhj34=; b=abLX7f3+1Jx7z4l7fMDPHLPoRZGZ9R0nM8ns3oWVX7aiHujgqPmDptRXrf7K4N1NV7 iafFd1vKgmMytglgpeByIm2etm8PBx6nYdrahZ4g0/dxHWR3bRoC5c0K2oAToNHdR0rs G85XXQ+OMNSfgkQPICGhKu4AFUznJk92yyLKwDX6t68bXy1Y1afxgcqF2Hrs2hRsS8Pi 1cVGQ/135Rq8DHs2i32YJ/uaSpZLHmMFkQEdBwI9bGEy1fU1/6Py8qR+g4Mw2XtURfuH rP2vSQAfzwsm7AmoQxkWOyj1kIWSKeW+aRYJEV/VwcFYAz1pgMCM8AVBtPjE13HITA/4 GS9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445284; x=1691050084; 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=f+zNYaRC7WOrXvS9MeEiQUBTAQfjLjc/pgN/esuhj34=; b=BDVXPUH+1ZSKsYlGA5M00IoJ9i0EvB1Mi/jPkvxR779PPOUY2ecCa+Lut2FbffQJoY E0GBgA9hM2PhyzqyBU23qNBZbwlIXQmxiM0oYFekPf7U5Mhc/EbpXRwKoJEvaajB3H9Z nhku5Jw2EgdrEastMcQgaAWUrmZX7/VsAYjE4X04uBouUoS2Yuvc+RzgINkVPWzeV1yc MqbX8GHQPI9eAlgacAVnAXug4G2ZfoRatwRAq0T/XqbAvMrwT6nSn5oxwlrXvGiaEJuN 6AmdFMLB2BFUcim4Yo0XB8/03+l1oIzwmdYjQRmzvVojNMz9FfE9B+jyMP5BtFgdsGQ/ CsLQ== X-Gm-Message-State: ABy/qLZg5fvZiP+f5rIlnGAaJ8HJmDu9774U6CDHFu6ZcsJaM6gb469w 1sV/eLGvtbClz4SeIzHQ1avrMw== X-Received: by 2002:a05:6a20:4286:b0:12d:77e:ba3 with SMTP id o6-20020a056a20428600b0012d077e0ba3mr6418674pzj.0.1690445284151; Thu, 27 Jul 2023 01:08:04 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id j8-20020aa78d08000000b006828e49c04csm885872pfe.75.2023.07.27.01.07.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:08:03 -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, 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 v3 11/49] f2fs: dynamically allocate the f2fs-shrinker Date: Thu, 27 Jul 2023 16:04:24 +0800 Message-Id: <20230727080502.77895-12-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230727080502.77895-1-zhengqi.arch@bytedance.com> References: <20230727080502.77895-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 Use new APIs to dynamically allocate the f2fs-shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- fs/f2fs/super.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index a123f1378d57..9200b67aa745 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -83,11 +83,27 @@ void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate, #endif /* f2fs-wide shrinker description */ -static struct shrinker f2fs_shrinker_info = { - .scan_objects = f2fs_shrink_scan, - .count_objects = f2fs_shrink_count, - .seeks = DEFAULT_SEEKS, -}; +static struct shrinker *f2fs_shrinker_info; + +static int __init f2fs_init_shrinker(void) +{ + f2fs_shrinker_info = shrinker_alloc(0, "f2fs-shrinker"); + if (!f2fs_shrinker_info) + return -ENOMEM; + + f2fs_shrinker_info->count_objects = f2fs_shrink_count; + f2fs_shrinker_info->scan_objects = f2fs_shrink_scan; + f2fs_shrinker_info->seeks = DEFAULT_SEEKS; + + shrinker_register(f2fs_shrinker_info); + + return 0; +} + +static void f2fs_exit_shrinker(void) +{ + shrinker_free(f2fs_shrinker_info); +} enum { Opt_gc_background, @@ -4937,7 +4953,7 @@ static int __init init_f2fs_fs(void) err = f2fs_init_sysfs(); if (err) goto free_garbage_collection_cache; - err = register_shrinker(&f2fs_shrinker_info, "f2fs-shrinker"); + err = f2fs_init_shrinker(); if (err) goto free_sysfs; err = register_filesystem(&f2fs_fs_type); @@ -4982,7 +4998,7 @@ static int __init init_f2fs_fs(void) f2fs_destroy_root_stats(); unregister_filesystem(&f2fs_fs_type); free_shrinker: - unregister_shrinker(&f2fs_shrinker_info); + f2fs_exit_shrinker(); free_sysfs: f2fs_exit_sysfs(); free_garbage_collection_cache: @@ -5014,7 +5030,7 @@ static void __exit exit_f2fs_fs(void) f2fs_destroy_post_read_processing(); f2fs_destroy_root_stats(); unregister_filesystem(&f2fs_fs_type); - unregister_shrinker(&f2fs_shrinker_info); + f2fs_exit_shrinker(); f2fs_exit_sysfs(); f2fs_destroy_garbage_collection_cache(); f2fs_destroy_extent_cache(); -- 2.30.2