From patchwork Mon Jan 6 18:18:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11319751 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 CF591138D for ; Mon, 6 Jan 2020 18:20:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ADEE32072C for ; Mon, 6 Jan 2020 18:20:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XoROECx0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726692AbgAFSUZ (ORCPT ); Mon, 6 Jan 2020 13:20:25 -0500 Received: from mail-yb1-f193.google.com ([209.85.219.193]:41618 "EHLO mail-yb1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726569AbgAFSUZ (ORCPT ); Mon, 6 Jan 2020 13:20:25 -0500 Received: by mail-yb1-f193.google.com with SMTP id k5so2949279ybf.8 for ; Mon, 06 Jan 2020 10:20:24 -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=Y+DoU9c16qOJBTwhodTBS9tAvwt3McnxPZo6WbuuM4s=; b=XoROECx0J9seBlfxwv93TVEW3amti3VRyvP6zyqQF86P13CFH9wNp+FnZPz9kgDsHx 3EYZ2BMcfTZusNUL225jcZBLuPVRHtZ4Foqhfas9BpIj1t3ZCIEK1711HyzBfxRrfrMe 02JmcpsxqYXFJikLfEMkRlhrOZTT3aB46a2Sgc7YxCGsdzxZJY9RmPAHTo5Iep3QP5bb R7ZRqja/L1kERvzmaPjuU7zj4dD9sjLpapzm3qHHZGf7+T+wXW1eRVI47f35T0015ZTv C5h30Bv2yxmc6pjbycJ5V1ZFPyj4DuOY7XJQprWr72UHzveR41IlWLXT/N0pu37zU/Nx tCkg== 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=Y+DoU9c16qOJBTwhodTBS9tAvwt3McnxPZo6WbuuM4s=; b=Fdqxg8h9L+paCxQ42eGVuKXCwB+/S8PM/LQfovewRHwfx+h2PpgK7f1Gj78gy0pOir Y2OQ6Dmovs2U/vjregL+5xdZInd7TuvKaERCYmibXwseqVoFRqTDVkwKQWR6RVq1h0Mg hI/nqisLPj5221V5FWbwU57+ubw0WAkJB9LVh0LK1ntjbNaec189wtHJEOnjPscOKfrD wvlPo60i4gux9PlcUcoC8Q8sLVPejUOV6WK9fKI28OedFf0zrWBPO8Ri33pxnaTG0Vom WpY/ok5TBRoyUj2oYWYsK+qa5YzR2FIcyKPrjUAVsSj/mnVh4RtB3tVxALd+cVXIX+mA l4jA== X-Gm-Message-State: APjAAAXSM8RZ2fUCdfvmHBE4G0IoMIgVrRsYcTnh8LM0sjru0Fg4/4JV 3sXRr56BRgyQw773GFhMAFaM4PAaug== X-Google-Smtp-Source: APXvYqz139j6u32yBB4/DHz0YJ4yKLIfuK8oqFvWhQiINi3S394kYGpRWv8SKILirce/Rn7zEh/Tlg== X-Received: by 2002:a25:d2c6:: with SMTP id j189mr79374296ybg.374.1578334823589; Mon, 06 Jan 2020 10:20:23 -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 r31sm24800524ywa.82.2020.01.06.10.20.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2020 10:20:23 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH RESEND 1/6] nfsd: fix filecache lookup Date: Mon, 6 Jan 2020 13:18:03 -0500 Message-Id: <20200106181808.562969-2-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200106181808.562969-1-trond.myklebust@hammerspace.com> References: <20200106181808.562969-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 Mon Jan 6 18:18:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11319753 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 CF9F5138D for ; Mon, 6 Jan 2020 18:20:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AEE6F2072C for ; Mon, 6 Jan 2020 18:20:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hLMKcID/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726695AbgAFSU0 (ORCPT ); Mon, 6 Jan 2020 13:20:26 -0500 Received: from mail-yb1-f193.google.com ([209.85.219.193]:47075 "EHLO mail-yb1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726569AbgAFSUZ (ORCPT ); Mon, 6 Jan 2020 13:20:25 -0500 Received: by mail-yb1-f193.google.com with SMTP id k128so11451628ybc.13 for ; Mon, 06 Jan 2020 10:20:25 -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=rtsdhCrWJX5DzFNesThGe18gpecWEgRIZqACkkfv9FA=; b=hLMKcID/Xevb2W4Cd7mfa+CTclzY755gzF/d8BmPejubC682KWHkY07DSzTaD7Z2PL 972kBiiTSf6HPED4E7ULjQnix9p2QOJKFV0NQKV+7NJZAsGrhbQgWOu6hXNsiU1BBUCN /yHgE+lmo8G27C8hRtqN9ZkFL/QMfP7vd9mjfw5SaoS1dGVOAwwjR5lwOwWfg+BJwHtt s2lrNlq5HtLlKQt6LuRcZKdQkikjpSQ4Dx72CDBN6AJ9SaeBc4akf8jDcZJZJmr0TiT7 OxmX6mAmZr3cJXlA7w7uJPXZZfYfzH86i26BOqUHGeAID+wyoLFGOK1H4roIblpSU+4F K/ZQ== 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=rtsdhCrWJX5DzFNesThGe18gpecWEgRIZqACkkfv9FA=; b=Bk7eD9frxIXPrKWq5Y+p7EvkU+syzIOKTkGxUPzemyX9EUffTtwxaPMVliweY7T4fd 9HDJ5XGf9E+ltVNY1EnsT+9MaDJwmBK4SpnXvOUnvyXzzeMM3GJ2u+7C6fL5IdjogbFo dGVQWGgZgupe5bE6gPYoZFTun5tgQhDNz0IbFHE8NLiRXGmb2C01SY++U2BdhHi6qp7k 95lmZuF6F8deYEIjI6dV4XKLRGiTTNjL1t8+27ZmT1HMI9cVDBEk6byHaQuN8UtAfUku ovefYTSFOhPTKhsinKO/UjMk7Q6ECCCjYR1ZzSdUPQ6x2FFY7NR5jUN9r3tsnuxbF4gW Wr6g== X-Gm-Message-State: APjAAAXUfFoOnZprY8/bkZVzRBh055ecLDXh6wBix7AUJEtvInRCo6ud hNDiT1QQdHvrtT1e2yQWjV+qGr3lew== X-Google-Smtp-Source: APXvYqwGwgbvKBUnvYTSapiB2dOBRuhX09qdl4Z7eG5UuTYAyrdbDHuKOwu54dMq+JJocQNNnKKkVw== X-Received: by 2002:a25:743:: with SMTP id 64mr77285395ybh.178.1578334824728; Mon, 06 Jan 2020 10:20:24 -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 r31sm24800524ywa.82.2020.01.06.10.20.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2020 10:20:24 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH RESEND 2/6] nfsd: cleanup nfsd_file_lru_dispose() Date: Mon, 6 Jan 2020 13:18:04 -0500 Message-Id: <20200106181808.562969-3-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200106181808.562969-2-trond.myklebust@hammerspace.com> References: <20200106181808.562969-1-trond.myklebust@hammerspace.com> <20200106181808.562969-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 Mon Jan 6 18:18:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11319755 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 1BCEF6C1 for ; Mon, 6 Jan 2020 18:20:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DAE182072C for ; Mon, 6 Jan 2020 18:20:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FzTztk/6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726683AbgAFSU1 (ORCPT ); Mon, 6 Jan 2020 13:20:27 -0500 Received: from mail-yb1-f194.google.com ([209.85.219.194]:41621 "EHLO mail-yb1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726569AbgAFSU1 (ORCPT ); Mon, 6 Jan 2020 13:20:27 -0500 Received: by mail-yb1-f194.google.com with SMTP id k5so2949323ybf.8 for ; Mon, 06 Jan 2020 10:20:26 -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=MXI7TKmJZJi0CofkXvBvPSoItXOdOc5Wya7Tcn2EIOU=; b=FzTztk/6KAQPL2NrszJFO2Afl19DjLcd0P1H0n9g5/n5p8UPVFKhRUOoVYLHPTuHP2 FSq7GsmW7/eW0665Ec4p3TdKqu32t+GRwoq3H8fA4/ywt6GexhtVem/NZldNxllk/RXE 1Z40tkFxPETq5PGnLojs48VgwQzXrgtc5783RBafSEciaSEaLcFha1w2kda0GzdYuu0n aWZPN7ip+Ly0uwOXkfO8IZA5qI8Eb/mcv7ZzKrbMotRlZ61AqAH1rPgG1wOZrBGo2kdU N7UB+GTs36MjkgbLXd/9ZSBRv4Dn89wdp5wV1xASONJ20vNTv9QeXhaWYd1ng/e9p6sU jx1w== 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=MXI7TKmJZJi0CofkXvBvPSoItXOdOc5Wya7Tcn2EIOU=; b=oEuOACAKwKQqt1cCXyivGq/jb1Bp7SckwIZ1wF7GnnMloOLNzvGpxsRgeHn/J15osa x5cnn06YHWJAyqBCdZPBH2rApmIbuYfc8zj4dma+Pi7nWuEOHep7WDiXVaAGqMShkOD3 zNoMSuFAWzf0ThqDpv22t5i1F3j1uTzEj2h6/f8DW2nIMPjxCDwer4u0D1ZclLhMnQ8U BHeT7FFNFXya9BHysC4Z/ERZvZcQ4156cUILDDBdiel+XKj8Dn40WRPwJ17T4MF20k+w 09AEWQKzr90CXl6ZgZJwS6oD9WyqBPQJ800xORZya67CwSVsJT9PMZ3EzbbhLaI0xj+v ilMw== X-Gm-Message-State: APjAAAXZxQRCwn705ZA7CgEjRoBL2L+l619/zvguqblxpPAKazY9LBbn 2iEdDRe4BXlfamdyJapgPA== X-Google-Smtp-Source: APXvYqyPl6FpenZwRuOI1Klu9fr61vA9hYMR0bup9UCU49l4zNVylWTgcVgQPRIDiDPg/n8aVR3tmA== X-Received: by 2002:a25:dc52:: with SMTP id y79mr69086892ybe.354.1578334825710; Mon, 06 Jan 2020 10:20:25 -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 r31sm24800524ywa.82.2020.01.06.10.20.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2020 10:20:25 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH RESEND 3/6] nfsd: Containerise filecache laundrette Date: Mon, 6 Jan 2020 13:18:05 -0500 Message-Id: <20200106181808.562969-4-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200106181808.562969-3-trond.myklebust@hammerspace.com> References: <20200106181808.562969-1-trond.myklebust@hammerspace.com> <20200106181808.562969-2-trond.myklebust@hammerspace.com> <20200106181808.562969-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 Mon Jan 6 18:18:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11319757 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 82093138D for ; Mon, 6 Jan 2020 18:20:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 618452072C for ; Mon, 6 Jan 2020 18:20:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="l5+chSSB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726699AbgAFSU2 (ORCPT ); Mon, 6 Jan 2020 13:20:28 -0500 Received: from mail-yb1-f196.google.com ([209.85.219.196]:47081 "EHLO mail-yb1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726569AbgAFSU2 (ORCPT ); Mon, 6 Jan 2020 13:20:28 -0500 Received: by mail-yb1-f196.google.com with SMTP id k128so11451691ybc.13 for ; Mon, 06 Jan 2020 10:20:27 -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=gY3N9AW/BeVLH0xQqk5UEbr4T+5CiQQRmrXEg2SfK5A=; b=l5+chSSB8oPQM7hPYJY/+OGdxsCe5IXcFG1SOUtrzxYIdjz8M5Pd6b//LkxDTOoJ7J /8X+ZPu+JKxdjmY6WCX8OGDXKdseC0yT4JE81HwDK955Qb/oHCYkwIskbCTbSFBjEQN8 te2VGh1//gpbWsBsmF/YzgAq19TPVGPKNvf7+YiZ+JMtL122hQtuaOjC9OpvSkWiY5qw Z1W6h365q84b9AgXzAnESXs/4OTVWRudis3cD7MpB9hN2qBTgjHjwoVd5VBJgJrqTmh0 tzWZgGnm6+chKKDICeefpOjAMkf6vqCnzPZOL9ojOX+a0mOAPB+qSri6Y6hwNBR+DSru woPw== 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=gY3N9AW/BeVLH0xQqk5UEbr4T+5CiQQRmrXEg2SfK5A=; b=FN4uO4b/Zp6D5xMKj/MHiKGFUYsu1M6JRILgZhRMOybbRBqaOEVES6ZFuOtZY1hHNM zFNgzLp93zf8TWzaLwdlVIuva+esqpX4jJCyMqt3555mpiOBbElgT2qDFP7KWWbFaZDm 3bfD8p/f2opH1Lpl9hNPt+1BHStpUcT63XY9zYZIxP9ffnfSRTshEYldkqIhI4/t4sRK Tb2DBc+yzulQs/PutAXSoB2nFCnjsDoQTH0jMEZEvaOza5PXh1R5gYzvIMS5rvTyCRhH ZMRXQdYt1rPMtI3+yjNTw8kPtIX+x8DuW7hDkNQbMK2bC2FbCIV2OX3PavWVkla1Z8ks LsEw== X-Gm-Message-State: APjAAAXEvFBgyPHdB67Se6KA/c0DwEDMSpXxLVT8k0d4MEVCGdkVExw6 qX3tNyJkXnAhamEtVsAy8mT+trBIxQ== X-Google-Smtp-Source: APXvYqy6ed+Lq1AQH9dQsCRM3YRHR501Ej/QOUqznojJEXpdjOA7IyDiBkdNVzAJi0ysiAYBckUUHw== X-Received: by 2002:a25:d903:: with SMTP id q3mr73202584ybg.244.1578334827038; Mon, 06 Jan 2020 10:20:27 -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 r31sm24800524ywa.82.2020.01.06.10.20.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2020 10:20:26 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH RESEND 4/6] nfsd: Remove unused constant NFSD_FILE_LRU_RESCAN Date: Mon, 6 Jan 2020 13:18:06 -0500 Message-Id: <20200106181808.562969-5-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200106181808.562969-4-trond.myklebust@hammerspace.com> References: <20200106181808.562969-1-trond.myklebust@hammerspace.com> <20200106181808.562969-2-trond.myklebust@hammerspace.com> <20200106181808.562969-3-trond.myklebust@hammerspace.com> <20200106181808.562969-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 Mon Jan 6 18:18:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11319759 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 B4E0E138D for ; Mon, 6 Jan 2020 18:20:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9420A2072C for ; Mon, 6 Jan 2020 18:20:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aAvoZM/5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726701AbgAFSUa (ORCPT ); Mon, 6 Jan 2020 13:20:30 -0500 Received: from mail-yw1-f68.google.com ([209.85.161.68]:36783 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726698AbgAFSU3 (ORCPT ); Mon, 6 Jan 2020 13:20:29 -0500 Received: by mail-yw1-f68.google.com with SMTP id n184so22258758ywc.3 for ; Mon, 06 Jan 2020 10:20:28 -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=1FuNP4R+SuvQzOLYpKGWQClYNeimIeK+zk75+PZJGI0=; b=aAvoZM/5/wI1MyGb6tR5WCworsxK0eZklq65oVpxmayQe2mb9+76hSM49UlnuAWlVf oa/PwobEzVWMBZe40qg+Rt7SSbbYgB8W5cV0GI40OzqaAaIkECXIkwe9wVDqDJTlcB6f FDzh7Qp6YaITC2N68oHSayMIZXIOfPUP8A0X1UCm4ypHjlZRzJ4WxxWLBab3yrvbpQma dWZhEeBxLdE9kzzyzOQvHHJFWVLHHkV7k/XX1h9wVxH9HGQwPG87iTYEPJ9t7zQ0pby8 V/w7RKCm95yHsSODnqwFyjyvturn4G63AWKOLvTKpGhr7o6qPjHrsuKQ2hM3g7O5XwmK cmLQ== 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=1FuNP4R+SuvQzOLYpKGWQClYNeimIeK+zk75+PZJGI0=; b=YJR0QBNfvXkOo4q/UwNku4ykIgRJN9kPCN/9qM4MJE4Udw2VtMAqYqfo6ES3CRHHzX cGr3wO5oCYG8CPFgJJgLKz2AP4wSTKR2y/IWOhPZrj3jQbVlX4b+19s5CmF7vCtbMpjs LuoNwn0IQF/XLmc1AyM5iRHLquUbIAxJDUV9EfPYWIyMSmI3wfUkTwAqdXyigtLFiZ/g 7dt3CyywZle2zy3DeXiOuBDgr6k4KQ//6KetCYanYXGuIK1AP2IYZ/Qs8QMVCggVhARh JXhh6M/bVjqmxJpQl17IFQbQQaGfVCEFmgrQoJ6UkPS4IA6do4XeSjPahR65xGRJv98M P68g== X-Gm-Message-State: APjAAAXy7rNDB/oeS6obU1JPC1y33OJPYijkXkdWNK6y1wR9fgw958R+ G8qmkzZwrAAzILRP8VerCA== X-Google-Smtp-Source: APXvYqx4TcThYfgs7qrONHjvGp5peUCEAGa5UEtZWBQDDUVqeBQuykQsJTWCzF/dHuakVrR//wWdwQ== X-Received: by 2002:a0d:c444:: with SMTP id g65mr77972588ywd.119.1578334828009; Mon, 06 Jan 2020 10:20:28 -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 r31sm24800524ywa.82.2020.01.06.10.20.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2020 10:20:27 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH RESEND 5/6] nfsd: Schedule the laundrette regularly irrespective of file errors Date: Mon, 6 Jan 2020 13:18:07 -0500 Message-Id: <20200106181808.562969-6-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200106181808.562969-5-trond.myklebust@hammerspace.com> References: <20200106181808.562969-1-trond.myklebust@hammerspace.com> <20200106181808.562969-2-trond.myklebust@hammerspace.com> <20200106181808.562969-3-trond.myklebust@hammerspace.com> <20200106181808.562969-4-trond.myklebust@hammerspace.com> <20200106181808.562969-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 Mon Jan 6 18:18:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11319761 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 F123B6C1 for ; Mon, 6 Jan 2020 18:20:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D0B3B2072C for ; Mon, 6 Jan 2020 18:20:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nZLylNO8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726569AbgAFSUa (ORCPT ); Mon, 6 Jan 2020 13:20:30 -0500 Received: from mail-yw1-f65.google.com ([209.85.161.65]:41256 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726700AbgAFSUa (ORCPT ); Mon, 6 Jan 2020 13:20:30 -0500 Received: by mail-yw1-f65.google.com with SMTP id l22so22246331ywc.8 for ; Mon, 06 Jan 2020 10:20:29 -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=9oOxowOdQD1G670wo6ZQAwloHGVMH3sqqzOg0q1KWUQ=; b=nZLylNO8GuI2iCHlEGUbiCMUH0LNBanT3eAwgWiZmzFvPlgmKemA1UjYC/hiZkPcpp BfaODNTcDMRfPr3Dss73Hti47at6SdyOCwsho7nVMlBrV/hkbHsFrMC7HWfLiJMB3ziR CVASG4GCzPrxmtKcI+ESShoLyYD4vsvmoGKTzFVXx3xIEP4V2xtT1Efwp3tPqYwsTeZI aSFXEPgoiV2tzFV8z/imOeCCSPzrk30GG21aOMfjkT70X0QK3ymQy7ohJY17uDzQK9sy 6mRGR9Buh725AloepVDF8YclSNCwzjc5IAZXzYvWznWtB2UWLvrYBlWUotvdEBnk4LTj OVgw== 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=9oOxowOdQD1G670wo6ZQAwloHGVMH3sqqzOg0q1KWUQ=; b=TxH22b1ftuMt5BABY5aLUfBPByTe9KoXgvqGJW/dD5jbYnQ3xxQt+nYjab+UUoBGVM Mhq0CmXWtVx0GH+L+Msvg17xCaM2lNVkljEazNziSiIKtFmcPJ1yREB88vzWt33J822K ETXngCEQZ+vqTOsrFE8SE+L83yJGUW8QHZbEVMC1hywUb9JQ4/L0TgrYUeZOlYMEAkIX 6e3ku5n1TPfLIJPabk/vCjUu5TJaX0wJqBLrrHEfdETm3pzI+DsZRoZGqMRucAunQVRI qq8mgqBpZZ69RfCgZERc+DM5TSvW0uJpbLEhPgZ+dqFF8Ed9IEbDns33fMwyYh+vtVUl GZ6A== X-Gm-Message-State: APjAAAW25Ki0jxArOF+Bar1PFDSIg/LNprc/7sr/e6TNxNwHii6vmKnj OzAGCmUpFY2FpnmwOEKpOQ== X-Google-Smtp-Source: APXvYqwyTgBk9CBJoh0Ahm7xeAF/UfN3Oh/Ntnw1R9d4P2sKEcQ0rPmrQHEFKPCB8IpYR1Fwm7Gvxg== X-Received: by 2002:a81:7913:: with SMTP id u19mr73020172ywc.321.1578334828892; Mon, 06 Jan 2020 10:20:28 -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 r31sm24800524ywa.82.2020.01.06.10.20.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2020 10:20:28 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH RESEND 6/6] nfsd: Reduce the number of calls to nfsd_file_gc() Date: Mon, 6 Jan 2020 13:18:08 -0500 Message-Id: <20200106181808.562969-7-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200106181808.562969-6-trond.myklebust@hammerspace.com> References: <20200106181808.562969-1-trond.myklebust@hammerspace.com> <20200106181808.562969-2-trond.myklebust@hammerspace.com> <20200106181808.562969-3-trond.myklebust@hammerspace.com> <20200106181808.562969-4-trond.myklebust@hammerspace.com> <20200106181808.562969-5-trond.myklebust@hammerspace.com> <20200106181808.562969-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();