From patchwork Thu Jun 22 08:53:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13288648 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 D85F8EB64DB for ; Thu, 22 Jun 2023 08:56:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6D2238D000B; Thu, 22 Jun 2023 04:56:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 681D28D0001; Thu, 22 Jun 2023 04:56:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 54A698D000B; Thu, 22 Jun 2023 04:56:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4672E8D0001 for ; Thu, 22 Jun 2023 04:56:15 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 0F2C0C0ACD for ; Thu, 22 Jun 2023 08:56:15 +0000 (UTC) X-FDA: 80929777110.22.6D15ED0 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by imf01.hostedemail.com (Postfix) with ESMTP id 185AF4001A for ; Thu, 22 Jun 2023 08:56:12 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=PB56VJEt; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf01.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.180 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=1687424173; 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=zUNTs2D5J+Px6+8NyTz0IGsKdVlRq3fVdCNXQo6zMeo=; b=hWONiU+cAzHWNEO61XQ0OBTxAZqY5MDOg8SoI/ur075RjQSoQ5S553fZ6Nu3M8HpsoO0Sd MDwiZAlTEis1Ml8MdIMhNEOg/oNP4rZf2oJgnxPWZEcqfM93AyevdZG4zAJbT89aaq7Rvt MNW5HjGUX4090Y7Q+6tTS3naCpvqoNs= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=PB56VJEt; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf01.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.180 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687424173; a=rsa-sha256; cv=none; b=7E45yINLpX9HW2QqoQeSAsHYqGuUweGtZQV13vGz4gSbVhlb+Tk9Vw4d5IyUdDmugGvT9e YebAbdaqFwTanh1sjghgB2PCXVL/VeB7EgGvVip1DgvnhuR/XMY2ExM8VJsVpVa9Ej+Ae7 IZDfVBATMXSQceSwchxoWsJlusYTNK8= Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-543a37c5c03so1091198a12.1 for ; Thu, 22 Jun 2023 01:56:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1687424172; x=1690016172; 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=zUNTs2D5J+Px6+8NyTz0IGsKdVlRq3fVdCNXQo6zMeo=; b=PB56VJEtwK39jb6ujoKeOUgYB/PJLrruyxKRjJr7vrytJTdiBm6YHrGem+eoP0b4tN ySO0Fp6iHJx1jYG5cUtED8VGJ9nuR5OzkvfKjRzGq011b3+5HaAEFO0JOZ1JrJyRnWbE zD+J47hPkoBpD2IoCQquNzCqiGwmlgwN3y5YbOJ5VGLqEl2FtVJoITLOXOxAzhFddu+k 6lt/tmVHj10PbE9jdwz/MvuKMpEDpm3abrU9F/6h0dgBlWZ5OjmzxDq5+jKr9MCDVLPh Sp8IUY5vM81KMKjfLSjlTI62E4wEBy9NQ8VxDpQ2xwoZwC4ItSHDc6u/r/EGjzaiDmrG iUiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687424172; x=1690016172; 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=zUNTs2D5J+Px6+8NyTz0IGsKdVlRq3fVdCNXQo6zMeo=; b=MUDMGlKDCoXDkJnn6JrQMztp887ceE/EWJiPkzOik4zBbhyqorO+CIT82DJtvs8+/Q HHNh5k0dvvTboeanBKdHMJk2Uw9fQyWUTws52WzBvPWREByiK33Jl33kLKy5/yosIY9O rg7KK1qcboo9YSdhuvNCcKjh+RKs42A+YSMarbxFzQtFRgxs2wtWAZqn3F4wDoTjBO8P 6HGGvWQT7CgJuccoqCKXUoSaU5NOlEWwiT1NTILSMzqp85mbgXgZF4oh8DepAfpCMnDY R9ufU1jYz54frRwpyypF9opiuVTwucIDgHQgbJecxlDfpSLmnr0gXqLgyX3NI3STd6Mg MuEw== X-Gm-Message-State: AC+VfDyVRvenc/VtHQkHQjUFjN8In3szUTBTa0kX4zi8n8C46LFRkTHV Wy4MNyiphtZt0hTBg2Gg315t8xpAVYYdAoJyZaA= X-Google-Smtp-Source: ACHHUZ7RZPPxDHHt9nXlq48w0UysjH5yX+GnVgYNyQdTPpVzG1MBfOvOCSKK+16aR/H5lLV5H8OFJg== X-Received: by 2002:a17:902:f688:b0:1ad:e3a8:3c4 with SMTP id l8-20020a170902f68800b001ade3a803c4mr20681104plg.4.1687424171977; Thu, 22 Jun 2023 01:56:11 -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.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jun 2023 01:56: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 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 16/29] NFSD: dynamically allocate the nfsd-reply shrinker Date: Thu, 22 Jun 2023 16:53:22 +0800 Message-Id: <20230622085335.77010-17-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: rspam12 X-Rspamd-Queue-Id: 185AF4001A X-Stat-Signature: 5nqaftyj5467yqxufd1nyqmbft4imy8r X-HE-Tag: 1687424172-622356 X-HE-Meta: U2FsdGVkX19BkMRpNN+24NZhdZ+r/LBFn2u8RiWUeZZMqHeTdX2IZ58Mz+PIM8Ar6QHaJ0Jbtp5FYU0zLYP+Ycykd19HQKfs9DJUEBu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va/tgR+AJc1gHAgjrqPpmlFGAZxbQNq7E0ApyGAoqvyDMaNV6SzhuPs+kNM/OfA64JhfZPh1GMrUdili/TdueQzf+UxM4idjDPMyG9OYGyra/Lo6jBF7O6ZUhjBWqcXSqBEAMIGk+J54Ck235VIB77HIc7b1bgW+3qzvYVpnsyrL0Q2Nt/ZwPgEn3TJk1Zy99tRP5jc2iOgEO95psPYPF6bfQiQ4DYfiZQYBTvb3 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-reply 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 --- fs/nfsd/netns.h | 2 +- fs/nfsd/nfscache.c | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 15 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 041faa13b852..ec33de8e418b 100644 --- a/fs/nfsd/nfscache.c +++ b/fs/nfsd/nfscache.c @@ -173,19 +173,23 @@ int nfsd_reply_cache_init(struct nfsd_net *nn) if (status) goto out_nomem; - 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) - goto out_stats_destroy; - nn->drc_hashtbl = kvzalloc(array_size(hashsize, sizeof(*nn->drc_hashtbl)), GFP_KERNEL); if (!nn->drc_hashtbl) + goto out_stats_destroy; + + nn->nfsd_reply_cache_shrinker = + shrinker_alloc_and_init(nfsd_reply_cache_count, + nfsd_reply_cache_scan, + 0, 1, 0, nn); + if (!nn->nfsd_reply_cache_shrinker) goto out_shrinker; + status = register_shrinker(nn->nfsd_reply_cache_shrinker, + "nfsd-reply:%s", nn->nfsd_name); + if (status) + goto out_register; + for (i = 0; i < hashsize; i++) { INIT_LIST_HEAD(&nn->drc_hashtbl[i].lru_head); spin_lock_init(&nn->drc_hashtbl[i].cache_lock); @@ -193,8 +197,11 @@ int nfsd_reply_cache_init(struct nfsd_net *nn) nn->drc_hashsize = hashsize; return 0; + +out_register: + shrinker_free(nn->nfsd_reply_cache_shrinker); out_shrinker: - unregister_shrinker(&nn->nfsd_reply_cache_shrinker); + kvfree(nn->drc_hashtbl); out_stats_destroy: nfsd_reply_cache_stats_destroy(nn); out_nomem: @@ -207,7 +214,7 @@ void nfsd_reply_cache_shutdown(struct nfsd_net *nn) struct svc_cacherep *rp; unsigned int i; - unregister_shrinker(&nn->nfsd_reply_cache_shrinker); + unregister_and_free_shrinker(nn->nfsd_reply_cache_shrinker); for (i = 0; i < nn->drc_hashsize; i++) { struct list_head *head = &nn->drc_hashtbl[i].lru_head; @@ -297,8 +304,7 @@ prune_cache_entries(struct nfsd_net *nn) 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); } @@ -306,8 +312,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; return prune_cache_entries(nn); }