From patchwork Tue Aug 3 18:03:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12416975 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5790C432BE for ; Tue, 3 Aug 2021 18:04:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A7FF961037 for ; Tue, 3 Aug 2021 18:04:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238588AbhHCSEP (ORCPT ); Tue, 3 Aug 2021 14:04:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238617AbhHCSEO (ORCPT ); Tue, 3 Aug 2021 14:04:14 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F7BBC061764 for ; Tue, 3 Aug 2021 11:04:02 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id c16so26221204wrp.13 for ; Tue, 03 Aug 2021 11:04:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DpbNU57dwIf0j8e6Vnow4rtXZ0Erpq3Ug+gPGUYekgM=; b=MY5QZ0oTxgwZ18rUI4C7T8SLOrpPpSvU3H6AGy76n0IFvLBIX2aX3YnDE2Kpe8hdOw ljdHt3msI/aJ8g9do3YLlEvrOhMKv+fOFpscTnKo8NjMTan86QlLyxwDuPPH5UrbX5Dt qmxa79Nrp3Xy64FTTeQ+BSv1nl5BmUDiECpgJG27QEAB9Hw++CyqnCPKehQayY8OpSCs JZEwCl8ZvenVKtqhExEttQTzF71l8fJsZ5bTWf971UInnR2GPLifMDiaGQW0CcCSpVRh VOPaaGV0bOhcLpmwrMXT6UuEU/72kXp6cFhsReN6RsA5w2ZoIvVbRoW8jsgRjzfPe5Kv M2cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DpbNU57dwIf0j8e6Vnow4rtXZ0Erpq3Ug+gPGUYekgM=; b=KdGJ9/J9UZY0XhyD4MnVliPZmfYe1jbYwx06JiQIH+3nJeZGhe5q7R0oignKhnUwLR GNzwRa37M+W9Ptno7qwWdv6hX0udE8caQL4Q2TIT+p3sQv4zVaJT9YdOgLgxu0xlj3i4 2WwTLlA4xImJ7VumPVcHMKT3s4JZrEuov1ApZNyShtlvNWLBKhrA6qATMndzgAXcRym3 S4Ndd9BoDCyW4CWcTz2N2suziX8HmOuSSQG2Ym6oLpDmNU3IDiz1hD57BmOMLH3eWmit fMgT8jT91f5m9KHWPY+kiqzFz4LKF2LpCnX3yGRUdWyt8J32+KWnqQK8RT+I/JnKc9nx 7Iig== X-Gm-Message-State: AOAM5306Nrq7N0SxjpiZjXPVoE0fDMDuUGMb/uvvQW6wzN+OajyYlx1J dD4/7qpQZrC4NZu1XnNpGso41+BktTU= X-Google-Smtp-Source: ABdhPJyu32Zb0kAJUt9f2clJ17JJ6Tp8wVUQW4JvcDVdjH2+feaGm29DzDonvnbN1vFgp1k12/guLA== X-Received: by 2002:a5d:5987:: with SMTP id n7mr8649927wri.260.1628013840652; Tue, 03 Aug 2021 11:04:00 -0700 (PDT) Received: from localhost.localdomain ([185.110.110.213]) by smtp.gmail.com with ESMTPSA id b14sm15515555wrm.43.2021.08.03.11.03.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 11:04:00 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH 1/4] fsnotify: replace igrab() with ihold() on attach connector Date: Tue, 3 Aug 2021 21:03:41 +0300 Message-Id: <20210803180344.2398374-2-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210803180344.2398374-1-amir73il@gmail.com> References: <20210803180344.2398374-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org We must have a reference on inode, so ihold is cheaper. Signed-off-by: Amir Goldstein Reviewed-by: Matthew Bobrowski --- fs/notify/mark.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/notify/mark.c b/fs/notify/mark.c index d32ab349db74..80459db58f63 100644 --- a/fs/notify/mark.c +++ b/fs/notify/mark.c @@ -493,8 +493,11 @@ static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp, conn->fsid.val[0] = conn->fsid.val[1] = 0; conn->flags = 0; } - if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) - inode = igrab(fsnotify_conn_inode(conn)); + if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) { + inode = fsnotify_conn_inode(conn); + ihold(inode); + } + /* * cmpxchg() provides the barrier so that readers of *connp can see * only initialized structure From patchwork Tue Aug 3 18:03:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12416977 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0376AC4320A for ; Tue, 3 Aug 2021 18:04:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DF62861037 for ; Tue, 3 Aug 2021 18:04:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238626AbhHCSEP (ORCPT ); Tue, 3 Aug 2021 14:04:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238624AbhHCSEO (ORCPT ); Tue, 3 Aug 2021 14:04:14 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44087C061757 for ; Tue, 3 Aug 2021 11:04:03 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id n28-20020a05600c3b9cb02902552e60df56so2674597wms.0 for ; Tue, 03 Aug 2021 11:04:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VgPb9kmai7KZaL+bLbc2JstMQjeBUpDeYZiCnA5QgkE=; b=scJ9Z4Kqjoz9+BDu8mO/XxgIwOkhsRSc5lkPYAQgu+PN0tsfGDyI7P28GkuEUjF/te YkRdP+ENLL8g9OV9hoPF2BmR8k4rQtvQe/JbL81QAHCFJtRDAvIcFG3P1/MxnvNK6JkG hi1uNcw8NTpECStrgzW+u6cKU78ve2FUNl0vPpmjUIgSE18eStinSQbLTzWwDt8ca1gr If8ohPPnGxdboj+P3pVZ13isrrxsYGqON+wGwGuRS8LwquQmEBUquOL66Zdu/S2CMsFD 9MfnuttI2HhS8Khbc1jpMDq8YO7JZkzmcpG8twEWc0sW+xDnbAXQjekxEjHpLtiKIK0p AOSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VgPb9kmai7KZaL+bLbc2JstMQjeBUpDeYZiCnA5QgkE=; b=YwiDF8gSreCV48GAozPUDaWm7qP1LDaNKYTWmUqIbZ6GIWPCyAccCrMEugQykkc1ti zqM9HbpXQSKK1itkU3uAXK7NmQEs5PWIw2UcHAVlzr+7Peqpx1WzRg2YyvJqaWQ15VqG 1CZvsxCNHHmDsM40quonpGL94bA4IJbsOp5a2woXV8/UyvkF597AnAEXcr0OPOyv5mJr dTGl99XqPrq89jquUm/DO+e5dbW4F+cbn2TbnW46wCKll6HbAfLd7HhZ1zGE5Z5NDEY5 WsccFf/BweqAbJ5fQgnwjbC02WYOm1mKVyzf4tpfHRllcJQ6ZFh6IZfOBj1Dv8NJsNzT Z87A== X-Gm-Message-State: AOAM531avRyMfiKQffkEqYsG8GneoKprpd7+409s3cqhAehX8HWyc0zN lHRi3+1CBKak8xaJJ2KUKGw= X-Google-Smtp-Source: ABdhPJwS5BAuyNreiYXP+2l4GAz5Fj54ZiXwfRhxJ1wsaqjINLMifW4Ik9Jk1EOmFkQMhdmeu9oKcg== X-Received: by 2002:a1c:3886:: with SMTP id f128mr5680592wma.85.1628013841871; Tue, 03 Aug 2021 11:04:01 -0700 (PDT) Received: from localhost.localdomain ([185.110.110.213]) by smtp.gmail.com with ESMTPSA id b14sm15515555wrm.43.2021.08.03.11.04.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 11:04:01 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH 2/4] fsnotify: count s_fsnotify_inode_refs for attached connectors Date: Tue, 3 Aug 2021 21:03:42 +0300 Message-Id: <20210803180344.2398374-3-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210803180344.2398374-1-amir73il@gmail.com> References: <20210803180344.2398374-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Instead of incrementing s_fsnotify_inode_refs when detaching connector from inode, increment it earlier when attaching connector to inode. Next patch is going to use s_fsnotify_inode_refs to count all objects with attached connectors. Signed-off-by: Amir Goldstein Reviewed-by: Matthew Bobrowski --- fs/notify/mark.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/fs/notify/mark.c b/fs/notify/mark.c index 80459db58f63..2d8c46e1167d 100644 --- a/fs/notify/mark.c +++ b/fs/notify/mark.c @@ -169,6 +169,21 @@ static void fsnotify_connector_destroy_workfn(struct work_struct *work) } } +static void fsnotify_get_inode_ref(struct inode *inode) +{ + ihold(inode); + atomic_long_inc(&inode->i_sb->s_fsnotify_inode_refs); +} + +static void fsnotify_put_inode_ref(struct inode *inode) +{ + struct super_block *sb = inode->i_sb; + + iput(inode); + if (atomic_long_dec_and_test(&sb->s_fsnotify_inode_refs)) + wake_up_var(&sb->s_fsnotify_inode_refs); +} + static void *fsnotify_detach_connector_from_object( struct fsnotify_mark_connector *conn, unsigned int *type) @@ -182,7 +197,6 @@ static void *fsnotify_detach_connector_from_object( if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) { inode = fsnotify_conn_inode(conn); inode->i_fsnotify_mask = 0; - atomic_long_inc(&inode->i_sb->s_fsnotify_inode_refs); } else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) { fsnotify_conn_mount(conn)->mnt_fsnotify_mask = 0; } else if (conn->type == FSNOTIFY_OBJ_TYPE_SB) { @@ -209,19 +223,12 @@ static void fsnotify_final_mark_destroy(struct fsnotify_mark *mark) /* Drop object reference originally held by a connector */ static void fsnotify_drop_object(unsigned int type, void *objp) { - struct inode *inode; - struct super_block *sb; - if (!objp) return; /* Currently only inode references are passed to be dropped */ if (WARN_ON_ONCE(type != FSNOTIFY_OBJ_TYPE_INODE)) return; - inode = objp; - sb = inode->i_sb; - iput(inode); - if (atomic_long_dec_and_test(&sb->s_fsnotify_inode_refs)) - wake_up_var(&sb->s_fsnotify_inode_refs); + fsnotify_put_inode_ref(objp); } void fsnotify_put_mark(struct fsnotify_mark *mark) @@ -495,7 +502,7 @@ static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp, } if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) { inode = fsnotify_conn_inode(conn); - ihold(inode); + fsnotify_get_inode_ref(inode); } /* @@ -505,7 +512,7 @@ static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp, if (cmpxchg(connp, NULL, conn)) { /* Someone else created list structure for us */ if (inode) - iput(inode); + fsnotify_put_inode_ref(inode); kmem_cache_free(fsnotify_mark_connector_cachep, conn); } From patchwork Tue Aug 3 18:03:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12416979 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26C70C4338F for ; Tue, 3 Aug 2021 18:04:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 100A16103C for ; Tue, 3 Aug 2021 18:04:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238634AbhHCSER (ORCPT ); Tue, 3 Aug 2021 14:04:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238624AbhHCSEQ (ORCPT ); Tue, 3 Aug 2021 14:04:16 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5ACF0C061757 for ; Tue, 3 Aug 2021 11:04:04 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id b13so15376183wrs.3 for ; Tue, 03 Aug 2021 11:04:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4GqhhvIv2GMHlPXgTIr4wx/CDKhM0RPHwwCAsHPU1So=; b=aXEnIKydC1M2eUtIbzWMV5fTDrSlQBxIWhYSnBMNMyPSPkiNFh2WdP7DavDCodTGT4 izAXuSXzIN/AO9apJMo+PQ2KQ18TMGgbHOmeFItleqo4ndVvgEcv/lP/OkV5nuZHSKBY JuR79kZip+fdtdGqTgKQFq8CEkQnBNLgccGwDaFe0x7frKPf/enMV5r4Znqf2cjjtrGX A8XZsPEU2aAVp40nD2k64kIpP1Dq9xPDNVxd8cEjjw3D81UOfZlZJbEcnyLpWtwkxKQ2 mmW04YpMexQYie9jo8yJeG7nzjiwc+m3jAHjj+hFOb1shORq1LH7vTulbHx7wPtTgz5X 20sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4GqhhvIv2GMHlPXgTIr4wx/CDKhM0RPHwwCAsHPU1So=; b=gqkI4KjA1WzkYiz47Dc1aXxgTYXYB0qr/P4LVL4X/J9zdFylayNbkmfN2V54cOE44U ZUgUzeMxGxxL9ymovu1HbbM8mwSnd8syV+X6X0IULyYpzAbqqDCaVPUzNaXuQm30bGYQ VqPQWt9boRuc/2RqJNviHMklsC3HVVYEIrQqxyeoSS6tJc3vKCvBhRH6UrgYaGgDxj/7 0aL0SWGF/6PVR14IwmGhbm1K3M5DOlH8aaWniUqTpm+xt0jw4jmPB/dbxJ7Kbf0F4Ds0 eoxPdwytIfPEZqg2OR7DV2K2HGpF3VXJc9IZYeRgbNuwClcXW5GpNaE4ZxCgEFq+6rNm rjig== X-Gm-Message-State: AOAM530d/1TzZW/80wPYBUdjyqdnh+Vp/2ZlkyL3Utcysu1exiLz7Ncm fMDtm0dFgL4bjm5Dd5C2pv8= X-Google-Smtp-Source: ABdhPJw48vqVkTqtNb2No5lEFdG2hMqCX6FzY2NZw/lYolqPoogmezzWClojjOXaMqITKC179rbUUw== X-Received: by 2002:a5d:4207:: with SMTP id n7mr24358387wrq.326.1628013842954; Tue, 03 Aug 2021 11:04:02 -0700 (PDT) Received: from localhost.localdomain ([185.110.110.213]) by smtp.gmail.com with ESMTPSA id b14sm15515555wrm.43.2021.08.03.11.04.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 11:04:02 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH 3/4] fsnotify: count all objects with attached connectors Date: Tue, 3 Aug 2021 21:03:43 +0300 Message-Id: <20210803180344.2398374-4-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210803180344.2398374-1-amir73il@gmail.com> References: <20210803180344.2398374-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Rename s_fsnotify_inode_refs to s_fsnotify_conectors and count all objects with attached connectors, not only inodes with attached connectors. This will be used to optimize fsnotify() calls on sb without any type of marks. Signed-off-by: Amir Goldstein --- fs/notify/fsnotify.c | 6 +++--- fs/notify/mark.c | 45 +++++++++++++++++++++++++++++++++++++++++--- include/linux/fs.h | 4 ++-- 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 30d422b8c0fc..a5de7f32c493 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -87,9 +87,9 @@ static void fsnotify_unmount_inodes(struct super_block *sb) if (iput_inode) iput(iput_inode); - /* Wait for outstanding inode references from connectors */ - wait_var_event(&sb->s_fsnotify_inode_refs, - !atomic_long_read(&sb->s_fsnotify_inode_refs)); + /* Wait for outstanding object references from connectors */ + wait_var_event(&sb->s_fsnotify_connectors, + !atomic_long_read(&sb->s_fsnotify_connectors)); } void fsnotify_sb_delete(struct super_block *sb) diff --git a/fs/notify/mark.c b/fs/notify/mark.c index 2d8c46e1167d..622bcbface4f 100644 --- a/fs/notify/mark.c +++ b/fs/notify/mark.c @@ -172,7 +172,7 @@ static void fsnotify_connector_destroy_workfn(struct work_struct *work) static void fsnotify_get_inode_ref(struct inode *inode) { ihold(inode); - atomic_long_inc(&inode->i_sb->s_fsnotify_inode_refs); + atomic_long_inc(&inode->i_sb->s_fsnotify_connectors); } static void fsnotify_put_inode_ref(struct inode *inode) @@ -180,8 +180,45 @@ static void fsnotify_put_inode_ref(struct inode *inode) struct super_block *sb = inode->i_sb; iput(inode); - if (atomic_long_dec_and_test(&sb->s_fsnotify_inode_refs)) - wake_up_var(&sb->s_fsnotify_inode_refs); + if (atomic_long_dec_and_test(&sb->s_fsnotify_connectors)) + wake_up_var(&sb->s_fsnotify_connectors); +} + +static void fsnotify_get_sb_connectors(struct fsnotify_mark_connector *conn) +{ + struct super_block *sb; + + if (conn->type == FSNOTIFY_OBJ_TYPE_DETACHED) + return; + + if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) + sb = fsnotify_conn_inode(conn)->i_sb; + else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) + sb = fsnotify_conn_mount(conn)->mnt.mnt_sb; + else if (conn->type == FSNOTIFY_OBJ_TYPE_SB) + sb = fsnotify_conn_sb(conn); + + atomic_long_inc(&sb->s_fsnotify_connectors); +} + +static void fsnotify_put_sb_connectors(struct fsnotify_mark_connector *conn) +{ + struct super_block *sb; + + if (conn->type == FSNOTIFY_OBJ_TYPE_DETACHED) + return; + + if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) + sb = fsnotify_conn_inode(conn)->i_sb; + else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) + sb = fsnotify_conn_mount(conn)->mnt.mnt_sb; + else if (conn->type == FSNOTIFY_OBJ_TYPE_SB) + sb = fsnotify_conn_sb(conn); + else + return; + + if (atomic_long_dec_and_test(&sb->s_fsnotify_connectors)) + wake_up_var(&sb->s_fsnotify_connectors); } static void *fsnotify_detach_connector_from_object( @@ -203,6 +240,7 @@ static void *fsnotify_detach_connector_from_object( fsnotify_conn_sb(conn)->s_fsnotify_mask = 0; } + fsnotify_put_sb_connectors(conn); rcu_assign_pointer(*(conn->obj), NULL); conn->obj = NULL; conn->type = FSNOTIFY_OBJ_TYPE_DETACHED; @@ -504,6 +542,7 @@ static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp, inode = fsnotify_conn_inode(conn); fsnotify_get_inode_ref(inode); } + fsnotify_get_sb_connectors(conn); /* * cmpxchg() provides the barrier so that readers of *connp can see diff --git a/include/linux/fs.h b/include/linux/fs.h index 640574294216..d48d2018dfa4 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1507,8 +1507,8 @@ struct super_block { /* Number of inodes with nlink == 0 but still referenced */ atomic_long_t s_remove_count; - /* Pending fsnotify inode refs */ - atomic_long_t s_fsnotify_inode_refs; + /* Number of inode/mount/sb objects that are being watched */ + atomic_long_t s_fsnotify_connectors; /* Being remounted read-only */ int s_readonly_remount; From patchwork Tue Aug 3 18:03:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12416981 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7584FC4320A for ; Tue, 3 Aug 2021 18:04:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5889B61037 for ; Tue, 3 Aug 2021 18:04:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238638AbhHCSER (ORCPT ); Tue, 3 Aug 2021 14:04:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238628AbhHCSER (ORCPT ); Tue, 3 Aug 2021 14:04:17 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53A8BC06175F for ; Tue, 3 Aug 2021 11:04:05 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id h14so26218658wrx.10 for ; Tue, 03 Aug 2021 11:04:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pi1UXkTQldERNML991jYDsPgWN1vYpM8GjLB7gfzc1E=; b=K8HR+dehCQLfMWVbgpOXAwZzR9jl0or7LFqyt8BEGPHsBv4hPgHGU/ZvsIHS/sFaaf Htq7b+CtfBMd1JcOGpyhgumXlWapNrJELVOGQpIVTtxAlzLtIkRrxgrdwkxQ45wt5loh eM29eoG+f2uncAgpewtXpgb2fD1+1gMLJR+z1o+jaM5E4MvN76Ct3prmEguZucRvVA8g L5IkBY1k/hAiacpbI4VgtM4uZRjT+9qDWpx40UhbLHncC8qPWm1JFw44RnYVK5cyWeJS 4sS/qltssXTiLlkZcne6Z1g+np1LmCY2ajOlqe9w9R3apZNKsjW2/GwF272QpbSQ7Pu/ kzOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pi1UXkTQldERNML991jYDsPgWN1vYpM8GjLB7gfzc1E=; b=k3AnGR0y6S5TvLb/ydpqWRqZ1ucoS4N3D28LdSCryYbgQaUYVkN0ISM4CBebEf/KMb thrJutf2vGs2Gsojl0Xmb84YmyueC1Sbepoh72i9Rt0Del6KI8QqLYqzaOzeL6xFOlB9 U1nlJRFZ8XukIryITGjfzWZFMkY2Dr0szbb5oINPy3HlzZr9RaVKGuMyTQ2gIS2tTCD6 1NvM1zifhcYk9cBzhP0nIa/SSBXj6fM/DbBdaC12CZf9SG094xNn4zoKKCGJ3kTuBrka 9iQ6VGWDfdbgcRm9e7psSWdJuyqk+n0cd6sBI0RHbuHK3mbxcUg0tqz00uQQk800Gym0 3Jmw== X-Gm-Message-State: AOAM533ShV211w8GK1rFU/x2mptsJGBwq59550WgPjYrIltxaSLDf7A3 0yE7M1cj55HsubPPOHAIKgzGSM5pVp4= X-Google-Smtp-Source: ABdhPJwH5BHhiJ5aJqS6GbmbvxoKhccrgv9Wpm03zIysFDtMfyQnKchFlU/dQWhUg3VSqRaSbDChUQ== X-Received: by 2002:adf:d085:: with SMTP id y5mr23877371wrh.272.1628013844012; Tue, 03 Aug 2021 11:04:04 -0700 (PDT) Received: from localhost.localdomain ([185.110.110.213]) by smtp.gmail.com with ESMTPSA id b14sm15515555wrm.43.2021.08.03.11.04.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 11:04:03 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH 4/4] fsnotify: optimize the case of no marks of any type Date: Tue, 3 Aug 2021 21:03:44 +0300 Message-Id: <20210803180344.2398374-5-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210803180344.2398374-1-amir73il@gmail.com> References: <20210803180344.2398374-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Add a simple check in the inline helpers to avoid calling fsnotify() and __fsnotify_parent() in case there are no marks of any type (inode/sb/mount) for an inode's sb, so there can be no objects of any type interested in the event. Signed-off-by: Amir Goldstein Reviewed-by: Matthew Bobrowski --- include/linux/fsnotify.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index f8acddcf54fb..12d3a7d308ab 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -30,6 +30,9 @@ static inline void fsnotify_name(struct inode *dir, __u32 mask, struct inode *child, const struct qstr *name, u32 cookie) { + if (atomic_long_read(&dir->i_sb->s_fsnotify_connectors) == 0) + return; + fsnotify(mask, child, FSNOTIFY_EVENT_INODE, dir, name, NULL, cookie); } @@ -41,6 +44,9 @@ static inline void fsnotify_dirent(struct inode *dir, struct dentry *dentry, static inline void fsnotify_inode(struct inode *inode, __u32 mask) { + if (atomic_long_read(&inode->i_sb->s_fsnotify_connectors) == 0) + return; + if (S_ISDIR(inode->i_mode)) mask |= FS_ISDIR; @@ -53,6 +59,9 @@ static inline int fsnotify_parent(struct dentry *dentry, __u32 mask, { struct inode *inode = d_inode(dentry); + if (atomic_long_read(&inode->i_sb->s_fsnotify_connectors) == 0) + return 0; + if (S_ISDIR(inode->i_mode)) { mask |= FS_ISDIR;