Return-Path: Received: from mx1.redhat.com ([209.132.183.28]:40448 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751177AbdH0PFg (ORCPT ); Sun, 27 Aug 2017 11:05:36 -0400 Subject: Re: [PATCH] fs/dcache: dentries should free after files unlinked or directories removed To: Linus Torvalds , "Wangkai (Kevin,C)" Cc: Jan Kara , "viro@zeniv.linux.org.uk" , "walters@verbum.org" , "linux-fsdevel@vger.kernel.org" , "Renjinyong (Renjinyong, Business Support Dept)" References: <1502099673-31620-1-git-send-email-wangkai86@huawei.com> <87B246BB5ED53A4C98E4F9A35839EDE18539C199@nkgeml514-mbx.china.huawei.com> <20170825144702.GB6758@quack2.suse.cz> <87B246BB5ED53A4C98E4F9A35839EDE18539D5EE@nkgeml514-mbx.china.huawei.com> From: Waiman Long Message-ID: Date: Sun, 27 Aug 2017 11:05:34 -0400 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Content-Language: en-US Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On 08/26/2017 12:18 PM, Linus Torvalds wrote: > On Fri, Aug 25, 2017 at 11:56 PM, Wangkai (Kevin,C) > wrote: >> but I am worried, if there are programs create,delete many temporary files and unique, >> the negative dentries will keep growing. > The thing is, this has nothing to do with unlink. > > The *easiest* way to generate negative dentries is in fact to never > create any files at all: just look up millions of non-existent names. > > IOW, just something like this > > #include > #include > #include > #include > > int main() > { > int i; > for (i = 0; i < 10000000; i++) { > char name[20]; > struct stat st; > > snprintf(name, sizeof(name), "n:%d", i); > stat(name, &st); > } > return 0; > } > > is a much easier and faster way to create negative dentries. > > And yes, it's entirely possible that we could/should have some way to > balance negative dentries against positive ones, but on the whole this > has not really come up as a huge problem. It is certainly true that the current scheme of unlimited negative dentry creation is not a problem under most cases. However, there are scenarios where it can be a problem. A customer discovered the negative dentry issue because of a bug in their application code. They fixed their code to solve the problem. However, they wondered if this could be used as one vector of a DoS attack on a Linux system by having a rogue program generate massive number of negative dentries continuously. It is the thought of this malicious use of the negative dentry behavior that prompted me to create and send out a patch to limit the number of negative dentries allowable in a system. Besides, Kevin had shown that keeping the dentry cache from growing too big was good for file lookup performance too. Cheers, Longman > For example, your module that does a lot of GFP_ATOMIC allocations - > if it wasn't for dentries, it would have been something else. > GFP_ATOMIC *will* fail after a while, because it just can't replenish > the free memory. That's fundamental. That's what GFP_ATOMIC _means_. > It's very much meant for "occasional critical allocations", and if you > do just GFP_ATOMIC, you will fail. > > Linus