From patchwork Thu Jul 12 16:46:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 10521933 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 80F06601C2 for ; Thu, 12 Jul 2018 16:47:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CD3C29810 for ; Thu, 12 Jul 2018 16:47:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 60D6829A38; Thu, 12 Jul 2018 16:47:23 +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 D4CF429A19 for ; Thu, 12 Jul 2018 16:47:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6805C6B026E; Thu, 12 Jul 2018 12:47:07 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5D6F56B0270; Thu, 12 Jul 2018 12:47:07 -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 23F7D6B0271; Thu, 12 Jul 2018 12:47:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f198.google.com (mail-qt0-f198.google.com [209.85.216.198]) by kanga.kvack.org (Postfix) with ESMTP id D11146B026F for ; Thu, 12 Jul 2018 12:47:06 -0400 (EDT) Received: by mail-qt0-f198.google.com with SMTP id 13-v6so30232326qtt.7 for ; Thu, 12 Jul 2018 09:47:06 -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=rX8fSq2DOmBPWypnGTgFg0GdXwtf73dp7CAh8vtsYc4=; b=Mi2i8RAjXMy/ZVxP374496cuDEcO4QU4IXT2B2+ENwRmTRSHw4yvALf2pHPtMi8U0M bvuZ1r2d/NZmK9u8VuSEXXUWgPyPt3797yxkjUWmzYOEnJRKLXhHsXiqcYCYiQ6WmMf8 RIHG59j3OyNx77GsTRaWSiRFQ55+uOFOXR7IWLjERxJiPFFdeyd2g6jPNUbWCG1s7bib 7XIpvUPvjtjK3zVDnCUK295AAHRWTAzwfqWvlPoj1Fuw/x/gNdLri4n1GtX51FIEQNJg n4x8e4MRLKogkfgOqZCgIj61KyaABCOizCTITXd7bpSjF3h8tS/Y3aIfxy1Vu7tK/+16 q1fw== 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: AOUpUlFYUJqUSJYFZLV6kE6Y9dShpg6tEGLQLeeL9MQDdhtoNeWJ0qj9 QE8Ilz/GAJF9EpW7TTDe8MVnFRpc2Mg3mQLlXW7RVcZB6wK87yGWWyyKVbFVGuADVZfMk1DYJts WjagC7He1gf8H+WeUlm3x0wypPEmbt/0WYFIczmcSUP8Sf6ONXmORdggYMoC6mFKINQ== X-Received: by 2002:a0c:e60e:: with SMTP id z14-v6mr3287890qvm.244.1531414026636; Thu, 12 Jul 2018 09:47:06 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdFQw8khUNe4s3ZHgiY8+SaFFOYgN7SWKvQW+NlqkaO0YB81K+aa/PUXnpaN0mwvZwKEFKO X-Received: by 2002:a0c:e60e:: with SMTP id z14-v6mr3287851qvm.244.1531414025983; Thu, 12 Jul 2018 09:47:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531414025; cv=none; d=google.com; s=arc-20160816; b=UEn8CmF3J8x3FZiGJOeWzAp8TYokJ87qi9aZuxMDq1EjKKkInDOBrI6MFmsQ/aPH3a Ltcs6hJKfiScw0j/+H1G4a1FPHKyNpRb0AlP8SVUPNILDUkOe2MIcxYye4lNSawgR/Bl 9VOHM2QC751ShAMl8mfdbyQukzm8eiFk4LG50m76LAgOK743f4TXi3x2oAKa2GJk/oDG uW5mgZLeNhtF4B0MicbZ0Jyi6GyoItxaLXrDRUQWb346Q4q+581PrXmB0sJ3ohBkz+el dObbBEUXtpe0XyyzQKFCu/N0SjK/oE9hD4vLvA2Ga468BGzLjwdgdEmx3/ClCfxDM9UY mAmw== 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=rX8fSq2DOmBPWypnGTgFg0GdXwtf73dp7CAh8vtsYc4=; b=BU+F4ZWn941JywiG1qyZsrJsPpyBO38lBgRN43xSRjLPtv2BbyXfwWkFLtiLAlYTIw 3BqvbWHvXLgQYfWsCUFRwuCjCSQCIu887riVgkcn+sCdL4wA/hZDxqiIBXQx48vzY5c1 5D1dClueHXJFIp+GmVZLKG0Zuqf08bfuGZn4Hfw3FuZ/NzYKjHhjaG3xClrNAXQ2TluT tmgp4oMyqt1QYT6W6EkNzAtWjK19ElILtje0ZOisgqOFA1+9kX2N29nuX2Vdph6L9F7s cXiGy1Dtr7ka9S7opVAMBH1UInzdIDkrqdk98mjA2donF0nsaH0qzqgSy1kBsnROJaT2 mkOg== 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 u42-v6si9899373qth.262.2018.07.12.09.47.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jul 2018 09:47:05 -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 7DDCF818F042; Thu, 12 Jul 2018 16:47:05 +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 08C0F1C677; Thu, 12 Jul 2018 16:47:05 +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)" , Michal Hocko , Waiman Long Subject: [PATCH v7 6/6] fs/dcache: Allow deconfiguration of negative dentry code to reduce kernel size Date: Thu, 12 Jul 2018 12:46:05 -0400 Message-Id: <1531413965-5401-7-git-send-email-longman@redhat.com> In-Reply-To: <1531413965-5401-1-git-send-email-longman@redhat.com> References: <1531413965-5401-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.8]); Thu, 12 Jul 2018 16:47:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 12 Jul 2018 16:47:05 +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 limiting code can be configured out, if necessary. Signed-off-by: Waiman Long --- fs/Kconfig | 10 ++++++++++ fs/dcache.c | 29 +++++++++++++++++++++++------ include/linux/dcache.h | 2 ++ kernel/sysctl.c | 2 ++ 4 files changed, 37 insertions(+), 6 deletions(-) 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 843c8be..dccfe39 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -141,6 +141,7 @@ struct dentry_stat_t dentry_stat = { #define NEG_DENTRY_BATCH (1 << 8) #define NEG_WARN_PERIOD (60 * HZ) /* Print a warning every min */ +#ifdef CONFIG_DCACHE_LIMIT_NEG_ENTRY static struct static_key limit_neg_key = STATIC_KEY_INIT_FALSE; static int neg_dentry_limit_old; int neg_dentry_limit; @@ -156,6 +157,7 @@ struct dentry_stat_t dentry_stat = { unsigned long warn_jiffies; /* Time when last warning is printed */ } ndblk ____cacheline_aligned_in_smp; proc_handler proc_neg_dentry_limit; +#endif /* CONFIG_DCACHE_LIMIT_NEG_ENTRY */ static DEFINE_PER_CPU(long, nr_dentry); static DEFINE_PER_CPU(long, nr_dentry_unused); @@ -200,7 +202,9 @@ static long get_nr_dentry_neg(void) for_each_possible_cpu(i) sum += per_cpu(nr_dentry_neg, i); +#ifdef CONFIG_DCACHE_LIMIT_NEG_ENTRY sum += neg_dentry_nfree_init - ndblk.nfree; +#endif return sum < 0 ? 0 : sum; } @@ -267,6 +271,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. */ @@ -289,12 +294,6 @@ static void __neg_dentry_dec(struct dentry *dentry) } } -static inline void neg_dentry_dec(struct dentry *dentry) -{ - if (unlikely(d_is_negative(dentry))) - __neg_dentry_dec(dentry); -} - /* * Try to decrement the negative dentry free pool by NEG_DENTRY_BATCH. * The actual decrement returned by the function may be smaller. @@ -454,6 +453,20 @@ int proc_neg_dentry_limit(struct ctl_table *ctl, int write, return 0; } EXPORT_SYMBOL_GPL(proc_neg_dentry_limit); +#else /* CONFIG_DCACHE_LIMIT_NEG_ENTRY */ + +static inline void __neg_dentry_dec(struct dentry *dentry) +{ + this_cpu_dec(nr_dentry_neg); +} + +#endif /* CONFIG_DCACHE_LIMIT_NEG_ENTRY */ + +static inline void neg_dentry_dec(struct dentry *dentry) +{ + if (unlikely(d_is_negative(dentry))) + __neg_dentry_dec(dentry); +} static inline int dentry_cmp(const struct dentry *dentry, const unsigned char *ct, unsigned tcount) { @@ -642,6 +655,7 @@ static void d_lru_add(struct dentry *dentry) dentry->d_flags |= DCACHE_LRU_LIST; this_cpu_inc(nr_dentry_unused); if (d_is_negative(dentry)) { +#ifdef CONFIG_DCACHE_LIMIT_NEG_ENTRY if (dentry->d_flags & DCACHE_NEW_NEGATIVE) { dentry->d_flags &= ~DCACHE_NEW_NEGATIVE; if (unlikely(neg_dentry_inc(dentry) < 0)) { @@ -658,6 +672,7 @@ static void d_lru_add(struct dentry *dentry) &dentry->d_sb->s_dentry_lru, &dentry->d_lru)); return; } +#endif /* * We don't do limit check for existing negative * dentries. @@ -3431,7 +3446,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 934a6d9..11729a1 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_limit; extern int neg_dentry_enforce; +#endif #endif /* __LINUX_DCACHE_H */ diff --git a/kernel/sysctl.c b/kernel/sysctl.c index a24101e..732c624 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1851,6 +1851,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-limit", .data = &neg_dentry_limit, @@ -1869,6 +1870,7 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write, .extra1 = &zero, .extra2 = &one, }, +#endif { } };