Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp11444ybj; Fri, 8 May 2020 05:27:24 -0700 (PDT) X-Google-Smtp-Source: APiQypJ0jtjqMbXTKXHpkaEpU1mfgemgdtXSdxXwGWRonAivFi/55UMiTlhNw0+oBC2w57C1FFAA X-Received: by 2002:aa7:d5d4:: with SMTP id d20mr1949242eds.369.1588940844098; Fri, 08 May 2020 05:27:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588940844; cv=none; d=google.com; s=arc-20160816; b=k1VV2Z/74A2m/+wSLAnhZH+dPQ+D7+PnP/Ks8yAPrjZDBg9oyL6HoIJq3hw+aHVS5r 0riWj9KVAfNsFFZML+eHZjlSEX4v0AiVQonjbHhWuCsAnLx0lJiMz5jS4DBob/2gwp0D 6t4lVyAMB+6w86VG760ywjvkyNODXL0OdwVdFs6H2M4KINZWU8TfnJSCkPyETVTADKpd NPoGDmWF59El2etPKB0zxcbhYoLQCNf2LzfQ0eyheBrV9vrWwvqBpvT85bwU5YGz2Oyx 6SjbLQMezR1wmLJLO7Pdo3zlCHcMGkjan8kIa40aYJeRetB/b9mTT8+EyoybTW0zecOq w7KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:dkim-signature; bh=fE5H5nxfbTVPsDYqy95Pi0qrqxG0n44r6YkokVlYuxs=; b=ytwOPXPaf01Y7pn/TMV9nzMjJ6rfltOp5e4EPg0eCDK6J5HiCEznSFxbKNbR8vE1M/ qWwRg5bUkG+52O2K5LcxwnNQdSpD4BT8uXlq86j6NKPwoVo7u4mnGXmhqQKHdXDabkrW rAjLtfy0gdcbJ93I3qD/UGXGN2KexpKaI4wV+RQlQmvggN9QpHyJ0Mr7YnK1zEV3ZaSh 6dQgO9LpyFV2X5/hZW6D3uByLCMTiMovCpXxL15rzMmgFPYTQVJNQMYqr2bQk0Ctv7B+ +R5oOb2bRfqI3w4J730EhTveeBdDcydFbNjPLp8TBrjelUQ+D/XItikq7daErCAyeYFg WaSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=H0viADmU; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p25si885692eji.408.2020.05.08.05.26.59; Fri, 08 May 2020 05:27:24 -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=pass header.i=@yandex-team.ru header.s=default header.b=H0viADmU; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727117AbgEHMX2 (ORCPT + 99 others); Fri, 8 May 2020 08:23:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727094AbgEHMXZ (ORCPT ); Fri, 8 May 2020 08:23:25 -0400 Received: from forwardcorp1j.mail.yandex.net (forwardcorp1j.mail.yandex.net [IPv6:2a02:6b8:0:1619::183]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B10DC05BD43 for ; Fri, 8 May 2020 05:23:25 -0700 (PDT) Received: from mxbackcorp1g.mail.yandex.net (mxbackcorp1g.mail.yandex.net [IPv6:2a02:6b8:0:1402::301]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id 38F662E0DD7; Fri, 8 May 2020 15:23:24 +0300 (MSK) Received: from myt5-70c90f7d6d7d.qloud-c.yandex.net (myt5-70c90f7d6d7d.qloud-c.yandex.net [2a02:6b8:c12:3e2c:0:640:70c9:f7d]) by mxbackcorp1g.mail.yandex.net (mxbackcorp/Yandex) with ESMTP id CwfcYZS86f-NNAWclZ0; Fri, 08 May 2020 15:23:24 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1588940604; bh=fE5H5nxfbTVPsDYqy95Pi0qrqxG0n44r6YkokVlYuxs=; h=In-Reply-To:Message-ID:References:Date:To:From:Subject:Cc; b=H0viADmU8Q1pZpdoq3gUEj+1k51lST+hEaXaQzaspjNPreBUobGD5qFJJFWjDTZGp qlxY2mfOF2tOueZPJ4/OWPOMlUWZTHdSiJAtumhD0dek8Lrtd2BO77fiuVy2fciQPS vEFgofTlKQcoOtSbRFNqyibCu/ALHX0go6vjdkiE= Authentication-Results: mxbackcorp1g.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from dynamic-vpn.dhcp.yndx.net (dynamic-vpn.dhcp.yndx.net [2a02:6b8:b080:7008::1:4]) by myt5-70c90f7d6d7d.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id fhizLjzH9z-NNWe0AWK; Fri, 08 May 2020 15:23:23 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) Subject: [PATCH RFC 4/8] fsnotify: stop walking child dentries if remaining tail is negative From: Konstantin Khlebnikov To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Alexander Viro Cc: Waiman Long Date: Fri, 08 May 2020 15:23:23 +0300 Message-ID: <158894060308.200862.2000400345829882905.stgit@buzz> In-Reply-To: <158893941613.200862.4094521350329937435.stgit@buzz> References: <158893941613.200862.4094521350329937435.stgit@buzz> User-Agent: StGit/0.22-32-g6a05 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When notification starts/stops listening events from inode's children it have to update dentry->d_flags of all positive child dentries. Scanning may took a long time if directory has a lot of negative child dentries. This is main beneficiary of sweeping cached negative dentries to the end. Before patch: nr_dentry = 24172597 24.2M nr_buckets = 8388608 2.9 avg nr_unused = 24158110 99.9% nr_negative = 24142810 99.9% inotify time: 0.507182 seconds After patch: nr_dentry = 24562747 24.6M nr_buckets = 8388608 2.9 avg nr_unused = 24548714 99.9% nr_negative = 24543867 99.9% inotify time: 0.000010 seconds Negative dentries no longer slow down inotify op at parent directory. Signed-off-by: Konstantin Khlebnikov --- fs/notify/fsnotify.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 72d332ce8e12..072974302950 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -127,8 +127,12 @@ void __fsnotify_update_child_dentry_flags(struct inode *inode) * original inode) */ spin_lock(&alias->d_lock); list_for_each_entry(child, &alias->d_subdirs, d_child) { - if (!child->d_inode) + if (!child->d_inode) { + /* all remaining children are negative */ + if (d_is_tail_negative(child)) + break; continue; + } spin_lock_nested(&child->d_lock, DENTRY_D_LOCK_NESTED); if (watched)