From patchwork Fri Jul 6 19:32:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 10512463 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 E855C6024A for ; Fri, 6 Jul 2018 19:34:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D793B287AC for ; Fri, 6 Jul 2018 19:34:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CBF1C287B7; Fri, 6 Jul 2018 19:34:55 +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=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49EB9287AC for ; Fri, 6 Jul 2018 19:34:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 453EB6B0273; Fri, 6 Jul 2018 15:34:33 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3B6D56B0274; Fri, 6 Jul 2018 15:34:33 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20F816B0275; Fri, 6 Jul 2018 15:34:33 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk0-f200.google.com (mail-qk0-f200.google.com [209.85.220.200]) by kanga.kvack.org (Postfix) with ESMTP id D36FD6B0274 for ; Fri, 6 Jul 2018 15:34:32 -0400 (EDT) Received: by mail-qk0-f200.google.com with SMTP id h67-v6so13821131qke.18 for ; Fri, 06 Jul 2018 12:34:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=evGngQSaXuFvTD/Wr1UPbAncum/3kS32fhyKZkJ1fGU=; b=S9JE3EDE4gnRvsCs4CvJI0vcDNkYl08wDgwN2GPBICxhoxgCr0XO/HcNq6fRTtdqKP rkbaph9dyKeOoQqmXXfTjGNNvfvowKvTr1G6nCZMUZ3xQpFeIspY3lPi4nsj9DPINDCR xIjVehBJm/kwBc5F9XwLTgvBCZ75bpLE4KBOesp1nPwYoyivTJU2iyPg8XJJn6Mm9/4O 2dmV970k2ly/xwf1q8J+Ajb3IfHYmK5riYnmnvaR1wmd9IK6VzpOMH9J5BaLvgv8/dIz twVEl46lqm65tuEWtsRduwe98yRpdqz1G1az+ZStQs09LiId3/TOYvDKpBQluEIkNoVI +bxw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of longman@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APt69E2onnugDUezcnRfQjHpFWiBlZAc5/Di7fquRqG386cgrNemttEP ICEP7G89U1ptN4BOppENTMGM8CJ2PQkgHWREk2My++f4pH5tj8XZy/JZgotqw/XtRIKdNrx2/iN 8uTrB9RQH1BOlWkzOQDjfd7Dca8/C6JX2lCOz7feZOFWgc1m4UvG5TAtT9ysKc9wliw== X-Received: by 2002:a0c:d683:: with SMTP id k3-v6mr9965016qvi.154.1530905672587; Fri, 06 Jul 2018 12:34:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfwmuUiOf4CXyY+j8dAdKf5eUi9IfKCH1pSQhWdtPqKdefjqtWNGJXWAGwzIFxX0sABBToQ X-Received: by 2002:a0c:d683:: with SMTP id k3-v6mr9964971qvi.154.1530905671786; Fri, 06 Jul 2018 12:34:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530905671; cv=none; d=google.com; s=arc-20160816; b=jHy1uvyRupvzZjdbsjgaMnaaq7BWgHnrG4FBHP5KOiXBLZ77/HfWaULOXoHyKYYiB3 dBgpLJRYFhejGdipHHnTYwieLrepUcxcgQA4+cnue+8vbRnMM2PqsuSK4wWb/1xQWNxP W3/jOiKoI9yRZR1hUqTGO7FLW1OnMkWU/6rjYoztTV6AF79Imqo8ZZ15IgdXQmd7FQMY WA+qSatzh5GTc8una+QrEXIeZbCNxb8amEqp3viFJx0ALAL/3L3CuZWJmYxDYz4B847k vPAxg96dgfKIZ7YoOA34QdOJPeGLSxRyyIuuRDAGyw6fhT6Rg6Mdrx2D5ZW5cIMiz66e s//A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=evGngQSaXuFvTD/Wr1UPbAncum/3kS32fhyKZkJ1fGU=; b=ODuHusJHGuw17YERAJNhlWzAU6Cv+PO8P4pt3CIEf6Syagifcvi87DyanffZYRRyzq 93ReNzJp4USn2Kz6HlfLR1LrrPxiLA+jFbijAlMqAA2tU41Oe+9WSf9zJM2AeL9MzO7v AXvliP+ftLjG/Sg2lErSrAwAp/+2Z7OwExj2TjY9vMTO0J2weaszR2p8gIeFgFb1uzOY XxYeDLHear6FEppRDJxSA8vLY2WiAaflzRNxtIdam3AIK00VWWrOz6Ays8Z4VXpGSzD7 BPd/Nd0ZMogrgi8tMuCJa/IZRAvAOwEIs2c0REqkVnBZygFrdy6JEOnJtEpwNYpM7VSO 2qMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of longman@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx3-rdu2.redhat.com. [66.187.233.73]) by mx.google.com with ESMTPS id b57-v6si2210070qte.346.2018.07.06.12.34.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Jul 2018 12:34:31 -0700 (PDT) Received-SPF: pass (google.com: domain of longman@redhat.com designates 66.187.233.73 as permitted sender) client-ip=66.187.233.73; Authentication-Results: mx.google.com; spf=pass (google.com: domain of longman@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 619F1401DE81; Fri, 6 Jul 2018 19:34:31 +0000 (UTC) Received: from llong.com (dhcp-17-175.bos.redhat.com [10.18.17.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id E519979DE; Fri, 6 Jul 2018 19:34:30 +0000 (UTC) From: Waiman Long To: Alexander Viro , Jonathan Corbet , "Luis R. Rodriguez" , Kees Cook Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, Linus Torvalds , Jan Kara , "Paul E. McKenney" , Andrew Morton , Ingo Molnar , Miklos Szeredi , Matthew Wilcox , Larry Woodman , James Bottomley , "Wangkai (Kevin C)" , Waiman Long Subject: [PATCH v6 7/7] fs/dcache: Allow deconfiguration of negative dentry code to reduce kernel size Date: Fri, 6 Jul 2018 15:32:52 -0400 Message-Id: <1530905572-817-8-git-send-email-longman@redhat.com> In-Reply-To: <1530905572-817-1-git-send-email-longman@redhat.com> References: <1530905572-817-1-git-send-email-longman@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 06 Jul 2018 19:34:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 06 Jul 2018 19:34:31 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'longman@redhat.com' RCPT:'' X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP The tracking and limit of negative dentries in a filesystem is a useful addition. However, for users who want to reduce the kernel size as much as possible, this feature will probably be on the chopping block. To suit those users, a default-y config option DCACHE_LIMIT_NEG_ENTRY is added so that the negative dentry tracking and limiting code can be configured out, if necessary. Signed-off-by: Waiman Long --- fs/Kconfig | 10 ++++++++++ fs/dcache.c | 33 ++++++++++++++++++++++++++++++++- include/linux/dcache.h | 2 ++ kernel/sysctl.c | 2 ++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/fs/Kconfig b/fs/Kconfig index ac474a6..b521941 100644 --- a/fs/Kconfig +++ b/fs/Kconfig @@ -113,6 +113,16 @@ source "fs/autofs/Kconfig" source "fs/fuse/Kconfig" source "fs/overlayfs/Kconfig" +# +# Track and limit the number of negative dentries allowed in the system. +# +config DCACHE_LIMIT_NEG_ENTRY + bool "Track & limit negative dcache entries" + default y + help + This option enables the tracking and limiting of the total + number of negative dcache entries allowable in the filesystem. + menu "Caches" source "fs/fscache/Kconfig" diff --git a/fs/dcache.c b/fs/dcache.c index 43d49d7..d00761e 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -143,6 +143,7 @@ struct dentry_stat_t dentry_stat = { #define NEG_IS_SB_UMOUNTING(sb) \ unlikely(!(sb)->s_root || !((sb)->s_flags & MS_ACTIVE)) +#ifdef CONFIG_DCACHE_LIMIT_NEG_ENTRY static struct static_key limit_neg_key = STATIC_KEY_INIT_FALSE; static int neg_dentry_pc_old; int neg_dentry_pc; @@ -166,10 +167,11 @@ struct dentry_stat_t dentry_stat = { static void d_lru_del(struct dentry *dentry); static void prune_negative_dentry(struct work_struct *work); static DECLARE_DELAYED_WORK(prune_neg_dentry_work, prune_negative_dentry); +static DEFINE_PER_CPU(long, nr_dentry_neg); +#endif /* CONFIG_DCACHE_LIMIT_NEG_ENTRY */ static DEFINE_PER_CPU(long, nr_dentry); static DEFINE_PER_CPU(long, nr_dentry_unused); -static DEFINE_PER_CPU(long, nr_dentry_neg); #if defined(CONFIG_SYSCTL) && defined(CONFIG_PROC_FS) @@ -203,6 +205,7 @@ static long get_nr_dentry_unused(void) return sum < 0 ? 0 : sum; } +#ifdef CONFIG_DCACHE_LIMIT_NEG_ENTRY static long get_nr_dentry_neg(void) { int i; @@ -213,6 +216,9 @@ static long get_nr_dentry_neg(void) sum += neg_dentry_nfree_init - ndblk.nfree; return sum < 0 ? 0 : sum; } +#else +static long get_nr_dentry_neg(void) { return 0; } +#endif int proc_nr_dentry(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) @@ -277,6 +283,7 @@ static inline int dentry_string_cmp(const unsigned char *cs, const unsigned char #endif +#ifdef CONFIG_DCACHE_LIMIT_NEG_ENTRY /* * Decrement negative dentry count if applicable. */ @@ -455,6 +462,26 @@ int proc_neg_dentry_pc(struct ctl_table *ctl, int write, return 0; } EXPORT_SYMBOL_GPL(proc_neg_dentry_pc); +#else /* CONFIG_DCACHE_LIMIT_NEG_ENTRY */ + +static inline void __neg_dentry_dec(struct dentry *dentry) +{ +} + +static inline void neg_dentry_dec(struct dentry *dentry) +{ +} + +static inline void __neg_dentry_inc(struct dentry *dentry, bool retain) +{ +} + +static inline void neg_dentry_inc(struct dentry *dentry) +{ +} + +#endif /* CONFIG_DCACHE_LIMIT_NEG_ENTRY */ + static inline int dentry_cmp(const struct dentry *dentry, const unsigned char *ct, unsigned tcount) { @@ -1485,6 +1512,7 @@ void shrink_dcache_sb(struct super_block *sb) } EXPORT_SYMBOL(shrink_dcache_sb); +#ifdef CONFIG_DCACHE_LIMIT_NEG_ENTRY /* * A modified version that attempts to remove a limited number of negative * dentries as well as some other non-negative dentries at the front. @@ -1639,6 +1667,7 @@ static void prune_negative_dentry(struct work_struct *work) deactivate_super(sb); WRITE_ONCE(ndblk.prune_sb, NULL); } +#endif /* CONFIG_DCACHE_LIMIT_NEG_ENTRY */ /** * enum d_walk_ret - action to talke during tree walk @@ -3576,7 +3605,9 @@ static void __init dcache_init(void) SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD|SLAB_ACCOUNT, d_iname); +#ifdef CONFIG_DCACHE_LIMIT_NEG_ENTRY raw_spin_lock_init(&ndblk.nfree_lock); +#endif /* Hash may have been set up in dcache_init_early */ if (!hashdist) diff --git a/include/linux/dcache.h b/include/linux/dcache.h index 71a3315..27ffc35 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -612,10 +612,12 @@ struct name_snapshot { void take_dentry_name_snapshot(struct name_snapshot *, struct dentry *); void release_dentry_name_snapshot(struct name_snapshot *); +#ifdef CONFIG_DCACHE_LIMIT_NEG_ENTRY /* * Negative dentry related declarations. */ extern int neg_dentry_pc; extern int neg_dentry_enforce; +#endif #endif /* __LINUX_DCACHE_H */ diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 8c008ae..875d5ef 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1852,6 +1852,7 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write, .proc_handler = proc_dointvec_minmax, .extra1 = &one, }, +#ifdef CONFIG_DCACHE_LIMIT_NEG_ENTRY { .procname = "neg-dentry-pc", .data = &neg_dentry_pc, @@ -1870,6 +1871,7 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write, .extra1 = &zero, .extra2 = &one, }, +#endif { } };