From patchwork Thu Aug 24 03:42:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363445 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 C3885C71145 for ; Thu, 24 Aug 2023 03:45:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 62284280084; Wed, 23 Aug 2023 23:45:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F88C8E0011; Wed, 23 Aug 2023 23:45:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C091280084; Wed, 23 Aug 2023 23:45:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 3A42D8E0011 for ; Wed, 23 Aug 2023 23:45:39 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0D98C1401B0 for ; Thu, 24 Aug 2023 03:45:39 +0000 (UTC) X-FDA: 81157608798.24.42BFE8F Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf07.hostedemail.com (Postfix) with ESMTP id 45FD84000D for ; Thu, 24 Aug 2023 03:45:36 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=lVZZLnG2; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf07.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.178 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=1692848736; 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=FXa1LVTr7cMGrveLuEzAv2/sv0TRtu2+M0j9hstuDhg=; b=Qd0iHVO25uGmovEBLEr8BFLIGm+5Rg8i4U5LS+PLE/gb1sNQlRAZPFX5W79+8HScNClpP1 2hz+lrP/yl61uV9CD352ZBlznY9i38a0BtCY5I5mCLaRQBxaZqid+E5po8pJgfQlGsbjZU MpWQ1gRBZx4/3dHZBagJ5iiYWNpPyRo= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=lVZZLnG2; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf07.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848736; a=rsa-sha256; cv=none; b=GyFhUx/L4xmBXYSeoFcWlwS8++d+DubvLHNaWb2QP7DTMZ5mWMmxNjyJemy6haepMs+cbL wCLjaZmUsjrOBapDNqaEJ9EKnV+EfnsHUDs7oeWn0biTiEizLiBcUY2Q5jmNUDWRl1HhcM joileA4pD1M89Wei4Hy5TLersvbQ+wo= Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-68bbd45d0d5so331100b3a.1 for ; Wed, 23 Aug 2023 20:45:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848735; x=1693453535; 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=FXa1LVTr7cMGrveLuEzAv2/sv0TRtu2+M0j9hstuDhg=; b=lVZZLnG2RsmN3a+zFL72bWnUGygaFgRp6akXzveK4gtMYRg/HADgJCRGx9wFYaUoSg pEwNRignomWbz0X2VtgkM5yh9ie22cmsn86JDSYo62UxX8AhnRWbtnxk7vsHU1TuklPr KYYlYgONHvsGMaxaPlnlctmdwx2t9FyKc/SGaBRFpkSfmwi4o4a4q0TloaM6lWreTy6+ dPqCqOkffPtxMYCMP0/9PFQmib97nVH3a2mDDsK9c1A1a3EU6i+rHDrFQYI3QbsVHTke t5Tgrl6fQSk6/O0l5wli/mgVVJqfFqz816vNoxt1a6BOYzzKWcqQBOWmo+92YHRVIkpP 4QiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848735; x=1693453535; 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=FXa1LVTr7cMGrveLuEzAv2/sv0TRtu2+M0j9hstuDhg=; b=Ze7o4vB5UiXOEIutHFu/l4KNwrvEOVMkwkE7zd4DqNjp/fAppoE8Mx0ArtHJNwryJ/ N5NmbC+xZpa1v7J+YSd/y8veblHvvASA/FTEZM01XPQM2M6ZB8Gu1UH+uvGpavWuLeNM GB52T2fuceLPambTBnvY4SU4gbGlYbGOFmu1ZWMQ8X9K9mO0MX00ZE8A2k0eZYIXZ/ir VuIUqTKBtb1RNSLac5mcbQFu8YtAwYzOcS4eJMTSDsWUTnnzlSo6H7OSeOtV4fukvF4e 3hz3F1Ls5CswP57hBHDnlAjzjRi/IOen3RHQ7bpQwNO5eSdbWMPIJzK2oF1scOk18G5M eNEg== X-Gm-Message-State: AOJu0YzYsSlu3Tcv6Q/A4Bi2toY+6bQVpXhpHWEjwo0P/QZ23IN3I/i3 TsEeoFcOI1WubVV5/eUmIHE4mw== X-Google-Smtp-Source: AGHT+IFDQmZdqE5+8g4xA8xE/nPvKPpbbUoiPsHTkmpATNJSbjrISgWKtS3Mjf4jrwQTFGPcO7csaQ== X-Received: by 2002:a05:6a00:1f89:b0:68a:33fc:a091 with SMTP id bg9-20020a056a001f8900b0068a33fca091mr13891213pfb.3.1692848735214; Wed, 23 Aug 2023 20:45:35 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.45.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:45:34 -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 , Chuck Lever , Jeff Layton , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , linux-nfs@vger.kernel.org Subject: [PATCH v5 12/45] nfsd: dynamically allocate the nfsd-filecache shrinker Date: Thu, 24 Aug 2023 11:42:31 +0800 Message-Id: <20230824034304.37411-13-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 45FD84000D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: gpqiy7pccc6ehtc41gm9co4eir5iz47j X-HE-Tag: 1692848736-198019 X-HE-Meta: U2FsdGVkX18iqSDA7AEvHsbBxGbAX1H6rbIU9ijEwd/j7OhDE/o1alt8zYUHKEGzMErVwiMKOf1x1Z3fdq2iW3XnIVs8IhI2gR0j3Cb3XWjNbjgjz55THOrUm4xoe7pzUn5VBJ2i31SpjNHpZ5ck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3CeJXwuhUmOo0SQNsDqUmFitZuTNBeqxwlrGLbqdIzUwBmtvSMNS0EqN2tuQoELEYjMVvTliGLuciH+imfAyCMbRc/seg/Z4ZBVF83RrFo7wS1deIIaW40FXIQnjI+0d3AQNhJX/JdiMZE+SJMbevz84NXGp/xa9o/SVG/mwfF6VPaBDkry0BqFcGl7qDIe168XZe+upxKfxKC8GYWJLCudlMgUwgF04DSHNK+bLqEwJgxhKaZi0EVbFxkKTXqsQSu+w4BI1Q7tcoJgpvmXm1rY1ym9hbNSsfYPcFC07inFP2YRoM/NUdPxD6XI07GQNFANxudYUS0HoiEQx9CIK6/mIhhnp/wT9cCgAYWHWV8G7/12xPe2CehlAUgYw= 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: Use new APIs to dynamically allocate the nfsd-filecache shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Chuck Lever CC: Jeff Layton CC: Neil Brown CC: Olga Kornievskaia CC: Dai Ngo CC: Tom Talpey CC: linux-nfs@vger.kernel.org --- fs/nfsd/filecache.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index ee9c923192e0..9c62b4502539 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -521,11 +521,7 @@ nfsd_file_lru_scan(struct shrinker *s, struct shrink_control *sc) return ret; } -static struct shrinker nfsd_file_shrinker = { - .scan_objects = nfsd_file_lru_scan, - .count_objects = nfsd_file_lru_count, - .seeks = 1, -}; +static struct shrinker *nfsd_file_shrinker; /** * nfsd_file_cond_queue - conditionally unhash and queue a nfsd_file @@ -746,12 +742,19 @@ nfsd_file_cache_init(void) goto out_err; } - ret = register_shrinker(&nfsd_file_shrinker, "nfsd-filecache"); - if (ret) { - pr_err("nfsd: failed to register nfsd_file_shrinker: %d\n", ret); + nfsd_file_shrinker = shrinker_alloc(0, "nfsd-filecache"); + if (!nfsd_file_shrinker) { + ret = -ENOMEM; + pr_err("nfsd: failed to allocate nfsd_file_shrinker\n"); goto out_lru; } + nfsd_file_shrinker->count_objects = nfsd_file_lru_count; + nfsd_file_shrinker->scan_objects = nfsd_file_lru_scan; + nfsd_file_shrinker->seeks = 1; + + shrinker_register(nfsd_file_shrinker); + ret = lease_register_notifier(&nfsd_file_lease_notifier); if (ret) { pr_err("nfsd: unable to register lease notifier: %d\n", ret); @@ -774,7 +777,7 @@ nfsd_file_cache_init(void) out_notifier: lease_unregister_notifier(&nfsd_file_lease_notifier); out_shrinker: - unregister_shrinker(&nfsd_file_shrinker); + shrinker_free(nfsd_file_shrinker); out_lru: list_lru_destroy(&nfsd_file_lru); out_err: @@ -891,7 +894,7 @@ nfsd_file_cache_shutdown(void) return; lease_unregister_notifier(&nfsd_file_lease_notifier); - unregister_shrinker(&nfsd_file_shrinker); + shrinker_free(nfsd_file_shrinker); /* * make sure all callers of nfsd_file_lru_cb are done before * calling nfsd_file_cache_purge