From patchwork Thu Aug 24 03:42:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363496 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 9C36DC3DA6F for ; Thu, 24 Aug 2023 03:48:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3DA658E0015; Wed, 23 Aug 2023 23:48:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 363588E0011; Wed, 23 Aug 2023 23:48:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1DD2C8E0015; Wed, 23 Aug 2023 23:48:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 0D43D8E0011 for ; Wed, 23 Aug 2023 23:48:46 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id DF737A0195 for ; Thu, 24 Aug 2023 03:48:45 +0000 (UTC) X-FDA: 81157616610.03.B967289 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf15.hostedemail.com (Postfix) with ESMTP id 1DC3DA000A for ; Thu, 24 Aug 2023 03:48:42 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=lO1BdOc8; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.169 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=1692848923; 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=iZYFEziqHKQTs36ii9IxaHzQyRy7+HnptX1eUkyxsok=; b=VQfY1MCN3V3EFlPWSPDIANS6+b+v8SKrLcWgVsNTh2RoRewdE6sJ2Gyd20ais9HMzyKG+6 u4H8vwziJEI3S2XnWtWp+qtzvGpQO53B3aOI224Cj9aQx8astcR4Pb/QjAUtUSCgu/5A6x 3WDybimpEEHH2ldo3zLgReSzqsw+9iM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=lO1BdOc8; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848923; a=rsa-sha256; cv=none; b=dBLfgtHOvv7hIGZyXfc9NLbLmwuVF1dtD/hnfO2f1VgvKuVXZo2TjX39Da0PbUhUPK3nat ubL9hx7g2v/UHCpvryM9YRkrNukr4Asb38WnFBYF8C6lyHKzNqPm1eo/5LrrvWkIMRnZ2W Mt670uTEGUtHbAswT1ndpy6DdfHkU8U= Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-68824a0e747so1238304b3a.1 for ; Wed, 23 Aug 2023 20:48:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848922; x=1693453722; 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=iZYFEziqHKQTs36ii9IxaHzQyRy7+HnptX1eUkyxsok=; b=lO1BdOc8IC76LRNZfOyYy9eMSIbqStBvooSiHRS3AafY74HoA5BqZ6t+3TGAl0AtpZ rev6hFOx+kyDkPHvZWJq9q0vP81aFRlb10Zk0Fn/fmFGc2gfXltX3ouoNMCO0npH2OYh mHzGaYb9GR0YpvYgV0F7nGHXI+2qAfWk7jBdjnrbHQ7ZoXsBAkbTq8I4pxbSsEHVsDz8 ZP9W981GjOmUSABfVm6ksphZLc3U0h1/AMUeOlX2AabLS3bbzoyM3q214L12qJTAcaI8 AuxZhADwW/QQM1sMR7rpIuhO83gYxeJqrQlI0CxOm2IAMzWUOcDbXFo7LC97q86bZmDo i6+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848922; x=1693453722; 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=iZYFEziqHKQTs36ii9IxaHzQyRy7+HnptX1eUkyxsok=; b=XiHyXBICBk+DjfMpf08z48rUOYQ+6TfCktTC0VYTYpZ0z+42yyb2n5H3UjKNWCMxXo qQ6oiG/ruWiZMoAbxkodSSjt6of1BHyE5pGzHs9+gwvxwcWQJsTwRIoXQ+iyjpttfCXM J3HZTgn1LcsjHrftRMM596KSNf8PN5Qz+YUBbI/kWz4pI8lGnn7437Ces0pYLZsLKnMy Cq7ZnRy9M0KrmJeOwL3Q+YGpaV3XnVM4HyG5xkiRQ4Bp1RBQB0z/O2Kuk6RthPGkG6sd obV7/8H7LJ7JPMh50fldBUJwf2tgDksbPwAAvG3A2x4c9Sjfioduo/pjGtFSrgVoGyXk E8mg== X-Gm-Message-State: AOJu0YxukNffF+aqNNnHJO7hpw4MCtMJgOWNABS794f0Gscub5ar8WGC +3nN8HgY8yI4PGzLUXbk/6qHog== X-Google-Smtp-Source: AGHT+IGiDI02Gkdoww8eG0IG14i0OeHJi8Gmt0fnAr81rlF4DRqTG1oQfD1+mqVI4jvLZxUezjNelw== X-Received: by 2002:a05:6a21:6da5:b0:133:6e3d:68cd with SMTP id wl37-20020a056a216da500b001336e3d68cdmr17945492pzb.3.1692848922018; Wed, 23 Aug 2023 20:48:42 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:48:41 -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 , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , linux-nfs@vger.kernel.org Subject: [PATCH v5 33/45] nfsd: dynamically allocate the nfsd-reply shrinker Date: Thu, 24 Aug 2023 11:42:52 +0800 Message-Id: <20230824034304.37411-34-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: 1DC3DA000A X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: f6fhn6fhxxzg4qqicxkzumz4tpjzg74b X-HE-Tag: 1692848922-261035 X-HE-Meta: U2FsdGVkX18TEEI5Y0FMDhoAv+ZW87cVCm8pMxrUiD3fqb0590TklaGz/nO21qCI3sFGRq1VpdxpFfhJQmfp+5CfjuXOKE+E9Q63cXTASW7dsLX4QwjoS40xDuF8F0LdL6YLhJA2PIU9K5DoG/phYFyxU+TKtcJg0U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xCaTNp1rlwLEtZ9/0yjhm2344g9oneQjZdc+Yk2p9fzG5aFPXRxaMoBvIlE2wUrQmyeJsAm4Cnv3h4qZ8/U4i9IOHLs7LrMAsNjY2HFBOoMo3AFyRVpOp6zaiZsodv7cWE67LKY0ZB4qwZs02K9V1JUZLj8zkaWDxBx5TKzhwDvNnEIOBkpTXEhnmz7qDOphSYqqLQ2GkNJeUNXbrA+91tuqfAuJhHXUh1rhSsCnXHLn3NcAO3oePH3s1LW7oEj/adkoDW+LMpY1tj6/R09Eef/24Qcw== 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-reply 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: Neil Brown CC: Olga Kornievskaia CC: Dai Ngo CC: Tom Talpey CC: linux-nfs@vger.kernel.org --- fs/nfsd/netns.h | 2 +- fs/nfsd/nfscache.c | 31 ++++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/fs/nfsd/netns.h b/fs/nfsd/netns.h index f669444d5336..ab303a8b77d5 100644 --- a/fs/nfsd/netns.h +++ b/fs/nfsd/netns.h @@ -177,7 +177,7 @@ struct nfsd_net { /* size of cache when we saw the longest hash chain */ unsigned int longest_chain_cachesize; - struct shrinker nfsd_reply_cache_shrinker; + struct shrinker *nfsd_reply_cache_shrinker; /* tracking server-to-server copy mounts */ spinlock_t nfsd_ssc_lock; diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c index 80621a709510..fd56a52aa5fb 100644 --- a/fs/nfsd/nfscache.c +++ b/fs/nfsd/nfscache.c @@ -201,26 +201,29 @@ int nfsd_reply_cache_init(struct nfsd_net *nn) { unsigned int hashsize; unsigned int i; - int status = 0; nn->max_drc_entries = nfsd_cache_size_limit(); atomic_set(&nn->num_drc_entries, 0); hashsize = nfsd_hashsize(nn->max_drc_entries); nn->maskbits = ilog2(hashsize); - nn->nfsd_reply_cache_shrinker.scan_objects = nfsd_reply_cache_scan; - nn->nfsd_reply_cache_shrinker.count_objects = nfsd_reply_cache_count; - nn->nfsd_reply_cache_shrinker.seeks = 1; - status = register_shrinker(&nn->nfsd_reply_cache_shrinker, - "nfsd-reply:%s", nn->nfsd_name); - if (status) - return status; - nn->drc_hashtbl = kvzalloc(array_size(hashsize, sizeof(*nn->drc_hashtbl)), GFP_KERNEL); if (!nn->drc_hashtbl) + return -ENOMEM; + + nn->nfsd_reply_cache_shrinker = shrinker_alloc(0, "nfsd-reply:%s", + nn->nfsd_name); + if (!nn->nfsd_reply_cache_shrinker) goto out_shrinker; + nn->nfsd_reply_cache_shrinker->scan_objects = nfsd_reply_cache_scan; + nn->nfsd_reply_cache_shrinker->count_objects = nfsd_reply_cache_count; + nn->nfsd_reply_cache_shrinker->seeks = 1; + nn->nfsd_reply_cache_shrinker->private_data = nn; + + shrinker_register(nn->nfsd_reply_cache_shrinker); + for (i = 0; i < hashsize; i++) { INIT_LIST_HEAD(&nn->drc_hashtbl[i].lru_head); spin_lock_init(&nn->drc_hashtbl[i].cache_lock); @@ -229,7 +232,7 @@ int nfsd_reply_cache_init(struct nfsd_net *nn) return 0; out_shrinker: - unregister_shrinker(&nn->nfsd_reply_cache_shrinker); + kvfree(nn->drc_hashtbl); printk(KERN_ERR "nfsd: failed to allocate reply cache\n"); return -ENOMEM; } @@ -239,7 +242,7 @@ void nfsd_reply_cache_shutdown(struct nfsd_net *nn) struct nfsd_cacherep *rp; unsigned int i; - unregister_shrinker(&nn->nfsd_reply_cache_shrinker); + shrinker_free(nn->nfsd_reply_cache_shrinker); for (i = 0; i < nn->drc_hashsize; i++) { struct list_head *head = &nn->drc_hashtbl[i].lru_head; @@ -323,8 +326,7 @@ nfsd_prune_bucket_locked(struct nfsd_net *nn, struct nfsd_drc_bucket *b, static unsigned long nfsd_reply_cache_count(struct shrinker *shrink, struct shrink_control *sc) { - struct nfsd_net *nn = container_of(shrink, - struct nfsd_net, nfsd_reply_cache_shrinker); + struct nfsd_net *nn = shrink->private_data; return atomic_read(&nn->num_drc_entries); } @@ -343,8 +345,7 @@ nfsd_reply_cache_count(struct shrinker *shrink, struct shrink_control *sc) static unsigned long nfsd_reply_cache_scan(struct shrinker *shrink, struct shrink_control *sc) { - struct nfsd_net *nn = container_of(shrink, - struct nfsd_net, nfsd_reply_cache_shrinker); + struct nfsd_net *nn = shrink->private_data; unsigned long freed = 0; LIST_HEAD(dispose); unsigned int i;