From patchwork Mon Feb 4 13:18:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 2091871 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id E76543FD56 for ; Mon, 4 Feb 2013 13:18:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755206Ab3BDNS3 (ORCPT ); Mon, 4 Feb 2013 08:18:29 -0500 Received: from mail-gh0-f180.google.com ([209.85.160.180]:32924 "EHLO mail-gh0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754819Ab3BDNS2 (ORCPT ); Mon, 4 Feb 2013 08:18:28 -0500 Received: by mail-gh0-f180.google.com with SMTP id f13so1525034ghb.11 for ; Mon, 04 Feb 2013 05:18:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=iwo+7zRlUXKJK08eAGtQW7Fjxb7Mgtq7n1MdbI0qKrg=; b=YKaKnFCVvAZTDDycp0EUFyXBktMbo5KYRKYAYEnHBqADLv/Rha87cDJA/IndjBCJEg amKxQIt83qcYctpEbLfOl5MCEB0MpsjzzefBmE7z3L/27W6RJtwIdItja7IHN6XV2bT8 RhwA+o7OVDOsmVvD+C5iyLQucgkAQMAVEJoEktb2FGiWQSL5/z0n9o/hRH33ZfNlqy45 RvodCpTfRoJl/q+/avapPvhskQxkfkljiGeplRnV7PVekKD/BQM+ePszWUw2OGPfsEz8 0xH10+ILzZMEbYYCOeGztYibYwO8zGUbwAB+0gy8ejbMx+xhA1g//1o7yDjN639kIzAA riZQ== X-Received: by 10.236.119.69 with SMTP id m45mr25573112yhh.128.1359983906894; Mon, 04 Feb 2013 05:18:26 -0800 (PST) Received: from salusa.poochiereds.net (cpe-107-015-113-143.nc.res.rr.com. [107.15.113.143]) by mx.google.com with ESMTPS id d80sm980595yhg.4.2013.02.04.05.18.24 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 04 Feb 2013 05:18:25 -0800 (PST) From: Jeff Layton To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 7/8] nfsd: register a shrinker for DRC cache entries Date: Mon, 4 Feb 2013 08:18:06 -0500 Message-Id: <1359983887-28535-8-git-send-email-jlayton@redhat.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1359983887-28535-1-git-send-email-jlayton@redhat.com> References: <1359983887-28535-1-git-send-email-jlayton@redhat.com> X-Gm-Message-State: ALoCoQk7iXkyzTvE1TEjoBnfZ5eOvHU/MXuNtl0SFW+8r2sNKGW9gAVVsxzmoFCEz3P1WQ/CsbWl Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Since we dynamically allocate them now, allow the system to call us up to release them if it gets low on memory. Since these entries aren't replaceable, only free ones that are expired or that are over the cap. The the seeks value is set to '1' however to indicate that freeing the these entries is low-cost. Signed-off-by: Jeff Layton --- fs/nfsd/nfscache.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c index d7b088b..d16a5d6 100644 --- a/fs/nfsd/nfscache.c +++ b/fs/nfsd/nfscache.c @@ -37,6 +37,13 @@ static inline u32 request_hash(u32 xid) static int nfsd_cache_append(struct svc_rqst *rqstp, struct kvec *vec); static void cache_cleaner_func(struct work_struct *unused); +static int nfsd_reply_cache_shrink(struct shrinker *shrink, + struct shrink_control *sc); + +struct shrinker nfsd_reply_cache_shrinker = { + .shrink = nfsd_reply_cache_shrink, + .seeks = 1, +}; /* * locking for the reply cache: @@ -110,6 +117,7 @@ nfsd_reply_cache_free(struct svc_cacherep *rp) int nfsd_reply_cache_init(void) { + register_shrinker(&nfsd_reply_cache_shrinker); drc_slab = kmem_cache_create("nfsd_drc", sizeof(struct svc_cacherep), 0, 0, NULL); if (!drc_slab) @@ -133,6 +141,7 @@ void nfsd_reply_cache_shutdown(void) { struct svc_cacherep *rp; + unregister_shrinker(&nfsd_reply_cache_shrinker); cancel_delayed_work_sync(&cache_cleaner); while (!list_empty(&lru_head)) { @@ -214,6 +223,20 @@ cache_cleaner_func(struct work_struct *unused) spin_unlock(&cache_lock); } +static int +nfsd_reply_cache_shrink(struct shrinker *shrink, struct shrink_control *sc) +{ + unsigned int num; + + spin_lock(&cache_lock); + if (sc->nr_to_scan) + prune_cache_entries(); + num = num_drc_entries; + spin_unlock(&cache_lock); + + return num; +} + /* * Search the request hash for an entry that matches the given rqstp. * Must be called with cache_lock held. Returns the found entry or