From patchwork Thu Aug 20 11:17:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 7043641 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B804BC05AD for ; Thu, 20 Aug 2015 11:17:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E00D4205CB for ; Thu, 20 Aug 2015 11:17:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E6083205C4 for ; Thu, 20 Aug 2015 11:17:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751823AbbHTLRe (ORCPT ); Thu, 20 Aug 2015 07:17:34 -0400 Received: from mail-yk0-f175.google.com ([209.85.160.175]:34807 "EHLO mail-yk0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751759AbbHTLRc (ORCPT ); Thu, 20 Aug 2015 07:17:32 -0400 Received: by ykdt205 with SMTP id t205so33872295ykd.1 for ; Thu, 20 Aug 2015 04:17:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=61b7W8s8lEICgYO5mTxVBHm0wMDuVStnvYGl2OuWsXU=; b=FTv387GF1WWoSo0Nq8VU3EejadqyJPEUK77HKFsr2ChRzHm3DQ66pculcIjfTrG5No 3KtcVIZFbSa2qx+RSgT0NgAlAEpEHWh6jN7VfRpbWTG0BTB+49sMjCspBCKbZE7f+n0g DH2MMQpQCA+YA/rPOLNRaa1054IfFhviTq2fDFCmWpPgoOT/HZb71Q5QeifhkcZiXeA6 dPLeJQWWnLGSW4gCtaBVoHhjmK72S+n57aX7OSeaHYRir9dk3px069Fs/wMc+taM5mdU iGCvczPp2lK8+JtePT1gwI3FWElgCz243soAKVHN5al3S3kcnL2cX0896gEq81w+eDsK Ndbw== X-Gm-Message-State: ALoCoQlPpsYvR+RJAZjKtvYqsWoLdxcddL3K2szLEHVs7y/0662J6pDq/5Q50Wm4in6i0H+XTojF X-Received: by 10.13.201.3 with SMTP id l3mr2547758ywd.118.1440069451853; Thu, 20 Aug 2015 04:17:31 -0700 (PDT) Received: from tlielax.poochiereds.net (cpe-45-37-211-243.nc.res.rr.com. [45.37.211.243]) by smtp.googlemail.com with ESMTPSA id k66sm3637319ywe.0.2015.08.20.04.17.31 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Aug 2015 04:17:31 -0700 (PDT) From: Jeff Layton X-Google-Original-From: Jeff Layton To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org, hch@lst.de, kinglongmee@gmail.com Subject: [PATCH v3 05/20] nfsd: add a shrinker to the nfsd_file cache Date: Thu, 20 Aug 2015 07:17:05 -0400 Message-Id: <1440069440-27454-6-git-send-email-jeff.layton@primarydata.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1440069440-27454-1-git-send-email-jeff.layton@primarydata.com> References: <1440069440-27454-1-git-send-email-jeff.layton@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Jeff Layton --- fs/nfsd/filecache.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index 63b24419c674..669e62f6f4f6 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -118,6 +118,46 @@ nfsd_file_dispose_list(struct list_head *dispose) } } +static enum lru_status +nfsd_file_lru_cb(struct list_head *item, struct list_lru_one *lru, + spinlock_t *lock, void *arg) + __releases(lock) + __acquires(lock) +{ + struct nfsd_file *nf = list_entry(item, struct nfsd_file, nf_lru); + bool unhashed; + + if (atomic_read(&nf->nf_ref) > 1) + return LRU_SKIP; + + spin_unlock(lock); + spin_lock(&nfsd_file_hashtbl[nf->nf_hashval].nfb_lock); + unhashed = nfsd_file_unhash(nf); + spin_unlock(&nfsd_file_hashtbl[nf->nf_hashval].nfb_lock); + if (unhashed) + nfsd_file_put(nf); + spin_lock(lock); + return unhashed ? LRU_REMOVED_RETRY : LRU_RETRY; +} + +static unsigned long +nfsd_file_lru_count(struct shrinker *s, struct shrink_control *sc) +{ + return list_lru_count(&nfsd_file_lru); +} + +static unsigned long +nfsd_file_lru_scan(struct shrinker *s, struct shrink_control *sc) +{ + return list_lru_shrink_walk(&nfsd_file_lru, sc, nfsd_file_lru_cb, NULL); +} + +static struct shrinker nfsd_file_shrinker = { + .scan_objects = nfsd_file_lru_scan, + .count_objects = nfsd_file_lru_count, + .seeks = 1, +}; + int nfsd_file_cache_init(void) { @@ -140,12 +180,20 @@ nfsd_file_cache_init(void) goto out_err; } + ret = register_shrinker(&nfsd_file_shrinker); + if (ret) { + pr_err("nfsd: failed to register nfsd_file_shrinker: %d\n", ret); + goto out_lru; + } + for (i = 0; i < NFSD_FILE_HASH_SIZE; i++) { INIT_HLIST_HEAD(&nfsd_file_hashtbl[i].nfb_head); spin_lock_init(&nfsd_file_hashtbl[i].nfb_lock); } out: return ret; +out_lru: + list_lru_destroy(&nfsd_file_lru); out_err: kfree(nfsd_file_hashtbl); nfsd_file_hashtbl = NULL; @@ -159,6 +207,7 @@ nfsd_file_cache_shutdown(void) struct nfsd_file *nf; LIST_HEAD(dispose); + unregister_shrinker(&nfsd_file_shrinker); for (i = 0; i < NFSD_FILE_HASH_SIZE; i++) { spin_lock(&nfsd_file_hashtbl[i].nfb_lock); while(!hlist_empty(&nfsd_file_hashtbl[i].nfb_head)) {