From patchwork Mon Sep 11 09:44:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379109 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 7DEDAEE7FF4 for ; Mon, 11 Sep 2023 09:50:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 235BB6B0250; Mon, 11 Sep 2023 05:50:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E6296B0251; Mon, 11 Sep 2023 05:50:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0AECB6B0252; Mon, 11 Sep 2023 05:50:15 -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 EE6496B0250 for ; Mon, 11 Sep 2023 05:50:14 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id CDC27B3698 for ; Mon, 11 Sep 2023 09:50:14 +0000 (UTC) X-FDA: 81223845948.07.D0C4E0A Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf08.hostedemail.com (Postfix) with ESMTP id E5C1E160018 for ; Mon, 11 Sep 2023 09:50:12 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=jYQc0pCU; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.174 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=1694425813; 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=VBsXECHPgwKWzzBJ2kxVPjqqD9cDsZj7wTGZXCs+v76JzsR6+A6ElHYc9tehl7eQvQ/hUH ppIIgpfMhmZZ/yu2WeoggUP98yh4Sxs0sjlE4Fw/ZFXdqqgedRaGWAWO2R6x9xsPwcpC1+ njpP51E3KUn3mIrug/52OHqUwV6M/aA= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=jYQc0pCU; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425813; a=rsa-sha256; cv=none; b=qL0ELcqexH7Pb+EZxDcMsMbCnenWH5pb7V1VO3R5PDKI35KUWOLG5jV8n9Fm6xuTJBxjkj OI5jh70Ti51bNu0gltjqeCd0dQxGoqRZEVojWYTXsrA6iZnuMhqrl6HiqUAvbtF1rW3u43 vMUrM9sTG/IqNsvqspvVkjQ+KU0pxxQ= Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1c3aa44c0faso1787875ad.1 for ; Mon, 11 Sep 2023 02:50:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425812; x=1695030612; darn=kvack.org; 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=jYQc0pCUu6vOcJ+DbnAUu4nw1Tg8jujvBC7VQIkRXJGDK8ERaf6oOGMx7RT+dzFNSV Yp+qvieSUcw4bRrqwWUibxmUaNwoTLqWKn47BitaO5lQ+tdBsCfQbWLoSZQ1Pa76TC0e MjtPNLzz/K9dtGtOn3FIqCgAj6CytEO9fYSUINf2c0jFeid3OBVo5LY3ysyhGm3AHkp6 zTXLrD/a4g/9qI4epN+mh3uqPQBrU28lWZAwVuW2ESOrFLm8BVSdwl0OU/UCWtDhUVFA rk5pLEW3tkwTtD/leZe2KdIHCHDIxBdSuBC6K/jZMjve54/Bs5BaHaa7g210HEDEVJzY 46Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425812; x=1695030612; 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=dEE6W0Blq6a6PM7LLbK+rf51aHd7l9BZwsUD38BNUF8+h4oUs9X/dd7mW+atgZZBsR tyfRm2bcIGZrzPv1Il6IFG08yHg8U/dmxC8Xg7NKdnS8tes6J4eqewZ0CuQkfAj+tYRe EPsSmMTMGosvsIGrESbT8ssFsFfxnzglbXukuc9PfwPk3qIsvTc8l4J5vRhKlzRdT5bh 7gRa89tmKegFgZwK0eS4FVcoOdABMOnAmVmDv9z/PIHeu53VZfZ/CT9MvapPsY/0L1Ww eY7KENVqkLN4mU76ONEJ4h+D9B6J4PdJ0NCTVhMKrV4Lc7naglxd4ygPs+DjIjW03ikk Zg9w== X-Gm-Message-State: AOJu0Yx4jiuY+nsiFDdinYU1QE7ZM2TditaM0JFPzqcnIIAVrG8rnMTU Wltrz8bKTTka4gPQNTW/QkN3zQ== X-Google-Smtp-Source: AGHT+IFx01yGZSAgnlbIN2EmaqAGM45aSzdAGkHUGYMQpSItramkO401wN4MdrY4LUd5pZ7aoS8pCA== X-Received: by 2002:a17:902:e84c:b0:1bf:349f:b85c with SMTP id t12-20020a170902e84c00b001bf349fb85cmr11526001plg.1.1694425811998; Mon, 11 Sep 2023 02:50:11 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id az7-20020a170902a58700b001bdc2fdcf7esm5988188plb.129.2023.09.11.02.50.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:50:11 -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 v6 33/45] nfsd: dynamically allocate the nfsd-reply shrinker Date: Mon, 11 Sep 2023 17:44:32 +0800 Message-Id: <20230911094444.68966-34-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230911094444.68966-1-zhengqi.arch@bytedance.com> References: <20230911094444.68966-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: E5C1E160018 X-Stat-Signature: b3sxw7n74ifrzmrt16kab3wuwirbgdf7 X-Rspam-User: X-HE-Tag: 1694425812-530953 X-HE-Meta: U2FsdGVkX1+KzxvGdk8lMibPiz7AyenyYbNCw8YPcQsMZ5iu0x4HmJm5/boJDcKT1cQoVbPK2l1FyjFqUsee+dVS0DEv5J/I5hjZ5pLdXnEb+iBvRzTuo1/6O3XwfuEgCeD86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kmtPyrGa628QRZADOljhBrNMJpVPaJeCjgOmcwOlY7CTGa0bK62vFfA1OHdUlVjS0EZzfU7NKTAsQfkRHEvg3hbDbPjtsbLE/tw8CbgO9iJU+6YzLfLHmuyG8WGAswmY7zvwOJbgsVoQ8aqGVg4Na16AmFhFV9xri9Gv16EoNrcgRi0/tVrw/FcuQFnTbcsPAXxqM1sJoKHitTup/ATTxcAAgzdJ90LD+awKNBtjXrIokBoX50Qgd1HRE2zoX5Z7wN5TjRcn/UYnG99qPe8N3UsKreOaDo+Zex1a5f7e5IYP7lZtKllUsCBqhS+wUZCi0NIqOmU4e1rqxUSA8tfIJTwuqD/+4WVML6zJaXuQMvlvk9yrkuhjRbAtpulZhsB54IsbiOpBX6SjW/cjW01iU0ISqAnb+JMw= 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 Acked-by: Muchun Song --- 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;