Commit ec44610f authored by Amir Goldstein's avatar Amir Goldstein Committed by Jan Kara

fsnotify: count all objects with attached connectors

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.

Link: https://lore.kernel.org/r/20210810151220.285179-4-amir73il@gmail.comSigned-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
Reviewed-by: default avatarMatthew Bobrowski <repnop@google.com>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
parent 11fa333b
...@@ -87,15 +87,15 @@ static void fsnotify_unmount_inodes(struct super_block *sb) ...@@ -87,15 +87,15 @@ static void fsnotify_unmount_inodes(struct super_block *sb)
if (iput_inode) if (iput_inode)
iput(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) void fsnotify_sb_delete(struct super_block *sb)
{ {
fsnotify_unmount_inodes(sb); fsnotify_unmount_inodes(sb);
fsnotify_clear_marks_by_sb(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));
} }
/* /*
......
...@@ -27,6 +27,21 @@ static inline struct super_block *fsnotify_conn_sb( ...@@ -27,6 +27,21 @@ static inline struct super_block *fsnotify_conn_sb(
return container_of(conn->obj, struct super_block, s_fsnotify_marks); 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 */ /* destroy all events sitting in this groups notification queue */
extern void fsnotify_flush_notify(struct fsnotify_group *group); extern void fsnotify_flush_notify(struct fsnotify_group *group);
......
...@@ -172,7 +172,7 @@ static void fsnotify_connector_destroy_workfn(struct work_struct *work) ...@@ -172,7 +172,7 @@ static void fsnotify_connector_destroy_workfn(struct work_struct *work)
static void fsnotify_get_inode_ref(struct inode *inode) static void fsnotify_get_inode_ref(struct inode *inode)
{ {
ihold(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) static void fsnotify_put_inode_ref(struct inode *inode)
...@@ -180,8 +180,24 @@ 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; struct super_block *sb = inode->i_sb;
iput(inode); iput(inode);
if (atomic_long_dec_and_test(&sb->s_fsnotify_inode_refs)) if (atomic_long_dec_and_test(&sb->s_fsnotify_connectors))
wake_up_var(&sb->s_fsnotify_inode_refs); 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( static void *fsnotify_detach_connector_from_object(
...@@ -203,6 +219,7 @@ 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_conn_sb(conn)->s_fsnotify_mask = 0;
} }
fsnotify_put_sb_connectors(conn);
rcu_assign_pointer(*(conn->obj), NULL); rcu_assign_pointer(*(conn->obj), NULL);
conn->obj = NULL; conn->obj = NULL;
conn->type = FSNOTIFY_OBJ_TYPE_DETACHED; conn->type = FSNOTIFY_OBJ_TYPE_DETACHED;
...@@ -504,6 +521,7 @@ static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp, ...@@ -504,6 +521,7 @@ static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp,
inode = fsnotify_conn_inode(conn); inode = fsnotify_conn_inode(conn);
fsnotify_get_inode_ref(inode); fsnotify_get_inode_ref(inode);
} }
fsnotify_get_sb_connectors(conn);
/* /*
* cmpxchg() provides the barrier so that readers of *connp can see * cmpxchg() provides the barrier so that readers of *connp can see
......
...@@ -1507,8 +1507,11 @@ struct super_block { ...@@ -1507,8 +1507,11 @@ struct super_block {
/* Number of inodes with nlink == 0 but still referenced */ /* Number of inodes with nlink == 0 but still referenced */
atomic_long_t s_remove_count; 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, note that
* inodes objects are currently double-accounted.
*/
atomic_long_t s_fsnotify_connectors;
/* Being remounted read-only */ /* Being remounted read-only */
int s_readonly_remount; int s_readonly_remount;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment