From patchwork Thu Jun 22 08:53:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13288647 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 D1F32EB64DB for ; Thu, 22 Jun 2023 08:56:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7201F8D0005; Thu, 22 Jun 2023 04:56:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D0528D0001; Thu, 22 Jun 2023 04:56:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 598628D0005; Thu, 22 Jun 2023 04:56:07 -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 4853D8D0001 for ; Thu, 22 Jun 2023 04:56:07 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 151CF40B1C for ; Thu, 22 Jun 2023 08:56:07 +0000 (UTC) X-FDA: 80929776774.16.6757A38 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf16.hostedemail.com (Postfix) with ESMTP id 3B9E8180014 for ; Thu, 22 Jun 2023 08:56:04 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=W9Q0mEFJ; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf16.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687424165; a=rsa-sha256; cv=none; b=oQIJf0uP4bwRqAhXgKiLhmLQ9hYV9lgUyr614q3mhFIDnSrjKgxMSEjrQyH1LoCmEdjtOH 53D4hcdU+Q0v35SyreUYPvL7i01bycItXZ7YDtECCvEWgNLGICTfxfv7a8cX1G3Q4iUhVX kWHL1gHFrk0AgkYfE2Y//oZYMka+qrk= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=W9Q0mEFJ; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf16.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.175 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=1687424165; 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=FWRSgLiVxGu7by+bRdZCMSZgL2CmyzCgjcAmFywfg3g=; b=Y0lKBkgL/Zbdxf2rCafMWOyRWBNXBBKDHrqaCms2wiVnqAhHTaAkzzGNaUqLOCrOqajgNA 4O0kDGKIvDOnRvZIBD9lqjBLcswkz0BlyLY+bA4cYW9Jl06u6uqDvTLYw/+pyEBDO3sb/2 pf8ket5DXcOiBuEDdCNo9qAZ+5bwW04= Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1b5466bc5f8so9654925ad.1 for ; Thu, 22 Jun 2023 01:56:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1687424164; x=1690016164; 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=FWRSgLiVxGu7by+bRdZCMSZgL2CmyzCgjcAmFywfg3g=; b=W9Q0mEFJ4YX/Kxo42ZpDHLFmjt3CYHNqumMzPD6lCEJ/AclBj6ki+9nXx+XP2OFoT9 biokZFjtTO4s6n85EeiNgXVRb8aHb7r2IMBB+HnwNOlBqet/0l5xfJVO+DolK/U7XTWU M277NuxA39AWH+q/lhKoP2vIlehvWLhpgJj/4uGWoGxCITX36OL+YHFtfzDKSSw2iPaX MbP+C5V24hBPOg4LWw9eV/ZehzOW8RyY8zV5pnDOyFwQ720HnrExvRoWQvOw0JMgQMOU XwvMcYncbAVdeNBjwwgU6wHkMwvamAyfgHl3RPNu98UxqyF0R9Sxc8Wx/1hGBgxkRDYX Kkuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687424164; x=1690016164; 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=FWRSgLiVxGu7by+bRdZCMSZgL2CmyzCgjcAmFywfg3g=; b=HgJEogKspnwVpZvGppOeBIehYLkkkMEFbGq60SGlxSNyygydao0YJVfecBns2NwhSf ikLmQGQtITOoElwuulSdhionU7tflLtcBzZcRvlP4Fb2GaitunUkLrXsf8x8ulAcJYfz qAU/oEk4rM9IbiUNA0eodMhF9f31DC+rAxGnJO8WFCS0bqE5VfuXcUxM4xuXWQeWGhOq PB06cxrPGE1EVVWRYO4KLSbs6Fl6WoAZD+kZP0DEylwItDlNmW3571qnNclRPN1jwC5V q5aB60J803OsN2sGqp0/PlEKEAzxiIFgdnHPwjQ/UFbl0WwruzhZkCKbkGKG0Nb6l750 kpgg== X-Gm-Message-State: AC+VfDwJ9sZBnPt3Ze5OwXBNCZ2gyoztKgLDY5gpzfQPqD9VaWLufY6o jRJx47vdn2XvhfSpFslXeuf7ea1dYc9nGxbGsy0= X-Google-Smtp-Source: ACHHUZ4nYFfrGKqZLYUWSywLes9hZrkxqoQAJfwtv5FmoHmc5MLCqSR93ZcAMHhMn41B6ov+vpDAfw== X-Received: by 2002:a17:902:ea01:b0:1b0:4680:60 with SMTP id s1-20020a170902ea0100b001b046800060mr21968987plg.1.1687424164102; Thu, 22 Jun 2023 01:56:04 -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.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jun 2023 01:56: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 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 15/29] NFSD: dynamically allocate the nfsd-client shrinker Date: Thu, 22 Jun 2023 16:53:21 +0800 Message-Id: <20230622085335.77010-16-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-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 3B9E8180014 X-Stat-Signature: ms3aaqptfm6n4qeqcxaohtz119aiwr1e X-HE-Tag: 1687424164-858578 X-HE-Meta: U2FsdGVkX1/u4HCW+Sp+oCsGPKfQAudE6ws02PTCZyChwByRWRxESB/jpBCrUkbGsrNjRROinahRe5dqYcb+qSwEUUysvAAfcLKKDpRMm7JwEU21Yzg70i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+oeM9LDKdQvb3BK6rKneQ+MYW+6KUw4xs5f3bRG58olZJKhrtAjykEqQv4H9j1H+1LfKUvR7bziPFu/M7RZ2rx6SOEmFC4M3tr5TCPAwmOG9rA9lO9lcFcil/mWkKkyaNAp9gpl3LVuWbERfpP1YO9HuvH0xxiqe9pCJ8P/XvyVUN87Ok6U0Zc4c7JuKwPtI4AIdIwO97cD9L/a 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 nfsd-client 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 nfsd_net. Signed-off-by: Qi Zheng Acked-by: Chuck Lever --- fs/nfsd/netns.h | 2 +- fs/nfsd/nfs4state.c | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/fs/nfsd/netns.h b/fs/nfsd/netns.h index ec49b200b797..f669444d5336 100644 --- a/fs/nfsd/netns.h +++ b/fs/nfsd/netns.h @@ -195,7 +195,7 @@ struct nfsd_net { int nfs4_max_clients; atomic_t nfsd_courtesy_clients; - struct shrinker nfsd_client_shrinker; + struct shrinker *nfsd_client_shrinker; struct work_struct nfsd_shrinker_work; }; diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 6e61fa3acaf1..a06184270548 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4388,8 +4388,7 @@ static unsigned long nfsd4_state_shrinker_count(struct shrinker *shrink, struct shrink_control *sc) { int count; - struct nfsd_net *nn = container_of(shrink, - struct nfsd_net, nfsd_client_shrinker); + struct nfsd_net *nn = shrink->private_data; count = atomic_read(&nn->nfsd_courtesy_clients); if (!count) @@ -8094,14 +8093,19 @@ static int nfs4_state_create_net(struct net *net) INIT_WORK(&nn->nfsd_shrinker_work, nfsd4_state_shrinker_worker); get_net(net); - nn->nfsd_client_shrinker.scan_objects = nfsd4_state_shrinker_scan; - nn->nfsd_client_shrinker.count_objects = nfsd4_state_shrinker_count; - nn->nfsd_client_shrinker.seeks = DEFAULT_SEEKS; - - if (register_shrinker(&nn->nfsd_client_shrinker, "nfsd-client")) + nn->nfsd_client_shrinker = shrinker_alloc_and_init(nfsd4_state_shrinker_count, + nfsd4_state_shrinker_scan, + 0, DEFAULT_SEEKS, 0, + nn); + if (!nn->nfsd_client_shrinker) goto err_shrinker; + + if (register_shrinker(nn->nfsd_client_shrinker, "nfsd-client")) + goto err_register; return 0; +err_register: + shrinker_free(nn->nfsd_client_shrinker); err_shrinker: put_net(net); kfree(nn->sessionid_hashtbl); @@ -8197,7 +8201,7 @@ nfs4_state_shutdown_net(struct net *net) struct list_head *pos, *next, reaplist; struct nfsd_net *nn = net_generic(net, nfsd_net_id); - unregister_shrinker(&nn->nfsd_client_shrinker); + unregister_and_free_shrinker(nn->nfsd_client_shrinker); cancel_work(&nn->nfsd_shrinker_work); cancel_delayed_work_sync(&nn->laundromat_work); locks_end_grace(&nn->nfsd4_manager);