From patchwork Thu Jun 25 00:16:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Hansen X-Patchwork-Id: 6671331 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 098CF9F39B for ; Thu, 25 Jun 2015 00:18:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A7D802042A for ; Thu, 25 Jun 2015 00:18:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4C67E207E4 for ; Thu, 25 Jun 2015 00:17:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752671AbbFYAQw (ORCPT ); Wed, 24 Jun 2015 20:16:52 -0400 Received: from mga02.intel.com ([134.134.136.20]:30752 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752357AbbFYAQL (ORCPT ); Wed, 24 Jun 2015 20:16:11 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP; 24 Jun 2015 17:16:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,673,1427785200"; d="scan'208";a="594262348" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.39.19]) by orsmga003.jf.intel.com with ESMTP; 24 Jun 2015 17:16:09 -0700 Subject: [RFCv2][PATCH 7/7] fsnotify: track when ignored mask clearing is needed To: dave@sr71.net Cc: jack@suse.cz, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, paulmck@linux.vnet.ibm.com, tim.c.chen@linux.intel.com, ak@linux.intel.com, dave.hansen@linux.intel.com From: Dave Hansen Date: Wed, 24 Jun 2015 17:16:08 -0700 References: <20150625001605.72553909@viggo.jf.intel.com> In-Reply-To: <20150625001605.72553909@viggo.jf.intel.com> Message-Id: <20150625001608.830BD5CA@viggo.jf.intel.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dave Hansen According to Jan Kara: You can have ignored mask set without any of the notification masks set and you are expected to clear the ignored mask on the first IN_MODIFY event. But, the only way we currently have to go and find if we need to do this ignored-mask-clearing is to go through the mark lists and look for them. That mark list iteration requires an srcu_read_lock() which has a memory barrier and can be expensive. The calculation of 'has_ignore' is pretty cheap because we store it next to another value which we are updating and we do it inside of a loop we were already running. This patch will really only matter when we have a workload where a file is being modified often _and_ there is an active fsnotify mark on it. Otherwise the checks against *_fsnotify.marks.first will keep us out of the expensive srcu_read_lock() call. Cc: Jan Kara Cc: Alexander Viro Cc: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Paul E. McKenney Cc: Tim Chen Cc: Andi Kleen Signed-off-by: Dave Hansen --- b/fs/notify/fsnotify.c | 44 ++++++++++++++++++++++++++++++++++------ b/fs/notify/mark.c | 8 +++++-- b/include/linux/fsnotify_head.h | 1 3 files changed, 45 insertions(+), 8 deletions(-) diff -puN fs/notify/fsnotify.c~fsnotify-ignore-present fs/notify/fsnotify.c --- a/fs/notify/fsnotify.c~fsnotify-ignore-present 2015-06-24 17:14:37.187226743 -0700 +++ b/fs/notify/fsnotify.c 2015-06-24 17:14:37.194227057 -0700 @@ -183,6 +183,34 @@ static int send_to_group(struct inode *t } /* + * The "logical or" of all of the marks' ->mask is kept in the + * i/mnt_fsnotify.mask. We can check it instead of going + * through all of the marks. fsnotify_recalc_mask() does the + * updates. + */ +static int some_mark_is_interested(__u32 mask, struct inode *inode, struct mount *mnt) +{ + if (mask & inode->i_fsnotify.mask) + return 1; + if (mnt && (mask & mnt->mnt_fsnotify.mask)) + return 1; + return 0; +} + +/* + * fsnotify_recalc_mask() recalculates "has_ignore" whenever any + * mark's flags change. + */ +static int some_mark_needs_ignore_clear(struct inode *inode, struct mount *mnt) +{ + if (inode->i_fsnotify.has_ignore) + return 1; + if (mnt && mnt->mnt_fsnotify.has_ignore) + return 1; + return 0; +} + +/* * This is the main call to fsnotify. The VFS calls into hook specific functions * in linux/fsnotify.h. Those functions then in turn call here. Here will call * out to all of the registered fsnotify_group. Those groups can then use the @@ -205,14 +233,18 @@ int fsnotify(struct inode *to_tell, __u3 mnt = NULL; /* - * if this is a modify event we may need to clear the ignored masks - * otherwise return if neither the inode nor the vfsmount care about - * this type of event. + * We must clear the (user-visible) ignored mask on the first IN_MODIFY + * event despite the 'mask' which is passed in here. But we can safely + * skip that step if we know there are no marks which need this action. + * + * We can also skip looking at the list of marks if we know that none + * of the marks are interested in the events in our 'mask'. */ - if (!(mask & FS_MODIFY) && - !(test_mask & to_tell->i_fsnotify.mask) && - !(mnt && test_mask & mnt->mnt_fsnotify.mask)) + if ((mask & FS_MODIFY) && !some_mark_needs_ignore_clear(to_tell, mnt)) + return 0; + else if (!some_mark_is_interested(test_mask, to_tell, mnt)) return 0; + /* * Optimization: srcu_read_lock() has a memory barrier which can * be expensive. It protects walking the *_fsnotify_marks lists. diff -puN fs/notify/mark.c~fsnotify-ignore-present fs/notify/mark.c --- a/fs/notify/mark.c~fsnotify-ignore-present 2015-06-24 17:14:37.189226832 -0700 +++ b/fs/notify/mark.c 2015-06-24 17:14:37.194227057 -0700 @@ -116,10 +116,14 @@ void fsnotify_recalc_mask(struct fsnotif { u32 new_mask = 0; struct fsnotify_mark *mark; + u32 has_ignore = 0; - hlist_for_each_entry(mark, &fsn->marks, obj_list) + hlist_for_each_entry(mark, &fsn->marks, obj_list) { + if (mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY) + has_ignore = 1; new_mask |= mark->mask; - + } + fsn->has_ignore = has_ignore; fsn->mask = new_mask; } diff -puN include/linux/fsnotify_head.h~fsnotify-ignore-present include/linux/fsnotify_head.h --- a/include/linux/fsnotify_head.h~fsnotify-ignore-present 2015-06-24 17:14:37.190226877 -0700 +++ b/include/linux/fsnotify_head.h 2015-06-24 17:14:37.193227012 -0700 @@ -11,6 +11,7 @@ struct fsnotify_head { #ifdef CONFIG_FSNOTIFY __u32 mask; /* all events this object cares about */ struct hlist_head marks; + __u32 has_ignore; /* any marks has ignore set */ #endif };