From patchwork Wed Oct 3 21:25:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10625335 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B9F751731 for ; Wed, 3 Oct 2018 21:26:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB2D128FF9 for ; Wed, 3 Oct 2018 21:26:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F86D29087; Wed, 3 Oct 2018 21:26:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E91D28FF9 for ; Wed, 3 Oct 2018 21:26:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726840AbeJDEQG (ORCPT ); Thu, 4 Oct 2018 00:16:06 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:53292 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726730AbeJDEQG (ORCPT ); Thu, 4 Oct 2018 00:16:06 -0400 Received: by mail-wm1-f65.google.com with SMTP id b19-v6so7061509wme.3 for ; Wed, 03 Oct 2018 14:25:58 -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; bh=WJ7ONiEM5USfpIMIZ0NsRrcFmQplKm8MWJZ3PZDI0Tk=; b=g8c6412p4F9rNLmsG9NI3xEmfnQy13H1tM488cRSzjtNDeoQO2x2L/rbW7VGFtKtCM q941X6yhb4o70HzEj7i3kU5lkP9JrTF+xrSJ5MBNVgJXssmMxXCzFaJyrbPtSV/ETuFt jmTKpj/RcJaL0iC73UL95wIROAgbkz1cmxtrhbspDaKStrVAObRLDbooFidZj73sFSog AzBaJLRslvV5bwbMxmPd7+Xtaoh172bUck4WNoOVegCrFwi8Zl1kJh/BG16EEu8g8Lef lD/MRd3ZOSGy24SxWtvbio9nWqccf9E3Y7H64gZ+bcg+2dRSiDXC/KX+Md4NiGezlv+z Rsvw== 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; bh=WJ7ONiEM5USfpIMIZ0NsRrcFmQplKm8MWJZ3PZDI0Tk=; b=BV/6vCVjlYFz24aXBTOIy/I2lTjJdOgh8pUrbVTp2YzGu4Iy6WDqZ5npczdb7D7QEC n4Zjt/3mlRnbXrid9wvsbsPd025tFuYIZRWxxh3xlUA9YPsum0m+xCLbV9FTVCcsN1+l vhbzOYqD6YGRiGQBisifQJ5eeDb4/Sqo3jV8TvwyOrASJPJh97V50hiadv3yRMB5MNIQ RnMrvT8rbLTYqsTJ+Gs++xYSNTxJphJZMIOwpFIiwdLqwmMASLHUDnZOfctqRqzdhRhD mG1pfEJXvXGFDSOWXmjCAxrtWHZHdF+jHmS99yZC+qrNHJ2qtcMdGndWrVKnPrjBYEOx kGMw== X-Gm-Message-State: ABuFfohdnFh8YrrHu47AodQ8EMMQBpls3qTHd82pwoTMcELxZDSdjCXf DrGBcw0mMs80B5C6xTOZ8+GHBoXz X-Google-Smtp-Source: ACcGV63QWo7jfX7j4AK3gyyaYMPQgOflZ26Aq7p57XfjpnbhE4Lur1TpKd86qA2oYA9uzO+nshbrRg== X-Received: by 2002:a1c:c444:: with SMTP id u65-v6mr2781803wmf.10.1538601957703; Wed, 03 Oct 2018 14:25:57 -0700 (PDT) Received: from localhost.localdomain ([141.226.14.107]) by smtp.gmail.com with ESMTPSA id 193-v6sm4073866wmj.21.2018.10.03.14.25.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 14:25:57 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 8/8] fsnotify: optimize away srcu_read_lock() for events on directories Date: Thu, 4 Oct 2018 00:25:39 +0300 Message-Id: <20181003212539.2384-9-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181003212539.2384-1-amir73il@gmail.com> References: <20181003212539.2384-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP inotify and dnotify are always interested in events on directories. fanotify is interested in events on directories only if user requested them by flag FAN_ONDIR. For the fanotify supported events on directories (open/access/close), if there is no inotify/dnotify associated marks and if none of the associated fanotify marks have the FS_ISDIR flag, we can skip iterating the marks and we avoid taking the srcu_read_lock() for all events on directories. In order to enable this check in fsnotify() we set the FS_ISDIR flag explicitly on all dnotify/inotify marks. Signed-off-by: Amir Goldstein --- fs/notify/dnotify/dnotify.c | 5 +++-- fs/notify/fsnotify.c | 9 ++++++++- fs/notify/inotify/inotify_user.c | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c index 58d77dc696eb..55f0ae5fe0ba 100644 --- a/fs/notify/dnotify/dnotify.c +++ b/fs/notify/dnotify/dnotify.c @@ -89,7 +89,7 @@ static int dnotify_handle_event(struct fsnotify_group *group, struct dnotify_struct *dn; struct dnotify_struct **prev; struct fown_struct *fown; - __u32 test_mask = mask & ~FS_EVENT_ON_CHILD; + __u32 test_mask = mask & ALL_FSNOTIFY_EVENTS; /* not a dir, dnotify doesn't care */ if (!S_ISDIR(inode->i_mode)) @@ -197,7 +197,8 @@ void dnotify_flush(struct file *filp, fl_owner_t id) /* this conversion is done only at watch creation */ static __u32 convert_arg(unsigned long arg) { - __u32 new_mask = FS_EVENT_ON_CHILD; + /* Interested in events on children including subdirs */ + __u32 new_mask = FS_EVENT_ON_CHILD | FS_ISDIR; if (arg & DN_MULTISHOT) new_mask |= FS_DN_MULTISHOT; diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 875975504409..a0ad06285450 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -332,9 +332,16 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, __u32 test_mask = (mask & ALL_FSNOTIFY_EVENTS); if (data_is == FSNOTIFY_EVENT_PATH) { - mnt = real_mount(((const struct path *)data)->mnt); + const struct path *path = data; + + mnt = real_mount(path->mnt); sb = mnt->mnt.mnt_sb; mnt_or_sb_mask = mnt->mnt_fsnotify_mask | sb->s_fsnotify_mask; + + /* Is anybody is interested in events on directories? */ + if (d_is_dir(path->dentry) && + !(FS_ISDIR & (to_tell->i_fsnotify_mask | mnt_or_sb_mask))) + return 0; } /* diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c index 105576daca4a..8d163b96a86a 100644 --- a/fs/notify/inotify/inotify_user.c +++ b/fs/notify/inotify/inotify_user.c @@ -91,9 +91,9 @@ static inline __u32 inotify_arg_to_mask(u32 arg) /* * everything should accept their own ignored, cares about children, - * and should receive events when the inode is unmounted + * directories, and should receive events when the inode is unmounted. */ - mask = (FS_IN_IGNORED | FS_EVENT_ON_CHILD | FS_UNMOUNT); + mask = (FS_IN_IGNORED | FS_EVENT_ON_CHILD | FS_ISDIR | FS_UNMOUNT); /* mask off the flags used to open the fd */ mask |= (arg & (IN_ALL_EVENTS | IN_ONESHOT | IN_EXCL_UNLINK));