From patchwork Tue Aug 10 15:12:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12429069 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 BD0CFC432BE for ; Tue, 10 Aug 2021 15:12:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9FA3B60FDA for ; Tue, 10 Aug 2021 15:12:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242709AbhHJPMv (ORCPT ); Tue, 10 Aug 2021 11:12:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242719AbhHJPMs (ORCPT ); Tue, 10 Aug 2021 11:12:48 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4EC6C06179B for ; Tue, 10 Aug 2021 08:12:25 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id b11so10631459wrx.6 for ; Tue, 10 Aug 2021 08:12:25 -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=fwwhc479nV/dKQaw1w4y0TanGoB6DLZWrBbYsA1C+1k=; b=TZ9VOm+rJyIk+JMyWjuqfeLBE08QwHl8gCjbEEOvErEUIR1Jz+sGHehLnj02D2oebO s5xlGeh4Upbvj2IhCOBKkFpD8n7++C9HQMbTHDenmLxdyAsPsF5lC6XilVeRKz5eU8eZ bWk+GFGfECnUQQrBMKGDqWkERai1qcjCBv7j8nlYylrNMARuTxx3rTo6cOZLuV4cf+7P gdt4lkmWWoxHKjC1Nu7Fy+edmZycbHaJOvCL727fZ39Ze7XNDX/49NwQrbXaVy4Hh57Q WRBGOsLdmfHnlidGGQUNX0YURY5mLVS8IyWIrZLkyvpEmdvemCc7MXqzTEekHHZEWfSa bTCw== 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=fwwhc479nV/dKQaw1w4y0TanGoB6DLZWrBbYsA1C+1k=; b=SmPTRxzeubKi51EOuJmA9ZI4PTSe4kkQngFh4LxIDtEtFWZCfBsgnHoNBUr0ZFX3t/ igfPBYCM3VIzVhGOvammLiI1n0aNcqGq73Q1Y0Xm9Xmr2C2QYEIcft+S6/Dm8f0GFa49 M3uUwb5VoMqHHhcaJboeOfDFvln30H93hb6sCB5Cx5mzMOSb7LlPQ4u/xPQ3/KSVRk6q AFJlsWWxismU98CUaij5fuohA3oyfXeoSqHC3wyLimA0QzprNuS1ZDVEzBa1rn8TSXSD 0bCZYLCymq8L38HUP6ZveilNnGQGr5VEwAWHQ4BOpJjDNn8f0zlN91OG/5HiRGQA7Zjc ME5w== X-Gm-Message-State: AOAM532WbfGP6Jh+2H6QwCkrVCCx4sw3AD1q93nBGTmxoAAdbM79MMYN ckd02pNrHxUQsrt0lD3iZjU= X-Google-Smtp-Source: ABdhPJy9LjwXSv77blYd7t7Vywp2w73CYJ9rMprwqJufH6sNVhHqoy/QFRVOS0labDjWQN39AoUBsA== X-Received: by 2002:a5d:53ca:: with SMTP id a10mr31352206wrw.197.1628608344432; Tue, 10 Aug 2021 08:12:24 -0700 (PDT) Received: from localhost.localdomain ([141.226.248.20]) by smtp.gmail.com with ESMTPSA id k12sm9568920wrd.75.2021.08.10.08.12.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Aug 2021 08:12:24 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org, Matthew Bobrowski Subject: [PATCH v2 1/4] fsnotify: replace igrab() with ihold() on attach connector Date: Tue, 10 Aug 2021 18:12:17 +0300 Message-Id: <20210810151220.285179-2-amir73il@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810151220.285179-1-amir73il@gmail.com> References: <20210810151220.285179-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. Reviewed-by: Matthew Bobrowski Signed-off-by: Amir Goldstein --- 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 10 15:12:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12429071 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 BE849C4320A for ; Tue, 10 Aug 2021 15:12:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A2579606A5 for ; Tue, 10 Aug 2021 15:12:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242707AbhHJPMw (ORCPT ); Tue, 10 Aug 2021 11:12:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242696AbhHJPMt (ORCPT ); Tue, 10 Aug 2021 11:12:49 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30388C061798 for ; Tue, 10 Aug 2021 08:12:27 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id k38-20020a05600c1ca6b029025af5e0f38bso2202432wms.5 for ; Tue, 10 Aug 2021 08:12:27 -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=KKgN7W6IzD5JntVCA6XBkExK5gIwEcrb/3fsqauRnWQ=; b=i2xe5CAFIDWi3Zo0Y+OGTEQIVeAVZeR97JkCevBkKp1/fjzfeJhosB15wRGVgew/Pv RsXpKU32b3MyUcB/gAln0ZzZGbm7Rahx9dK3Uqu0xdB93GNZOg10obx6IqKhcRRl6wyi cX0uXQflZeYoS8RcOugNkZL4PLHdnkcTsR0UcUHUHEGUx2RE+Ty0+zNXJPQ6BhAnxBsZ rGdr5P/11w6gExL9rWZFe31VhKIBVTCPfURRLCJYOwTyo686hay7p3cCLgZ9EcUpYqD9 aYSZ1JO4BExPSJzOmSG/T1k4IJpa3jeBe7OwvGYr291v5Buj1uShv0N7+pCI/4xqbRg2 auMw== 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=KKgN7W6IzD5JntVCA6XBkExK5gIwEcrb/3fsqauRnWQ=; b=jimoL5R5lu5hJUxW5gdusAufBIvBoPNrq3gjYtPeIUA20osXxNBr7N5/Gh5joD6Giy LDxvh2VCqeNVi7vjBGYOR18bzW2YzSbSV0alH6nKRm1hNz2a7A+SyGE63hzB/3ItDT9Q FbJnkQW3IdyuU0i7MUVbFP81akGYGDZJ8vLg5wusqYTbfO5PRRhJJeby4OE+Mwv4RBo9 zZVqJ2JCn/+m6CSNGWgiJIi0kDLm9ILUa2zs8T9UK8/PUcHxLmQ0Ad4QuCivxGFTDUUX frT2Fx0mParDjKwpAIZqrvY4z0WS3EMMVAilZ3ZzMYA7eTA6teWOItoO8Qqv4frgeZ7x UC4Q== X-Gm-Message-State: AOAM531OYNB79sPCJ1XBhHvkskuU9ETyz56Dqb58BmE28zMG0hXTPJak 0z8KNuwPX+DhkiEjJ8F9/g8= X-Google-Smtp-Source: ABdhPJy2zS6dkF3VL0+SSsCoGwsNlYjdodkrUeCcbrzZeSMR7y1Anlhw/az3D0tHHeScHBYQY8Yr+A== X-Received: by 2002:a1c:6a07:: with SMTP id f7mr12718291wmc.15.1628608345812; Tue, 10 Aug 2021 08:12:25 -0700 (PDT) Received: from localhost.localdomain ([141.226.248.20]) by smtp.gmail.com with ESMTPSA id k12sm9568920wrd.75.2021.08.10.08.12.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Aug 2021 08:12:25 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org, Matthew Bobrowski Subject: [PATCH v2 2/4] fsnotify: count s_fsnotify_inode_refs for attached connectors Date: Tue, 10 Aug 2021 18:12:18 +0300 Message-Id: <20210810151220.285179-3-amir73il@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810151220.285179-1-amir73il@gmail.com> References: <20210810151220.285179-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. Reviewed-by: Matthew Bobrowski Signed-off-by: Amir Goldstein --- 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 10 15:12:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12429073 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 05F31C4338F for ; Tue, 10 Aug 2021 15:12:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D9B7D60FC4 for ; Tue, 10 Aug 2021 15:12:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242719AbhHJPMx (ORCPT ); Tue, 10 Aug 2021 11:12:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242704AbhHJPMv (ORCPT ); Tue, 10 Aug 2021 11:12:51 -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 937B5C0613C1 for ; Tue, 10 Aug 2021 08:12:28 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id k29so13979782wrd.7 for ; Tue, 10 Aug 2021 08:12:28 -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=YEQ3pWZUnS//0e5IqiwBxlZdqIcHB6a0l5C6qRGJ94s=; b=lUk6S+2KePtxtYCjUEzMrdYFP5ksI7kew9X+w2GUoA1VR4/BDRWYrf90vQvxYnveNT z+vLPLkszhwsorpCF4szTSJJmr+thiAQgC6WzpCMenYxiwCr4UzWXJvvk7JzX+xmD3Fg v131ifwVbVBH+0cJQb06QvM8LmOjGQYlM+XDRxXu8ouow0MpKXhpoKAfL9sZMjQBHQgw gbMtLfZ0aZSVWKpxCdVa1rPBRQNhHf1UCDU+sxKj2ZwuRk5x87urcwOWt80dD5Ut1Vti T291lYU8T+sHYiPmfxYd6NrexMkbPSCHV4peCwleX8KC/f5msRJXWcoJb3IpojNgsMjb v38g== 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=YEQ3pWZUnS//0e5IqiwBxlZdqIcHB6a0l5C6qRGJ94s=; b=PKSzdqE0if1FZjZQXB/HXhrMVnaoKBxQYuvgGAUZHZglVK3QHRTCNWBMcGBL891bjo yLxvg1onI8ZvTP4w+M/pe1tJKYDEdkMhNcJ4ahQe0tfk84TMwYGjf4TkcXeBFNRvMbk4 pYr9Ef/kmCUTD6xc/odb664j6/GHwfWP5X/zHxmBXjUgh+lEWK0mWrQH5dfGKBqMjmdy lM6z6G403iadILNU9vZvl7WTMbu+sZ4AhtfspXrrq85vv0+SOwSi3DhYcniMeLjEV0XO DW51myS3YoOMzl7jvOTXMeTw1xho86pgAbAFFYhZ8va0aJ5OmPUfkPGPk4ScfIWWT2+h aDVQ== X-Gm-Message-State: AOAM532BNY8LY6Ur9mA1zwnYHkaS2EiNS5eYVEx4AqODf2Yxk/TMRBt9 gFgDHA5LOOA2lYgldd9jwdM= X-Google-Smtp-Source: ABdhPJyhWQ3hWWSLeZ4srgmfLmP6fcB4GC1QyWz8HjSq0wbo5chxkfGyoegaWUU1uPSkeIujIqpTag== X-Received: by 2002:adf:e8d0:: with SMTP id k16mr31976235wrn.195.1628608347231; Tue, 10 Aug 2021 08:12:27 -0700 (PDT) Received: from localhost.localdomain ([141.226.248.20]) by smtp.gmail.com with ESMTPSA id k12sm9568920wrd.75.2021.08.10.08.12.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Aug 2021 08:12:26 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 3/4] fsnotify: count all objects with attached connectors Date: Tue, 10 Aug 2021 18:12:19 +0300 Message-Id: <20210810151220.285179-4-amir73il@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810151220.285179-1-amir73il@gmail.com> References: <20210810151220.285179-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_connectors 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 Reviewed-by: Matthew Bobrowski --- fs/notify/fsnotify.c | 6 +++--- fs/notify/fsnotify.h | 15 +++++++++++++++ fs/notify/mark.c | 24 +++++++++++++++++++++--- include/linux/fs.h | 4 ++-- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 30d422b8c0fc..963e6ce75b96 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -87,15 +87,15 @@ 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)); } void fsnotify_sb_delete(struct super_block *sb) { fsnotify_unmount_inodes(sb); fsnotify_clear_marks_by_sb(sb); + /* Wait for outstanding object references from connectors */ + wait_var_event(&sb->s_fsnotify_connectors, + !atomic_long_read(&sb->s_fsnotify_connectors)); } /* diff --git a/fs/notify/fsnotify.h b/fs/notify/fsnotify.h index ff2063ec6b0f..87d8a50ee803 100644 --- a/fs/notify/fsnotify.h +++ b/fs/notify/fsnotify.h @@ -27,6 +27,21 @@ static inline struct super_block *fsnotify_conn_sb( return container_of(conn->obj, struct super_block, s_fsnotify_marks); } +static inline struct super_block *fsnotify_connector_sb( + struct fsnotify_mark_connector *conn) +{ + switch (conn->type) { + case FSNOTIFY_OBJ_TYPE_INODE: + return fsnotify_conn_inode(conn)->i_sb; + case FSNOTIFY_OBJ_TYPE_VFSMOUNT: + return fsnotify_conn_mount(conn)->mnt.mnt_sb; + case FSNOTIFY_OBJ_TYPE_SB: + return fsnotify_conn_sb(conn); + default: + return NULL; + } +} + /* destroy all events sitting in this groups notification queue */ extern void fsnotify_flush_notify(struct fsnotify_group *group); diff --git a/fs/notify/mark.c b/fs/notify/mark.c index 2d8c46e1167d..95006d1d29ab 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,24 @@ 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 = fsnotify_connector_sb(conn); + + if (sb) + atomic_long_inc(&sb->s_fsnotify_connectors); +} + +static void fsnotify_put_sb_connectors(struct fsnotify_mark_connector *conn) +{ + struct super_block *sb = fsnotify_connector_sb(conn); + + if (sb && 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 +219,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 +521,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 10 15:12:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12429075 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 67B4BC432BE for ; Tue, 10 Aug 2021 15:12:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 448B460F25 for ; Tue, 10 Aug 2021 15:12:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242725AbhHJPMy (ORCPT ); Tue, 10 Aug 2021 11:12:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242716AbhHJPMw (ORCPT ); Tue, 10 Aug 2021 11:12:52 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE194C0613C1 for ; Tue, 10 Aug 2021 08:12:29 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id k29so13979879wrd.7 for ; Tue, 10 Aug 2021 08:12:29 -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=Qly801pD8R1BCAJDgcv2Jy+JMcMqItg9ZtCsmo0L3YI=; b=rvoSiV1VnvykmqsYGqBOYG0NYCiNhP7yRiqC/egVr1alQK00TeLSWJmMZlEhBx3CcN P6bvkJUxf7cKSTJdJ6OZxhkgVl9upazMadO54KtAV7aBJTv6FHQbXqRVLxkwMirX8CGk aD0JXCjBmwi5REf70bdVd6ETxsHqL/bMkcKYmOhSmFIjjuboiCJ9t5roa0+XYlv/PTdz 7ls0BCArC9v8qWIXhvIqcs1egySBBx9iePBzJ+045AN06otuDvOlvLB/kLaIxz0c3wnM 87jwx8KGBFp2EwNjNmk+NFJGEUV5EFwYKC/UhJ24od54Es1VVxacFIWcBqVgcwiaz0YP 2QsQ== 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=Qly801pD8R1BCAJDgcv2Jy+JMcMqItg9ZtCsmo0L3YI=; b=VXoTRDcJ5TtOR+KVC13QIovGqY+sKhr9Mk8FcJNfOKU4UA3cSE00dKaGH7ULIY6qvo 3OOnSUSDDFc071er5bMON/coBHx4j4iU4wvqsqeAf+Ky2gi/10ZsEiTsKaNruHjHB5CE hdmZhXu/rYpGLFuwK3NTv+/5iEMbumkhIFAOlSphjqCN4SxM8OuBM1NBlu2Y0daTB2nl Nw0q0QFeeE8jKoa4uxX+pu2G0hgKvSby8/Scu0lo1G9Aeb3D2vT14yMG7FAYkIvC/VS2 K4rd/izHQkpuB8yeqOagToy7/RsHMGR7edkaTZml7o4ppMVqdOgUnt0Dd4uNkV0acmm8 G6NA== X-Gm-Message-State: AOAM5316gw9kSxpQ6Y7T3VYXRPXkT4LcozitXjpfbbR91rkRwIvn7SDw wR4sanS6PzmmN2r/FG4B33M= X-Google-Smtp-Source: ABdhPJz/A9XJZt3kUZ1frZvQFpXmR6qog3J4r4xspf3LimwQnDkB5qdL3BfyKNmEJnLVLtCQZ92mEg== X-Received: by 2002:adf:ee51:: with SMTP id w17mr30651035wro.279.1628608348616; Tue, 10 Aug 2021 08:12:28 -0700 (PDT) Received: from localhost.localdomain ([141.226.248.20]) by smtp.gmail.com with ESMTPSA id k12sm9568920wrd.75.2021.08.10.08.12.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Aug 2021 08:12:28 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org, Matthew Bobrowski Subject: [PATCH v2 4/4] fsnotify: optimize the case of no marks of any type Date: Tue, 10 Aug 2021 18:12:20 +0300 Message-Id: <20210810151220.285179-5-amir73il@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810151220.285179-1-amir73il@gmail.com> References: <20210810151220.285179-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. Reviewed-by: Matthew Bobrowski Signed-off-by: Amir Goldstein --- 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;