From patchwork Thu Aug 24 03:42:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363495 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 8B9D9C71145 for ; Thu, 24 Aug 2023 03:48:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 27A5F2800A6; Wed, 23 Aug 2023 23:48:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 203D98E0011; Wed, 23 Aug 2023 23:48:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07D2B2800A6; Wed, 23 Aug 2023 23:48:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E7BFB8E0011 for ; Wed, 23 Aug 2023 23:48:35 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id BDC5C401AE for ; Thu, 24 Aug 2023 03:48:35 +0000 (UTC) X-FDA: 81157616190.06.CBA6928 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf13.hostedemail.com (Postfix) with ESMTP id 03B0520007 for ; Thu, 24 Aug 2023 03:48:33 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=glrCcAGl; spf=pass (imf13.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692848914; 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=zC9WqkIww9J/yjcNVRfpW3XQ6AEKQ/LjI/iUfI4jlaA=; b=wZOYBD/isRhflSSHa+DYwbHoEcqvUhsEPaKIqm/QpkrNZ2xljWOIJn5tZNM6wzTpFMZuzD idptFaBhmDw1Ow1MOS7Zy5L03GYEaRzdntVmOm8wrhzk2BZe1tewAYMDNHFFdRiVVucJT2 r1mA0yjpTV5NuRVgpf96JHjNPlXsU5M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848914; a=rsa-sha256; cv=none; b=oYUmzrJ36X7tGCckGG0uZRMkbxPDr44HF3ls59IwUckZxEW9XUaE1twpAw5G6waGTV5EqN 3DfjMqZTIsNfQ4D1+f2FXbxNXm9kUEM14OgO5FX6VlnqSM6buHBxbY0KHvGSVnp8BILsyF DWa5E89EuPbg6hQuvrDnG707M1EGR9g= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=glrCcAGl; spf=pass (imf13.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-68a56ed12c0so756316b3a.0 for ; Wed, 23 Aug 2023 20:48:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848913; x=1693453713; 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=zC9WqkIww9J/yjcNVRfpW3XQ6AEKQ/LjI/iUfI4jlaA=; b=glrCcAGlI9tORwLN4JeOX2Ojmpg3nd+ma/3S7SfNP2JPT41zIZ0IQM10eTVKPLkYqI pg2c3cj/mxF72M7VVk2LY+U28qMFYAPfxu7KPD67Jpu5o7z+DfyV007ggfjzdgLysN82 cVDAiZHzpVRc6gETtIv1NBFK6Hvgz9JH2aOGng4fmagYixWYge8xFOfj1w99o4OKSpcR lqLQMu8XVXXZKfG0W+wqfQnFIKtFhj4kiY4i3y6Fokx88A3jo9QjLRBpri3lqrfzuIJu U/0aQHnJg90B6KEbY8BJ7rA54knmfENUkK0fN4nXKSLjT+G6swoIKswdwLSd7IVK09ma wTRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848913; x=1693453713; 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=zC9WqkIww9J/yjcNVRfpW3XQ6AEKQ/LjI/iUfI4jlaA=; b=FQAx8Jz5PmM7Vn8fQ3jKOyjGzXdv89prPtzanidN+2ywhNFNYWnE3az0fE2eKBhR57 6du0QxoIdgsPzdgXHbzfe1AxsbOJ4yj2RERDtJgMG4s6Kz8VIfJ9QaQCw8RkctDXJI0q u41sTbxYMx62CMSpryxJfF9aFVOUrfaYL7xKD6/qsz2BKeHLCTLRgHjHE5HUdUSzpHmT pZ3m0lke97bIJUn+Qpt7EyMlBl5hgZufH70B+tHSRF4dPgmRLUCbe5eeimAk57IuKHkk E9QL1Puhk9mqN4mF6nhIK3qmqh5XRX5Z6x/52omqz9tvVFd3wTLtkqU2ayglj6cisFNp 7MIQ== X-Gm-Message-State: AOJu0YyIDX73OLNxO16FvvZaybwztNd2iVlI5DeBAV0/oxm1YwD8k0eV cZsdDztytVmOhlJejrauV8LOdQ== X-Google-Smtp-Source: AGHT+IEQ29rJQXeZVflVKNLar0GggbK4xIRfj9VbHOaq33vMQI6xRJWrdG4vksRQlcd6vKsocE2yjA== X-Received: by 2002:a05:6a21:78aa:b0:133:7a67:b477 with SMTP id bf42-20020a056a2178aa00b001337a67b477mr18675611pzc.1.1692848913047; Wed, 23 Aug 2023 20:48:33 -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.48.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:48:32 -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 , Chuck Lever , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey , linux-nfs@vger.kernel.org Subject: [PATCH v5 32/45] nfsd: dynamically allocate the nfsd-client shrinker Date: Thu, 24 Aug 2023 11:42:51 +0800 Message-Id: <20230824034304.37411-33-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: 03B0520007 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: ieej1yipz5gsr4wbuwd94pi4jmmj3rxa X-HE-Tag: 1692848913-102058 X-HE-Meta: U2FsdGVkX1+XTRcMYzo456epI+M2nEQA9srdrC8Tf4dZaZAlG+nPNGSXRo1heaKCFsCs8ikTQhG++kuICRpJCngV6/TGevWY4tssnX+xfrnzAFYmaX55IrwFhG0Q8PMZDGoDtS30T4qjETaLGFxvpDzuSvrTecPUnYCzkp+P0QolE7kp/4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nr4or3gwwCGoW9/nXtTXR3vAjEXtlZmP38LuB8JfA2tbNC9wqELzYNFy1EFfwTxlaYpPTXiyIJNVBpPHqQ16xCnCuAc6tuYHlFSs4Mre7BTC+/2T0u3qofcgNJnVYWgMXDWGYWlrF/VubiOgIy7i1NvXEsK5GddCSdKoBPzHEJ9HGI+udm6dfSn61gpTxAHpMrZ3Z0DFwW46zOgD4Xe85oYIahfA9uhtPCNo0HUKSrsRL+pnulFhm6s1CI3Bqho2TNDoQs4oII9hOsQ22c+gUR7Ja2Mt0EWYQ9dE8+37SilnuzyWiE3U2TpvmJCvQW0FsvBrfP2OGLIS8vu/u+saKf8= 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 nfsd-client shrinker, so that it can be freed asynchronously via 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 Acked-by: Jeff Layton CC: Jeff Layton CC: Olga Kornievskaia CC: Dai Ngo CC: Tom Talpey CC: linux-nfs@vger.kernel.org --- 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 4c6a94a9699d..b2742065a813 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4400,8 +4400,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) @@ -8149,12 +8148,17 @@ 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(0, "nfsd-client"); + if (!nn->nfsd_client_shrinker) goto err_shrinker; + + 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; + nn->nfsd_client_shrinker->private_data = nn; + + shrinker_register(nn->nfsd_client_shrinker); + return 0; err_shrinker: @@ -8252,7 +8256,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); + shrinker_free(nn->nfsd_client_shrinker); cancel_work(&nn->nfsd_shrinker_work); cancel_delayed_work_sync(&nn->laundromat_work); locks_end_grace(&nn->nfsd4_manager);