From patchwork Fri Jul 21 13:43:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 9856967 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C77D9600F5 for ; Fri, 21 Jul 2017 13:44:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD51728749 for ; Fri, 21 Jul 2017 13:44:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1D90287B6; Fri, 21 Jul 2017 13:44:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 70D7728749 for ; Fri, 21 Jul 2017 13:44:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753894AbdGUNnh (ORCPT ); Fri, 21 Jul 2017 09:43:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35626 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750858AbdGUNnf (ORCPT ); Fri, 21 Jul 2017 09:43:35 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B3250C0B2A44; Fri, 21 Jul 2017 13:43:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B3250C0B2A44 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=longman@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B3250C0B2A44 Received: from llong.com (dhcp-17-6.bos.redhat.com [10.18.17.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9732F17DD8; Fri, 21 Jul 2017 13:43:33 +0000 (UTC) From: Waiman Long To: Alexander Viro , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Paul E. McKenney" , Andrew Morton , Ingo Molnar , Miklos Szeredi , Matthew Wilcox , Larry Woodman , Waiman Long Subject: [PATCH v2 2/4] fs/dcache: Report negative dentry number in dentry-state Date: Fri, 21 Jul 2017 09:43:08 -0400 Message-Id: <1500644590-6599-3-git-send-email-longman@redhat.com> In-Reply-To: <1500644590-6599-1-git-send-email-longman@redhat.com> References: <1500644590-6599-1-git-send-email-longman@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 21 Jul 2017 13:43:34 +0000 (UTC) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The number of negative dentries currently in the system is now reported in the /proc/sys/fs/dentry-state file. Signed-off-by: Waiman Long --- fs/dcache.c | 16 +++++++++++++++- include/linux/dcache.h | 7 ++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/fs/dcache.c b/fs/dcache.c index 866df38..d6d2d2d 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -135,6 +135,7 @@ struct dentry_stat_t dentry_stat = { */ #define NEG_DENTRY_BATCH (1 << 8) static long neg_dentry_percpu_limit __read_mostly; +static long neg_dentry_nfree_init __read_mostly; /* Free pool initial value */ static struct { raw_spinlock_t nfree_lock; long nfree; /* Negative dentry free pool */ @@ -176,11 +177,23 @@ static long get_nr_dentry_unused(void) return sum < 0 ? 0 : sum; } +static long get_nr_dentry_neg(void) +{ + int i; + long sum = 0; + + for_each_possible_cpu(i) + sum += per_cpu(nr_dentry_neg, i); + sum += neg_dentry_nfree_init - ndblk.nfree; + return sum < 0 ? 0 : sum; +} + int proc_nr_dentry(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { dentry_stat.nr_dentry = get_nr_dentry(); dentry_stat.nr_unused = get_nr_dentry_unused(); + dentry_stat.nr_negative = get_nr_dentry_neg(); return proc_doulongvec_minmax(table, write, buffer, lenp, ppos); } #endif @@ -3733,7 +3746,8 @@ static void __init neg_dentry_init(void) raw_spin_lock_init(&ndblk.nfree_lock); /* 20% in global pool & 80% in percpu free */ - ndblk.nfree = totalram_pages * nr_dentry_page * neg_dentry_pc / 500; + ndblk.nfree = neg_dentry_nfree_init + = totalram_pages * nr_dentry_page * neg_dentry_pc / 500; cnt = ndblk.nfree * 4 / num_possible_cpus(); if (unlikely(cnt < 2 * NEG_DENTRY_BATCH)) cnt = 2 * NEG_DENTRY_BATCH; diff --git a/include/linux/dcache.h b/include/linux/dcache.h index 498233b..0f749e2 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -63,9 +63,10 @@ struct qstr { struct dentry_stat_t { long nr_dentry; long nr_unused; - long age_limit; /* age in seconds */ - long want_pages; /* pages requested by system */ - long dummy[2]; + long age_limit; /* age in seconds */ + long want_pages; /* pages requested by system */ + long nr_negative; /* # of negative dentries */ + long dummy; }; extern struct dentry_stat_t dentry_stat;