Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp564830pxj; Fri, 11 Jun 2021 06:10:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKnFY7KqzdwSVW67ZHR4UJPWLKVoXdP5stelHp4TTu7jL/j/dYEWTwILITaLbiIH3a/RUw X-Received: by 2002:a17:907:10d8:: with SMTP id rv24mr3552297ejb.542.1623417047916; Fri, 11 Jun 2021 06:10:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623417047; cv=none; d=google.com; s=arc-20160816; b=IuYxs/X1HrVn7TOG1/2dJfg1SPRudAvGqpdunjXUrztA3w3l8BxeJaxLqdiE1cI4q5 arsVswNM3gz3/hdHlqsjGoegWqcRuhOtlUhbI2D2FpJ3DCls6vuTnk7FNBYWZ5gTq4Eb JvPC7XSsdp38Q4NLOZ7sYVukbdLVfwcqNt6HEKljCQG5X+lk1YN6pBumxVfhMtbSlJ5x xbycurRsbHOeT52QFDl70abjbuebMpkTBtmJobUA2O4bkvCIOcUpQmFI2ycVuUn+mqz9 /f1QMJIMKIqdWBwvFRjNgDszwsEpnXHLbtbsffRUIyjTywY/HWYYx7BA+SclF8dRTme8 TuvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Dx7GSd7iO7rvrKTCA9ogAPIg0Js8UGiEJvwjK+2gj2E=; b=qSLsD36Rod1eACCQC5P9niyMj4oPc0gqm5It1AsQZbPUAffvjBL4YewC+kuCzTjByu 6vTLg7yt0kWChZgqu02cQFSbtexWx5Vr8ABxAWiN6C72WqYIqu+7/gOVkxzciMfLxkfM MNl0hlkJvUb2NcCVM853j+fUpUZ00c4Us9LZkzamH7z+/J/U0QP5faxSlW+z25Kif/vx pDbQLVkFl3iCDH4l6rTWS9cB7MjNCU8RHMolsLbHaLliTA2P+YmttIKaqxIZCq7fY9gs wPp+sd+6T5UPZ7WxAUqpBezYoTjBY1sLNuoLRGYUYFvV8+kDrGu5/C9iu+35e7OTtnlY G3yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b=NUltRQ+k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ba17si4973406edb.400.2021.06.11.06.10.21; Fri, 11 Jun 2021 06:10:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b=NUltRQ+k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231357AbhFKNK3 (ORCPT + 99 others); Fri, 11 Jun 2021 09:10:29 -0400 Received: from mail-ua1-f41.google.com ([209.85.222.41]:37633 "EHLO mail-ua1-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229633AbhFKNK3 (ORCPT ); Fri, 11 Jun 2021 09:10:29 -0400 Received: by mail-ua1-f41.google.com with SMTP id f34so2552097uae.4 for ; Fri, 11 Jun 2021 06:08:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Dx7GSd7iO7rvrKTCA9ogAPIg0Js8UGiEJvwjK+2gj2E=; b=NUltRQ+kEMueiFZrkAI1RyPxI037UoOyBgAWAd6gcdZ2j+K8v9cJlDMq+yS9UtwnJ3 EAKCrAyHcVmEhH+75eyUO4RHk2+ONa9gGNpdTWoeNrtGbHE+L/swWqbccaSUbagssJUz yb3lco4g4ZRvwZK117eTEPuYhtCR/vWKec8pM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Dx7GSd7iO7rvrKTCA9ogAPIg0Js8UGiEJvwjK+2gj2E=; b=T5le6ieLk2SefHE5qA6nhDJlW0eG+I9/2gRMUCNMkKGcBX9oNu3ows36BHlqblb91g 2FzwHBl49WzgBpYqb0VK32Mx/l+EdjKCSp5DfaLvAR8GaKa0aWDUUC1QSVvK0/BI/MxX 6r4GzB++XbTM+9pxyFTU5OClz5IOQeoPbDqMT3vDHsGW8blwGgsnTQfUl7y89FSeyw3T bRDeGHSBggFcNPA1YXSOQAnqUdlnS6mLOmu9egxh/Tu8euLoImZjdyacTPVFcnaUyc0Q OvzOAyHh51KiZ5on/sBuSvTX4XLJo1ahi3gB1JsueY9C01ta/RcI/8XDRxZyhmLSMz0Z dMdA== X-Gm-Message-State: AOAM530uRY8fe4hnVEIgjW16jv7mHuvBsiS+Vda5Y/xkkVbCQdGqV8jr wmKy2ie1EcG86YC4tU8IacEJhqWR7cLQxKFZqvzsoA== X-Received: by 2002:ab0:6448:: with SMTP id j8mr2871941uap.13.1623416839332; Fri, 11 Jun 2021 06:07:19 -0700 (PDT) MIME-Version: 1.0 References: <162322846765.361452.17051755721944717990.stgit@web.messagingengine.com> <162322862726.361452.10114120072438540655.stgit@web.messagingengine.com> In-Reply-To: <162322862726.361452.10114120072438540655.stgit@web.messagingengine.com> From: Miklos Szeredi Date: Fri, 11 Jun 2021 15:07:08 +0200 Message-ID: Subject: Re: [PATCH v6 3/7] kernfs: use VFS negative dentry caching To: Ian Kent Cc: Greg Kroah-Hartman , Tejun Heo , Eric Sandeen , Fox Chen , Brice Goglin , Al Viro , Rick Lindsley , David Howells , Marcelo Tosatti , "Eric W. Biederman" , Carlos Maiolino , linux-fsdevel , Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 9 Jun 2021 at 10:50, Ian Kent wrote: > > If there are many lookups for non-existent paths these negative lookups > can lead to a lot of overhead during path walks. > > The VFS allows dentries to be created as negative and hashed, and caches > them so they can be used to reduce the fairly high overhead alloc/free > cycle that occurs during these lookups. > > Use the kernfs node parent revision to identify if a change has been > made to the containing directory so that the negative dentry can be > discarded and the lookup redone. > > Signed-off-by: Ian Kent > --- > fs/kernfs/dir.c | 52 ++++++++++++++++++++++++++++++++-------------------- > 1 file changed, 32 insertions(+), 20 deletions(-) > > diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c > index b3d1bc0f317d0..4f037456a8e17 100644 > --- a/fs/kernfs/dir.c > +++ b/fs/kernfs/dir.c > @@ -1039,9 +1039,28 @@ static int kernfs_dop_revalidate(struct dentry *dentry, unsigned int flags) > if (flags & LOOKUP_RCU) > return -ECHILD; > > - /* Always perform fresh lookup for negatives */ > - if (d_really_is_negative(dentry)) > - goto out_bad_unlocked; > + /* Negative hashed dentry? */ > + if (d_really_is_negative(dentry)) { > + struct dentry *d_parent = dget_parent(dentry); > + struct kernfs_node *parent; > + > + /* If the kernfs parent node has changed discard and > + * proceed to ->lookup. > + */ > + parent = kernfs_dentry_node(d_parent); > + if (parent) { > + if (kernfs_dir_changed(parent, dentry)) { Perhaps add a note about this being dependent on parent of a negative dentry never changing. If this was backported to a kernel where this assumption doesn't hold, there would be a mathematical chance of a false negative. Thanks, Miklos