linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Jan Kara <jack@suse.cz>,
	Matthew Bobrowski <mbobrowski@mbobrowski.org>,
	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 3/4] fsnotify: count all objects with attached connectors
Date: Tue, 10 Aug 2021 12:47:34 +0200	[thread overview]
Message-ID: <20210810104734.GC18722@quack2.suse.cz> (raw)
In-Reply-To: <20210803180344.2398374-4-amir73il@gmail.com>

On Tue 03-08-21 21:03:43, Amir Goldstein wrote:
> 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 <amir73il@gmail.com>
> ---
>  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));
>  }

I think this is wrong and will deadlock unmount if there's pending sb mark
because s_fsnotify_connectors won't drop to 0. I think you need to move
this wait to fsnotify_sb_delete() after fsnotify_clear_marks_by_sb().

Otherwise the patch looks good to me.

								Honza

>  
>  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;
> -- 
> 2.25.1
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  parent reply	other threads:[~2021-08-10 10:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-03 18:03 [PATCH 0/4] Performance optimization for no fsnotify marks Amir Goldstein
2021-08-03 18:03 ` [PATCH 1/4] fsnotify: replace igrab() with ihold() on attach connector Amir Goldstein
2021-08-10  5:39   ` Matthew Bobrowski
2021-08-03 18:03 ` [PATCH 2/4] fsnotify: count s_fsnotify_inode_refs for attached connectors Amir Goldstein
2021-08-10  6:03   ` Matthew Bobrowski
2021-08-03 18:03 ` [PATCH 3/4] fsnotify: count all objects with " Amir Goldstein
2021-08-10  6:31   ` Matthew Bobrowski
2021-08-10 14:12     ` Amir Goldstein
2021-08-10 10:47   ` Jan Kara [this message]
2021-08-10 14:22     ` Amir Goldstein
2021-08-03 18:03 ` [PATCH 4/4] fsnotify: optimize the case of no marks of any type Amir Goldstein
2021-08-08 14:34   ` [fsnotify] e902b4cafb: unixbench.score 6.1% improvement kernel test robot
2021-08-10  6:43   ` [PATCH 4/4] fsnotify: optimize the case of no marks of any type Matthew Bobrowski
2021-08-10 10:49 ` [PATCH 0/4] Performance optimization for no fsnotify marks Jan Kara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210810104734.GC18722@quack2.suse.cz \
    --to=jack@suse.cz \
    --cc=amir73il@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=mbobrowski@mbobrowski.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).