From patchwork Tue Dec 10 20:27:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11283203 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9A670112B for ; Tue, 10 Dec 2019 20:29:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 798732077B for ; Tue, 10 Dec 2019 20:29:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ra7wfKfo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726500AbfLJU3q (ORCPT ); Tue, 10 Dec 2019 15:29:46 -0500 Received: from mail-yw1-f66.google.com ([209.85.161.66]:37188 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726589AbfLJU3q (ORCPT ); Tue, 10 Dec 2019 15:29:46 -0500 Received: by mail-yw1-f66.google.com with SMTP id v84so1484718ywa.4 for ; Tue, 10 Dec 2019 12:29:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=d9z0I4z27omUwUY16yCeHYxB+5qzZFnDqr3pTad5jvg=; b=Ra7wfKfo5lKntPVufclepjjeZyQCKXncT2TmnnGn9K0+O3KoNgaBD/B94deKEs2dBP rcfs+oki22DsEw3txRP4DKVCMKEqRcfhe3lb0uQClFdb1ExWAqqlKRcAO0R7Tinh6mIg WWBBsmllmzS/fVJhA2BIm9YtJc8zfYSlFIa2P2C+4GYyvzm4dcP7sHEN19xPG+oC9qK7 +QuIgKjTM7AM8QoZ8daVbJ0Dc4H44VWY1gctisSeKf3La1LL7XTdebJFJmcOp6GGG348 F6N/f+k9gMZ806TTrE2IQZ0xK8VAtS8kj4avQcKwoza9rs3Ell9UTQ1DoWwx5aSGpsf2 HDhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=d9z0I4z27omUwUY16yCeHYxB+5qzZFnDqr3pTad5jvg=; b=TPHt3exM8stZTtez8d4JT9YNsVR4LGdTpm21ozSrdAie1FT3EZ5989Iuy4tvrT5hiM LHblneU1lMTqPwzeRS0hEoQq4/+9oxvjbCjDAE7u1R7bfC6pQRY2HqZY8DYN2mDwKM4v Xo5JewhwYCaP0Ion2U3kllJeck5kJ/YLG4oxV+4TeaKDy5/SlNnbjOIvXcIQNXg+XU+Q dL5CDmGxyMCc/1oTvRgINHWfp42IjWJ8lGzbggz8nbqa6Z4s3AhJ36mpBn+ZGGB5DFcq vSLKVnPszOEfUOpDwxEiQ27p4dP5T7XcQCMh8x5xhUcJy7FQ72MHnV6Q2/4PRpUwTi0l yTPQ== X-Gm-Message-State: APjAAAUNeMNXrXrT5mcEx25+KX26QfGRG7TZs3eHjC4mn4YIwvJihHDw g1gs5pduTcilzvqke5+3fpe1udg= X-Google-Smtp-Source: APXvYqyQ9JDhIDueQW9WzAtfJD57N3MhpRMVaBemQLIdoYtlYuK5KMy46g6ti43ejI/EyGyU0e6jlQ== X-Received: by 2002:a81:f81:: with SMTP id 123mr26137811ywp.268.1576009785702; Tue, 10 Dec 2019 12:29:45 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id x84sm1947508ywg.47.2019.12.10.12.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 12:29:45 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: Chuck Lever , linux-nfs@vger.kernel.org Subject: [PATCH 1/6] nfsd: fix filecache lookup Date: Tue, 10 Dec 2019 15:27:30 -0500 Message-Id: <20191210202735.304477-2-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191210202735.304477-1-trond.myklebust@hammerspace.com> References: <20191210202735.304477-1-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org If the lookup keeps finding a nfsd_file with an unhashed open file, then retry once only. Signed-off-by: Trond Myklebust --- fs/nfsd/filecache.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index 32a9bf22ac08..0a3e5c2aac4b 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -789,6 +789,7 @@ nfsd_file_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf, *new; struct inode *inode; unsigned int hashval; + bool retry = true; /* FIXME: skip this if fh_dentry is already set? */ status = fh_verify(rqstp, fhp, S_IFREG, @@ -824,6 +825,11 @@ nfsd_file_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp, /* Did construction of this file fail? */ if (!test_bit(NFSD_FILE_HASHED, &nf->nf_flags)) { + if (!retry) { + status = nfserr_jukebox; + goto out; + } + retry = false; nfsd_file_put_noref(nf); goto retry; } From patchwork Tue Dec 10 20:27:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11283205 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 675A014E3 for ; Tue, 10 Dec 2019 20:29:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4680A2077B for ; Tue, 10 Dec 2019 20:29:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CcQ+xP2D" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725999AbfLJU3s (ORCPT ); Tue, 10 Dec 2019 15:29:48 -0500 Received: from mail-yw1-f68.google.com ([209.85.161.68]:35434 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726816AbfLJU3s (ORCPT ); Tue, 10 Dec 2019 15:29:48 -0500 Received: by mail-yw1-f68.google.com with SMTP id i190so7855513ywc.2 for ; Tue, 10 Dec 2019 12:29:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=N/nhr9SYe3Lf1NBGV+k83w8+Y7/b7c+eVtxtCi3KLLE=; b=CcQ+xP2Duo20BVtLTsVYwzYBHY1rT2iGmZ+MzpvThV8XLGTQvuaplAf9G8XoaZm6NU foXvX60VsQGuBjJDToSjEsEFu6neG2LhzKmy8OIVEQxtRez8NFDBS8iYNMNHvQefQJIE izU9UsbNlQeHA6CCMB6sisQORAoLW2QqOhz6/qJAVgIqso90k1yP9w3w5MjGpTFIMVLs Mj9H6iDFktxlGzs5nHgGwy9MVQdABhJ5kJkj3pzKz1qajNIH6IftIp0/gaqtmIrM3UES 3/vNkHIqNk12Vx7umyHWSGBIM2QbGK4Eg9gtLR/ywyUIf+1EgpDKVp9y7iP7xCSYZsV3 8/Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=N/nhr9SYe3Lf1NBGV+k83w8+Y7/b7c+eVtxtCi3KLLE=; b=lLui7wB8Nf14qJDxRDniKjRWSDTZyfU+tIC8X0u3rCfx7EsQv+6T6xSb2o1E4M0mS6 6W5Qdken7+kfUl53UbL9Seuot4T2SO/kXtugZ+zYvjEiVY7yhsJ4gGKjD5f1P/IVURJy oN4dCWHd+wH4oWRupMoPshzbor5CIRGs+7k82e/CFT7BitvFpjaU0hnducsnKS4xbH1x 1g6qVaxXj6J9sSxJxD0C3Eprea/x/cZ7LQCQp4GsXeBzrIQuxK5548pMyx4eZ8ARkbSY vQOjQtFsZPvHi181i0Id9sofaMbwq85qLtrBNaVgbHad4Rxl9kkO3LhRa3TtUqTHPZF1 H6aQ== X-Gm-Message-State: APjAAAXRRua9Lg08YUfvEybjGNWROit6VfrcttDN9XTog4up3EIpXABB Z6WnOOWxAaPF3Gl5PyJD7sVnGiY= X-Google-Smtp-Source: APXvYqwcwvyt94dehcqmXngDlCkUHE1nmvZBzfmPKeAj1UzJlZM5wHEoqjELlO5UpRaRnM8NBVPiQw== X-Received: by 2002:a0d:cd44:: with SMTP id p65mr27126217ywd.118.1576009786856; Tue, 10 Dec 2019 12:29:46 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id x84sm1947508ywg.47.2019.12.10.12.29.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 12:29:46 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: Chuck Lever , linux-nfs@vger.kernel.org Subject: [PATCH 2/6] nfsd: cleanup nfsd_file_lru_dispose() Date: Tue, 10 Dec 2019 15:27:31 -0500 Message-Id: <20191210202735.304477-3-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191210202735.304477-2-trond.myklebust@hammerspace.com> References: <20191210202735.304477-1-trond.myklebust@hammerspace.com> <20191210202735.304477-2-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Signed-off-by: Trond Myklebust --- fs/nfsd/filecache.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index 0a3e5c2aac4b..c048e3071db7 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -256,8 +256,6 @@ nfsd_file_do_unhash(struct nfsd_file *nf) nfsd_reset_boot_verifier(net_generic(nf->nf_net, nfsd_net_id)); --nfsd_file_hashtbl[nf->nf_hashval].nfb_count; hlist_del_rcu(&nf->nf_node); - if (!list_empty(&nf->nf_lru)) - list_lru_del(&nfsd_file_lru, &nf->nf_lru); atomic_long_dec(&nfsd_filecache_count); } @@ -266,6 +264,8 @@ nfsd_file_unhash(struct nfsd_file *nf) { if (test_and_clear_bit(NFSD_FILE_HASHED, &nf->nf_flags)) { nfsd_file_do_unhash(nf); + if (!list_empty(&nf->nf_lru)) + list_lru_del(&nfsd_file_lru, &nf->nf_lru); return true; } return false; @@ -402,15 +402,14 @@ nfsd_file_lru_cb(struct list_head *item, struct list_lru_one *lru, static void nfsd_file_lru_dispose(struct list_head *head) { - while(!list_empty(head)) { - struct nfsd_file *nf = list_first_entry(head, - struct nfsd_file, nf_lru); - list_del_init(&nf->nf_lru); + struct nfsd_file *nf; + + list_for_each_entry(nf, head, nf_lru) { spin_lock(&nfsd_file_hashtbl[nf->nf_hashval].nfb_lock); nfsd_file_do_unhash(nf); spin_unlock(&nfsd_file_hashtbl[nf->nf_hashval].nfb_lock); - nfsd_file_put_noref(nf); } + nfsd_file_dispose_list(head); } static unsigned long From patchwork Tue Dec 10 20:27:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11283207 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 236011593 for ; Tue, 10 Dec 2019 20:29:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DF37B20828 for ; Tue, 10 Dec 2019 20:29:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lLxkDuNL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726589AbfLJU3u (ORCPT ); Tue, 10 Dec 2019 15:29:50 -0500 Received: from mail-yb1-f193.google.com ([209.85.219.193]:46485 "EHLO mail-yb1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726879AbfLJU3t (ORCPT ); Tue, 10 Dec 2019 15:29:49 -0500 Received: by mail-yb1-f193.google.com with SMTP id v15so8129566ybp.13 for ; Tue, 10 Dec 2019 12:29:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ba0uzz6l8AKpkZYZrCYzKwmhXV5OyQbQtIoLGFI8Opk=; b=lLxkDuNL1XPPGbCSrUnxqnvlFZy7OwA7YtGbes8CrCKADlO8Vv1uM0t+TG1w4FIogh LkzvTu32mMpok8W0FwpOM0v2+XyUTR4AS5hhE0+iYXTTLVJTGLEOOolcoRppMbUgdcdp cm33xuNJqy6tpHVqML4uQXn4qlyzLuPN2fWqYZF7lTUx5cSKTcI0wcqK7dpbgH38i70J WvN2fK68K+6GEXbzjjogKTIY/9+/34w8YUUrjgN5ADt1NtVIaWFlhGX8bSchwJ3r6Hqg Uya/JRBzwFbgMggpx/owakguNiUM3HWJe0EkajGPCF1jezeKPsehoGSBMndOh6GDQ4cd uRCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ba0uzz6l8AKpkZYZrCYzKwmhXV5OyQbQtIoLGFI8Opk=; b=czSzCgpFu3CXPiRNYdcjvu4u8fvsRzlQz7wIAQxog57gP7rBV2SN09zMGXlpK37P1t Aa9ibFoQitsP4cLZ+HNGoflE6noxFdsDyE1M8iann5MwXcQe4T5WJve+V8evUBtEKfRJ gXvXqvJrjzyeM9OGfmhgMK8aZtuLOYMM7T293PfLWmzvTy5sZfZx7pYYehnI2w8U7mkG WoojY/PFh3ERzymLS3iYo2X7FDZCjHYb9A05dkGt+Sgi2HvXFjWXihu7GaqgOHUKcdRd 1nwXDw365eg1KxFPAgLWv4wQ9zrDe5ptLGzVjNAfsJCYJsdCMrcYp8N8hsTakq5rXfIq 8A1g== X-Gm-Message-State: APjAAAWrIvIx8KOvrQh148yfbReBOqsto3O/X+VH0FFAbcprD8c+W7hJ 4f+cmqgpEvLX1dEohFtzvA== X-Google-Smtp-Source: APXvYqyqb7LxxZMNvP7TpYbtinQQxgT45JTB0oTEnVcYaDF2WPmzmZ7LkPYeCwUXd3pXUAv4sihH8Q== X-Received: by 2002:a25:3803:: with SMTP id f3mr25934062yba.144.1576009788063; Tue, 10 Dec 2019 12:29:48 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id x84sm1947508ywg.47.2019.12.10.12.29.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 12:29:47 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: Chuck Lever , linux-nfs@vger.kernel.org Subject: [PATCH 3/6] nfsd: Containerise filecache laundrette Date: Tue, 10 Dec 2019 15:27:32 -0500 Message-Id: <20191210202735.304477-4-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191210202735.304477-3-trond.myklebust@hammerspace.com> References: <20191210202735.304477-1-trond.myklebust@hammerspace.com> <20191210202735.304477-2-trond.myklebust@hammerspace.com> <20191210202735.304477-3-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Ensure that if the filecache laundrette gets stuck, it only affects the knfsd instances of one container. The notifier callbacks can be called from various contexts so avoid using synchonous filesystem operations that might deadlock. Signed-off-by: Trond Myklebust --- fs/nfsd/filecache.c | 238 ++++++++++++++++++++++++++++++++++++-------- fs/nfsd/filecache.h | 2 + fs/nfsd/nfssvc.c | 9 +- 3 files changed, 207 insertions(+), 42 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index c048e3071db7..e71af553c2ed 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -44,6 +44,17 @@ struct nfsd_fcache_bucket { static DEFINE_PER_CPU(unsigned long, nfsd_file_cache_hits); +struct nfsd_fcache_disposal { + struct list_head list; + struct work_struct work; + struct net *net; + spinlock_t lock; + struct list_head freeme; + struct rcu_head rcu; +}; + +struct workqueue_struct *nfsd_filecache_wq __read_mostly; + static struct kmem_cache *nfsd_file_slab; static struct kmem_cache *nfsd_file_mark_slab; static struct nfsd_fcache_bucket *nfsd_file_hashtbl; @@ -52,32 +63,21 @@ static long nfsd_file_lru_flags; static struct fsnotify_group *nfsd_file_fsnotify_group; static atomic_long_t nfsd_filecache_count; static struct delayed_work nfsd_filecache_laundrette; +static DEFINE_SPINLOCK(laundrette_lock); +static LIST_HEAD(laundrettes); -enum nfsd_file_laundrette_ctl { - NFSD_FILE_LAUNDRETTE_NOFLUSH = 0, - NFSD_FILE_LAUNDRETTE_MAY_FLUSH -}; +static void nfsd_file_gc(void); static void -nfsd_file_schedule_laundrette(enum nfsd_file_laundrette_ctl ctl) +nfsd_file_schedule_laundrette(void) { long count = atomic_long_read(&nfsd_filecache_count); if (count == 0 || test_bit(NFSD_FILE_SHUTDOWN, &nfsd_file_lru_flags)) return; - /* Be more aggressive about scanning if over the threshold */ - if (count > NFSD_FILE_LRU_THRESHOLD) - mod_delayed_work(system_wq, &nfsd_filecache_laundrette, 0); - else - schedule_delayed_work(&nfsd_filecache_laundrette, NFSD_LAUNDRETTE_DELAY); - - if (ctl == NFSD_FILE_LAUNDRETTE_NOFLUSH) - return; - - /* ...and don't delay flushing if we're out of control */ - if (count >= NFSD_FILE_LRU_LIMIT) - flush_delayed_work(&nfsd_filecache_laundrette); + queue_delayed_work(system_wq, &nfsd_filecache_laundrette, + NFSD_LAUNDRETTE_DELAY); } static void @@ -312,7 +312,9 @@ nfsd_file_put(struct nfsd_file *nf) set_bit(NFSD_FILE_REFERENCED, &nf->nf_flags); if (nfsd_file_put_noref(nf) == 1 && is_hashed && unused) - nfsd_file_schedule_laundrette(NFSD_FILE_LAUNDRETTE_MAY_FLUSH); + nfsd_file_schedule_laundrette(); + if (atomic_long_read(&nfsd_filecache_count) >= NFSD_FILE_LRU_LIMIT) + nfsd_file_gc(); } struct nfsd_file * @@ -353,6 +355,58 @@ nfsd_file_dispose_list_sync(struct list_head *dispose) flush_delayed_fput(); } +static void +nfsd_file_list_remove_disposal(struct list_head *dst, + struct nfsd_fcache_disposal *l) +{ + spin_lock(&l->lock); + list_splice_init(&l->freeme, dst); + spin_unlock(&l->lock); +} + +static void +nfsd_file_list_add_disposal(struct list_head *files, struct net *net) +{ + struct nfsd_fcache_disposal *l; + + rcu_read_lock(); + list_for_each_entry_rcu(l, &laundrettes, list) { + if (l->net == net) { + spin_lock(&l->lock); + list_splice_tail_init(files, &l->freeme); + spin_unlock(&l->lock); + queue_work(nfsd_filecache_wq, &l->work); + break; + } + } + rcu_read_unlock(); +} + +static void +nfsd_file_list_add_pernet(struct list_head *dst, struct list_head *src, + struct net *net) +{ + struct nfsd_file *nf, *tmp; + + list_for_each_entry_safe(nf, tmp, src, nf_lru) { + if (nf->nf_net == net) + list_move_tail(&nf->nf_lru, dst); + } +} + +static void +nfsd_file_dispose_list_delayed(struct list_head *dispose) +{ + LIST_HEAD(list); + struct nfsd_file *nf; + + while(!list_empty(dispose)) { + nf = list_first_entry(dispose, struct nfsd_file, nf_lru); + nfsd_file_list_add_pernet(&list, dispose, nf->nf_net); + nfsd_file_list_add_disposal(&list, nf->nf_net); + } +} + /* * Note this can deadlock with nfsd_file_cache_purge. */ @@ -399,17 +453,40 @@ nfsd_file_lru_cb(struct list_head *item, struct list_lru_one *lru, return LRU_SKIP; } -static void -nfsd_file_lru_dispose(struct list_head *head) +static unsigned long +nfsd_file_lru_walk_list(struct shrink_control *sc) { + LIST_HEAD(head); struct nfsd_file *nf; + unsigned long ret; - list_for_each_entry(nf, head, nf_lru) { + if (sc) + ret = list_lru_shrink_walk(&nfsd_file_lru, sc, + nfsd_file_lru_cb, &head); + else + ret = list_lru_walk(&nfsd_file_lru, + nfsd_file_lru_cb, + &head, LONG_MAX); + list_for_each_entry(nf, &head, nf_lru) { spin_lock(&nfsd_file_hashtbl[nf->nf_hashval].nfb_lock); nfsd_file_do_unhash(nf); spin_unlock(&nfsd_file_hashtbl[nf->nf_hashval].nfb_lock); } - nfsd_file_dispose_list(head); + nfsd_file_dispose_list_delayed(&head); + return ret; +} + +static void +nfsd_file_gc(void) +{ + nfsd_file_lru_walk_list(NULL); +} + +static void +nfsd_file_gc_worker(struct work_struct *work) +{ + nfsd_file_gc(); + nfsd_file_schedule_laundrette(); } static unsigned long @@ -421,12 +498,7 @@ nfsd_file_lru_count(struct shrinker *s, struct shrink_control *sc) static unsigned long nfsd_file_lru_scan(struct shrinker *s, struct shrink_control *sc) { - LIST_HEAD(head); - unsigned long ret; - - ret = list_lru_shrink_walk(&nfsd_file_lru, sc, nfsd_file_lru_cb, &head); - nfsd_file_lru_dispose(&head); - return ret; + return nfsd_file_lru_walk_list(sc); } static struct shrinker nfsd_file_shrinker = { @@ -488,7 +560,7 @@ nfsd_file_close_inode(struct inode *inode) __nfsd_file_close_inode(inode, hashval, &dispose); trace_nfsd_file_close_inode(inode, hashval, !list_empty(&dispose)); - nfsd_file_dispose_list(&dispose); + nfsd_file_dispose_list_delayed(&dispose); } /** @@ -504,16 +576,11 @@ static void nfsd_file_delayed_close(struct work_struct *work) { LIST_HEAD(head); + struct nfsd_fcache_disposal *l = container_of(work, + struct nfsd_fcache_disposal, work); - list_lru_walk(&nfsd_file_lru, nfsd_file_lru_cb, &head, LONG_MAX); - - if (test_and_clear_bit(NFSD_FILE_LRU_RESCAN, &nfsd_file_lru_flags)) - nfsd_file_schedule_laundrette(NFSD_FILE_LAUNDRETTE_NOFLUSH); - - if (!list_empty(&head)) { - nfsd_file_lru_dispose(&head); - flush_delayed_fput(); - } + nfsd_file_list_remove_disposal(&head, l); + nfsd_file_dispose_list(&head); } static int @@ -574,6 +641,10 @@ nfsd_file_cache_init(void) if (nfsd_file_hashtbl) return 0; + nfsd_filecache_wq = alloc_workqueue("nfsd_filecache", 0, 0); + if (!nfsd_filecache_wq) + goto out; + nfsd_file_hashtbl = kcalloc(NFSD_FILE_HASH_SIZE, sizeof(*nfsd_file_hashtbl), GFP_KERNEL); if (!nfsd_file_hashtbl) { @@ -627,7 +698,7 @@ nfsd_file_cache_init(void) spin_lock_init(&nfsd_file_hashtbl[i].nfb_lock); } - INIT_DELAYED_WORK(&nfsd_filecache_laundrette, nfsd_file_delayed_close); + INIT_DELAYED_WORK(&nfsd_filecache_laundrette, nfsd_file_gc_worker); out: return ret; out_notifier: @@ -643,6 +714,8 @@ nfsd_file_cache_init(void) nfsd_file_mark_slab = NULL; kfree(nfsd_file_hashtbl); nfsd_file_hashtbl = NULL; + destroy_workqueue(nfsd_filecache_wq); + nfsd_filecache_wq = NULL; goto out; } @@ -681,6 +754,88 @@ nfsd_file_cache_purge(struct net *net) } } +static struct nfsd_fcache_disposal * +nfsd_alloc_fcache_disposal(struct net *net) +{ + struct nfsd_fcache_disposal *l; + + l = kmalloc(sizeof(*l), GFP_KERNEL); + if (!l) + return NULL; + INIT_WORK(&l->work, nfsd_file_delayed_close); + l->net = net; + spin_lock_init(&l->lock); + INIT_LIST_HEAD(&l->freeme); + return l; +} + +static void +nfsd_free_fcache_disposal(struct nfsd_fcache_disposal *l) +{ + rcu_assign_pointer(l->net, NULL); + cancel_work_sync(&l->work); + nfsd_file_dispose_list(&l->freeme); + kfree_rcu(l, rcu); +} + +static void +nfsd_add_fcache_disposal(struct nfsd_fcache_disposal *l) +{ + spin_lock(&laundrette_lock); + list_add_tail_rcu(&l->list, &laundrettes); + spin_unlock(&laundrette_lock); +} + +static void +nfsd_del_fcache_disposal(struct nfsd_fcache_disposal *l) +{ + spin_lock(&laundrette_lock); + list_del_rcu(&l->list); + spin_unlock(&laundrette_lock); +} + +static int +nfsd_alloc_fcache_disposal_net(struct net *net) +{ + struct nfsd_fcache_disposal *l; + + l = nfsd_alloc_fcache_disposal(net); + if (!l) + return -ENOMEM; + nfsd_add_fcache_disposal(l); + return 0; +} + +static void +nfsd_free_fcache_disposal_net(struct net *net) +{ + struct nfsd_fcache_disposal *l; + + rcu_read_lock(); + list_for_each_entry_rcu(l, &laundrettes, list) { + if (l->net != net) + continue; + nfsd_del_fcache_disposal(l); + rcu_read_unlock(); + nfsd_free_fcache_disposal(l); + return; + } + rcu_read_unlock(); +} + +int +nfsd_file_cache_start_net(struct net *net) +{ + return nfsd_alloc_fcache_disposal_net(net); +} + +void +nfsd_file_cache_shutdown_net(struct net *net) +{ + nfsd_file_cache_purge(net); + nfsd_free_fcache_disposal_net(net); +} + void nfsd_file_cache_shutdown(void) { @@ -705,6 +860,8 @@ nfsd_file_cache_shutdown(void) nfsd_file_mark_slab = NULL; kfree(nfsd_file_hashtbl); nfsd_file_hashtbl = NULL; + destroy_workqueue(nfsd_filecache_wq); + nfsd_filecache_wq = NULL; } static bool @@ -872,7 +1029,8 @@ nfsd_file_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp, nfsd_file_hashtbl[hashval].nfb_maxcount = max(nfsd_file_hashtbl[hashval].nfb_maxcount, nfsd_file_hashtbl[hashval].nfb_count); spin_unlock(&nfsd_file_hashtbl[hashval].nfb_lock); - atomic_long_inc(&nfsd_filecache_count); + if (atomic_long_inc_return(&nfsd_filecache_count) >= NFSD_FILE_LRU_THRESHOLD) + nfsd_file_gc(); nf->nf_mark = nfsd_file_mark_find_or_create(nf); if (nf->nf_mark) diff --git a/fs/nfsd/filecache.h b/fs/nfsd/filecache.h index 851d9abf54c2..79a7d6808d97 100644 --- a/fs/nfsd/filecache.h +++ b/fs/nfsd/filecache.h @@ -51,6 +51,8 @@ struct nfsd_file { int nfsd_file_cache_init(void); void nfsd_file_cache_purge(struct net *); void nfsd_file_cache_shutdown(void); +int nfsd_file_cache_start_net(struct net *net); +void nfsd_file_cache_shutdown_net(struct net *net); void nfsd_file_put(struct nfsd_file *nf); struct nfsd_file *nfsd_file_get(struct nfsd_file *nf); void nfsd_file_close_inode_sync(struct inode *inode); diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c index e8bee8ff30c5..dce7a8e2c1c5 100644 --- a/fs/nfsd/nfssvc.c +++ b/fs/nfsd/nfssvc.c @@ -394,13 +394,18 @@ static int nfsd_startup_net(int nrservs, struct net *net, const struct cred *cre nn->lockd_up = 1; } - ret = nfs4_state_start_net(net); + ret = nfsd_file_cache_start_net(net); if (ret) goto out_lockd; + ret = nfs4_state_start_net(net); + if (ret) + goto out_filecache; nn->nfsd_net_up = true; return 0; +out_filecache: + nfsd_file_cache_shutdown_net(net); out_lockd: if (nn->lockd_up) { lockd_down(net); @@ -415,7 +420,7 @@ static void nfsd_shutdown_net(struct net *net) { struct nfsd_net *nn = net_generic(net, nfsd_net_id); - nfsd_file_cache_purge(net); + nfsd_file_cache_shutdown_net(net); nfs4_state_shutdown_net(net); if (nn->lockd_up) { lockd_down(net); From patchwork Tue Dec 10 20:27:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11283209 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EE85514E3 for ; Tue, 10 Dec 2019 20:29:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CDB922077B for ; Tue, 10 Dec 2019 20:29:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kbVyuAO4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726879AbfLJU3v (ORCPT ); Tue, 10 Dec 2019 15:29:51 -0500 Received: from mail-yb1-f194.google.com ([209.85.219.194]:43307 "EHLO mail-yb1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726881AbfLJU3v (ORCPT ); Tue, 10 Dec 2019 15:29:51 -0500 Received: by mail-yb1-f194.google.com with SMTP id d34so3883991yba.10 for ; Tue, 10 Dec 2019 12:29:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t/+PxnQdKAutGXiVSCU+o4iJAihQ69OWMQr+GyxT+TY=; b=kbVyuAO4qPzAA6L5vQZxUBorhOQinIRUrPbrR5EYmU5Bh0hNoLC82jzKLQSqtP/l51 BpgcZ27wYwU12K0KfmxzezSmwhoEcImaVl+sCKlMHXMu1S0BXZ64Vox5NWCV0DbE7OyZ 1Cm7vKjveEJq8ndyqX60jZcK4tWwB8njFlHdM1ShvJKyo5zFTjmjyggvEu6vK+TIwXez XCmB3LbKKOlec6xTyzz9nMRwRhyymIVEe4ew3YU9YLSAKBcdhDqhOi+lN+7wHgwcfbmV 8exDqqvW65vJ0OI9nseRUVT6jpJU7/peyRymfWNx6s4jXZPdpP+LWzVQL1G7hwowjZRK Kw/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=t/+PxnQdKAutGXiVSCU+o4iJAihQ69OWMQr+GyxT+TY=; b=YrpGy8T7aJPQn7gzjuW9NOXv1HRtaSJPkmv9+wYM7JHK0RD0ORiYR16w9NcQ9AK+hM xAZNmz0h0FF3C8wKpQ4IMTc7D80E4RlB9XDwVtJld43unAhNK5Cfd1I7kLUbhlqZucLR q9on5UqwNDQSSOG8kaPWUtaVCJKKOwKEGUfFMMDr0D+mieaeshncXvtTWJl+VESpfcBD cnjp2JvR1fEMSZMcJpuOqrIN0eSNChARCbT/isciF+VABBKn1B9pOnqXLt3AwECvuPm1 ZIWWD6pcqgLQ8qXvjU1DbWZZk3AIliNKZRs5tMDvBimtVQU/1eFeK+6MRim3jfvQPajx H/oQ== X-Gm-Message-State: APjAAAXkXZ2bGVjgTzMhGrNbZeRXcNrOG0sJrmslaoZxovwH3VFzMyb8 wm+vmG2zkJ/N9FDpsZ3Bkt0StDI= X-Google-Smtp-Source: APXvYqw9oUdcmz83UK/oknV/rarujZsU9kiFKk3+jFYvwT5Wn81Kf4xU+0E+tpuwsiRy4BPBYOM6NA== X-Received: by 2002:a25:2a50:: with SMTP id q77mr25028354ybq.47.1576009789524; Tue, 10 Dec 2019 12:29:49 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id x84sm1947508ywg.47.2019.12.10.12.29.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 12:29:48 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: Chuck Lever , linux-nfs@vger.kernel.org Subject: [PATCH 4/6] nfsd: Remove unused constant NFSD_FILE_LRU_RESCAN Date: Tue, 10 Dec 2019 15:27:33 -0500 Message-Id: <20191210202735.304477-5-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191210202735.304477-4-trond.myklebust@hammerspace.com> References: <20191210202735.304477-1-trond.myklebust@hammerspace.com> <20191210202735.304477-2-trond.myklebust@hammerspace.com> <20191210202735.304477-3-trond.myklebust@hammerspace.com> <20191210202735.304477-4-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Signed-off-by: Trond Myklebust --- fs/nfsd/filecache.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index e71af553c2ed..6b0ab43b0618 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -27,7 +27,6 @@ #define NFSD_FILE_HASH_SIZE (1 << NFSD_FILE_HASH_BITS) #define NFSD_LAUNDRETTE_DELAY (2 * HZ) -#define NFSD_FILE_LRU_RESCAN (0) #define NFSD_FILE_SHUTDOWN (1) #define NFSD_FILE_LRU_THRESHOLD (4096UL) #define NFSD_FILE_LRU_LIMIT (NFSD_FILE_LRU_THRESHOLD << 2) @@ -440,15 +439,13 @@ nfsd_file_lru_cb(struct list_head *item, struct list_lru_one *lru, goto out_skip; if (test_and_clear_bit(NFSD_FILE_REFERENCED, &nf->nf_flags)) - goto out_rescan; + goto out_skip; if (!test_and_clear_bit(NFSD_FILE_HASHED, &nf->nf_flags)) goto out_skip; list_lru_isolate_move(lru, &nf->nf_lru, head); return LRU_REMOVED; -out_rescan: - set_bit(NFSD_FILE_LRU_RESCAN, &nfsd_file_lru_flags); out_skip: return LRU_SKIP; } From patchwork Tue Dec 10 20:27:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11283211 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0F77614E3 for ; Tue, 10 Dec 2019 20:29:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E20762077B for ; Tue, 10 Dec 2019 20:29:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="E0WMenFL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727051AbfLJU3w (ORCPT ); Tue, 10 Dec 2019 15:29:52 -0500 Received: from mail-yb1-f196.google.com ([209.85.219.196]:42742 "EHLO mail-yb1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727047AbfLJU3v (ORCPT ); Tue, 10 Dec 2019 15:29:51 -0500 Received: by mail-yb1-f196.google.com with SMTP id p137so8145900ybg.9 for ; Tue, 10 Dec 2019 12:29:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7GB97zh1aT6vdl33UGntJyfknfwBcQGtnm/vtVyhwkc=; b=E0WMenFLIw7i8U3xI3M6IjJEkbFjrj4ewyToVXMjne2R8FyI8s9DNfcPpLuU2Mjqg7 lTFIul7a7LxELPqONtMKbNNtVBk5NrFFxO4eum60boa3GC7U2ft50POfY9uNaUR2yI2x pejAPcwmGwf8fkaImRaEtldh2nUFXHu1rio0r3YNjJs+AJY5wm0O/4v6qTRS+rj+x8SZ V0SkAqfZ2dJsC9YSER/xQ5jisZ2ZQNduUl4tpJacC5hhglJe0+yyxrB7KZrrrR/YFoPF fw0Qvzqq8BrBO5an/GVzYdxSRBEr6Zpph8mEMRnlRTaUhs7Tp93gwi8qpilTiyRGdrS4 uZSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7GB97zh1aT6vdl33UGntJyfknfwBcQGtnm/vtVyhwkc=; b=lBkpyM/gkVqIL6OIQrBLxI1AA1hzT1ELhqQ9vAARaPumg/+B7gppCektj2jIgL+4Jn Q2roCUsNSMkIl+VtzZKmd4VK3pNgutS612rh2+oji0INzXhXCQSySCEJBpPeN2q0IW7C 0mU4LVJGZifJ1SrgDKQncCxInobLdbzlVbOifaGjq/AC/rqge8MO1ponzfzs3eKWiNUM br8N6WzdSIQYJLyBsmcxAd65MKIEUMEqCndxx4ceI+317LRFuL5D9Vc68me9YndDGWVA zdXJh0G0GBa4F4XrM2aqCa646GraMfLB+SvUQvSGwo0cYFJ0eKKCJ6zmyiEXebdU0CjG ZkwA== X-Gm-Message-State: APjAAAV+Onen1/+8REL4Fto1eEf8SGoTNmhUSdb1UR2kDS8QtYULk5qJ N0acsproQXjMH/h3+NJWDg== X-Google-Smtp-Source: APXvYqwGFnLll97bQHhqBYCE85J6r5bQReOcdGnXCcopDahRPq0Eavj0aLrrOl2KurIdgzHSdCjRyg== X-Received: by 2002:a25:d45:: with SMTP id 66mr24922384ybn.216.1576009790487; Tue, 10 Dec 2019 12:29:50 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id x84sm1947508ywg.47.2019.12.10.12.29.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 12:29:50 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: Chuck Lever , linux-nfs@vger.kernel.org Subject: [PATCH 5/6] nfsd: Schedule the laundrette regularly irrespective of file errors Date: Tue, 10 Dec 2019 15:27:34 -0500 Message-Id: <20191210202735.304477-6-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191210202735.304477-5-trond.myklebust@hammerspace.com> References: <20191210202735.304477-1-trond.myklebust@hammerspace.com> <20191210202735.304477-2-trond.myklebust@hammerspace.com> <20191210202735.304477-3-trond.myklebust@hammerspace.com> <20191210202735.304477-4-trond.myklebust@hammerspace.com> <20191210202735.304477-5-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Emsure we schedule the laundrette even if the struct file is carrying file errors. Signed-off-by: Trond Myklebust --- fs/nfsd/filecache.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index 6b0ab43b0618..4cef03a7726c 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -237,13 +237,6 @@ nfsd_file_check_write_error(struct nfsd_file *nf) return filemap_check_wb_err(file->f_mapping, READ_ONCE(file->f_wb_err)); } -static bool -nfsd_file_in_use(struct nfsd_file *nf) -{ - return nfsd_file_check_writeback(nf) || - nfsd_file_check_write_error(nf); -} - static void nfsd_file_do_unhash(struct nfsd_file *nf) { @@ -307,10 +300,9 @@ void nfsd_file_put(struct nfsd_file *nf) { bool is_hashed = test_bit(NFSD_FILE_HASHED, &nf->nf_flags) != 0; - bool unused = !nfsd_file_in_use(nf); set_bit(NFSD_FILE_REFERENCED, &nf->nf_flags); - if (nfsd_file_put_noref(nf) == 1 && is_hashed && unused) + if (nfsd_file_put_noref(nf) == 1 && is_hashed) nfsd_file_schedule_laundrette(); if (atomic_long_read(&nfsd_filecache_count) >= NFSD_FILE_LRU_LIMIT) nfsd_file_gc(); From patchwork Tue Dec 10 20:27:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11283213 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BB8FB112B for ; Tue, 10 Dec 2019 20:29:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9B80720836 for ; Tue, 10 Dec 2019 20:29:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WxBbp/k+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727047AbfLJU3x (ORCPT ); Tue, 10 Dec 2019 15:29:53 -0500 Received: from mail-yb1-f195.google.com ([209.85.219.195]:45866 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727048AbfLJU3w (ORCPT ); Tue, 10 Dec 2019 15:29:52 -0500 Received: by mail-yb1-f195.google.com with SMTP id i3so8132020ybe.12 for ; Tue, 10 Dec 2019 12:29:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BhsViqo0iLapQVB2vpZLRC2Hcy3AviaHK/eXGr600IY=; b=WxBbp/k+KUgx7hXmEjs+NTOGktmxEM8X8qUwdpysidExzTnlKuwOW508vY0peEp5kk hln/oSz4tn95aMgn5xD3cSFxsWO0t+0SXqlGV+ipT64vNy39zHlcjAiA28tB9QDJPzxx wKpq585Y+fgJT83NnML4AmgYvKzNH6N0BozMFIGqOpKPvuld2los5tN1whkoUpzun5j/ fUUzn9v5K1QVmlpbs+5jjcj59MWfjcUKXrE4uVIG9ldsVMVnh2bW6HRsNMh95KZS4G3f BWDWUwf3aKHx4nDdhTQq9nbyvmfxsotdTfb475rK0hJBGkN0xhZccbXPTM4hHn9Ax/pj fSpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BhsViqo0iLapQVB2vpZLRC2Hcy3AviaHK/eXGr600IY=; b=PYv7M5Y6dkDYeJfJEXG25IBOeJkgxitgcw9BzdPZkjXrq1KLA8FGBd6vVIXszPVAFm jfgb7ATreAQqmirrP37ZBcsAqmvPOK2sf/I08AZ444omXHdcNAULRRzsMV3/+X+E4V8v SJh7wVdsbh2yv8lMBe6cBXWxOZp+qu7JvRJfqvMAep22cTanAELXXXdIWJuABC11LRuR jI03ZlnM2pfly4m74ia2L2H9KXAVQkf54v+MqdO+d9VBtdA5cJT1nVgQPOhKTogBWiqz WO6FkK8YX9HTrhjlpAj0Ux4fDlz4zTR/ssl3WYzWPWXEl6LdM/P3OMc7iPxI64L6zqJC 7VYg== X-Gm-Message-State: APjAAAUGUTRxNuT0vFYRGTOT84r8HZ82K4gBar5k7UqYdu//kXx6jOeF ul1OTvIxlR8c/1SOVmzp1w== X-Google-Smtp-Source: APXvYqz7HLpdq9gR8IKUSPVehtEicwbYsPVuCz4V7/B87iGk/S2qXrPzLpGODJm6a0ulCyrWa5ctAw== X-Received: by 2002:a25:a229:: with SMTP id b38mr12887653ybi.208.1576009791447; Tue, 10 Dec 2019 12:29:51 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id x84sm1947508ywg.47.2019.12.10.12.29.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 12:29:51 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: Chuck Lever , linux-nfs@vger.kernel.org Subject: [PATCH 6/6] nfsd: Reduce the number of calls to nfsd_file_gc() Date: Tue, 10 Dec 2019 15:27:35 -0500 Message-Id: <20191210202735.304477-7-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191210202735.304477-6-trond.myklebust@hammerspace.com> References: <20191210202735.304477-1-trond.myklebust@hammerspace.com> <20191210202735.304477-2-trond.myklebust@hammerspace.com> <20191210202735.304477-3-trond.myklebust@hammerspace.com> <20191210202735.304477-4-trond.myklebust@hammerspace.com> <20191210202735.304477-5-trond.myklebust@hammerspace.com> <20191210202735.304477-6-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Don't call nfsd_file_gc() on every put of the reference in nfsd_file_put(). Instead, do it only when we're expecting the refcount to go to 1. Signed-off-by: Trond Myklebust --- fs/nfsd/filecache.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index 4cef03a7726c..9c2b29e07975 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -282,27 +282,32 @@ nfsd_file_unhash_and_release_locked(struct nfsd_file *nf, struct list_head *disp return true; } -static int +static void nfsd_file_put_noref(struct nfsd_file *nf) { - int count; trace_nfsd_file_put(nf); - count = atomic_dec_return(&nf->nf_ref); - if (!count) { + if (atomic_dec_and_test(&nf->nf_ref)) { WARN_ON(test_bit(NFSD_FILE_HASHED, &nf->nf_flags)); nfsd_file_free(nf); } - return count; } void nfsd_file_put(struct nfsd_file *nf) { - bool is_hashed = test_bit(NFSD_FILE_HASHED, &nf->nf_flags) != 0; + bool is_hashed; set_bit(NFSD_FILE_REFERENCED, &nf->nf_flags); - if (nfsd_file_put_noref(nf) == 1 && is_hashed) + if (atomic_read(&nf->nf_ref) > 2 || !nf->nf_file) { + nfsd_file_put_noref(nf); + return; + } + + filemap_flush(nf->nf_file->f_mapping); + is_hashed = test_bit(NFSD_FILE_HASHED, &nf->nf_flags) != 0; + nfsd_file_put_noref(nf); + if (is_hashed) nfsd_file_schedule_laundrette(); if (atomic_long_read(&nfsd_filecache_count) >= NFSD_FILE_LRU_LIMIT) nfsd_file_gc();