fsnotify: Check parent watches without child dentry flags
Subsystems (2)
cover fsnotify: Check parent watches without child dentry flags
This patch removes the cached-child dentry walk performed when a directory first starts watching child events. Instead, the event path takes a reference to the parent dentry and checks its child-watch mask. It also removes the DCACHE_FSNOTIFY_PARENT_WATCHED flag and its update sites.
On the test host, 12 million files were populated and their positive dentries were warmed before each run. With eight concurrent unlink/recreate workers and 100 sole-watch add/close cycles, inotify_add_watch() measured:
Before After
run 1 average 107.420 ms 0.004 ms run 2 average 125.433 ms 0.004 ms run 1 maximum 122.811 ms 0.113 ms run 2 maximum 141.198 ms 0.095 ms
The displayed 0.004 ms averages are rounded to three decimal places. Maximum unlink/recreate latency was 777.852 and 770.569 ms before, versus 8.525 and 15.624 ms after. Those mutation maxima are supporting observations:
workers ran only during the watch-add loops, so the pre-change and post-change mutation measurement windows had very different lengths.
One 100,000-iteration, single-worker open/close event-path run per mode gave:
Before After
none: p50/p99 ns 9564 / 15703 9684 / 15023
throughput 102221 ops/s 101432 ops/s
other: p50/p99 ns 9554 / 15573 9684 / 14962
throughput 99442 ops/s 101497 ops/s parent: p50/p99 ns 12529 / 19179 12499 / 17716
throughput 78196 ops/s 78655 ops/s
The 'other' mode watches a different directory on the same filesystem, so it exercises the superblock watcher path without target-file event delivery. These are single runs; they do not establish a small event-path cost or its absence. No open/close regression is apparent at this measurement resolution. The test used worker CPU 2 and listener CPU 4 on kernels 6.19.0-rc8.V_fsn0.el9.omm0.x86_64 and 6.19.0-rc8.fsn3.el9.omm3.x86_64, respectively. The test host reported XFS for its working directory.
The inotify correctness test and broader fsnotify functional test passed on both kernels. The fanotify permission subtest skipped with EPERM in both runs, so FAN_OPEN_PERM remains unvalidated by these results.
Partha Sarathi Satapathy (1):
fsnotify: Check parent watches without child dentry flags
fs/dcache.c | 4 -- fs/notify/fsnotify.c | 99 ++++++++------------------------ fs/notify/fsnotify.h | 6 -- fs/notify/mark.c | 35 ----------- include/linux/dcache.h | 1 - include/linux/fsnotify.h | 7 +-- include/linux/fsnotify_backend.h | 29 ++-------- 7 files changed, 29 insertions(+), 152 deletions(-)
PATCH 1/1 fsnotify: Check parent watches without child dentry flags
Enabling child watches currently walks all cached children of a directory to set DCACHE_FSNOTIFY_PARENT_WATCHED. This makes watch installation proportional to the number of cached dentries and takes each child's d_lock.
Instead, obtain a referenced parent and read its child-watch mask in __fsnotify_parent() when deciding whether to include parent and name information. Check the parent directly in fsnotify_open_perm_and_set_mode() so permission events are handled before the normal open notification.
Remove the bulk walk, the dentry flag, and its dcache updates. This moves work from watch installation to events: events on a superblock with watchers now acquire and release a parent dentry reference.
---
Tested on a 12-million-file directory with eight mutation workers and 100 watch-add cycles: the two before/after average watch-add latencies were 107.420/0.004 ms and 125.433/0.004 ms. Inotify functional tests passed on both kernels; the fanotify permission test skipped with EPERM. See the cover letter for event-path measurements and their single-run limitation.
fs/dcache.c | 4 -- fs/notify/fsnotify.c | 99 ++++++++------------------------ fs/notify/fsnotify.h | 6 -- fs/notify/mark.c | 35 ----------- include/linux/dcache.h | 1 - include/linux/fsnotify.h | 7 +-- include/linux/fsnotify_backend.h | 29 ++-------- 7 files changed, 29 insertions(+), 152 deletions(-)
fs/dcache.c +0 -4
@@ -1984,7 +1984,6 @@ static void __d_instantiate(struct dentry *dentry, struct inode *inode)raw_write_seqcount_begin (&dentry->d_seq);__d_set_inode_and_type (dentry, inode, add_flags);raw_write_seqcount_end (&dentry->d_seq); -fsnotify_update_flags (dentry); }/**
@@ -2764,7 +2763,6 @@ static inline void __d_add(struct dentry *dentry, struct inode *inode,raw_write_seqcount_begin (&dentry->d_seq);__d_set_inode_and_type (dentry, inode, add_flags);raw_write_seqcount_end (&dentry->d_seq); -fsnotify_update_flags (dentry); }__d_rehash (dentry);if (dir)
@@ -2939,13 +2937,11 @@ static void __d_move(struct dentry *dentry, struct dentry *target,__hlist_del (&target->d_sib);hlist_add_head (&target->d_sib, &target->d_parent->d_children);__d_rehash (target); -fsnotify_update_flags (target); }if (!hlist_unhashed (&dentry->d_sib))__hlist_del (&dentry->d_sib);hlist_add_head (&dentry->d_sib, &dentry->d_parent->d_children);__d_rehash (dentry); -fsnotify_update_flags (dentry);fscrypt_handle_d_move (dentry);write_seqcount_end (&target->d_seq);
fs/notify/fsnotify.c +23 -76
141 lines not on this page · raw message
fs/notify/fsnotify.h +0 -6
@@ -100,12 +100,6 @@ static inline void fsnotify_clear_marks_by_mntns(struct mnt_namespace *mntns) fsnotify_destroy_marks(&mntns->n_fsnotify_marks); } -/* -* update the dentry->d_flags of all of inode's children to indicate if inode cares -* about events that happen to its children. -*/ -extern void fsnotify_set_children_dentry_flags (struct inode *inode); -extern struct kmem_cache *fsnotify_mark_connector_cachep;#endif /* __FS_NOTIFY_FSNOTIFY_H_ */
fs/notify/mark.c +0 -35
@@ -264,24 +264,6 @@ static void *__fsnotify_recalc_mask(struct fsnotify_mark_connector *conn)return fsnotify_update_iref (conn, want_iref); } -static bool fsnotify_conn_watches_children ( -struct fsnotify_mark_connector *conn) -{ -if (conn->type !=FSNOTIFY_OBJ_TYPE_INODE ) -return false; - -return fsnotify_inode_watches_children (fsnotify_conn_inode (conn)); -} - -static void fsnotify_conn_set_children_dentry_flags ( -struct fsnotify_mark_connector *conn) -{ -if (conn->type !=FSNOTIFY_OBJ_TYPE_INODE ) -return ; - -fsnotify_set_children_dentry_flags (fsnotify_conn_inode (conn)); -} -/* * Calculate mask of events for a list of marks. The caller must make sure * connector and connector->obj cannot disappear under us. Callers achieve
@@ -290,23 +272,12 @@ static void fsnotify_conn_set_children_dentry_flags(*/ void fsnotify_recalc_mask (struct fsnotify_mark_connector *conn) { -bool update_children; -if (!conn)return ;spin_lock (&conn->lock); - update_children = !fsnotify_conn_watches_children (conn);__fsnotify_recalc_mask (conn); - update_children &=fsnotify_conn_watches_children (conn);spin_unlock (&conn->lock); -/* -* Set children's PARENT_WATCHED flags only if parent started watching. -* When parent stops watching, we clear false positive PARENT_WATCHED -* flags lazily in __fsnotify_parent(). -*/ -if (update_children) -fsnotify_conn_set_children_dentry_flags (conn); }/* Free all connectors queued for freeing once SRCU period ends */
@@ -430,12 +401,6 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)spin_unlock (&destroy_lock);queue_work (system_dfl_wq, &connector_reaper_work); } -/* -* Note that we didn't update flags telling whether inode cares about -* what's happening with children. We update these flags from -* __fsnotify_parent() lazily when next event happens on one of our -* children. -*/ spin_lock (&destroy_lock);list_add (&mark->g_list, &destroy_list);spin_unlock (&destroy_lock);
include/linux/dcache.h +0 -1
@@ -205,7 +205,6 @@ enum dentry_flags {* last dput() */ DCACHE_NFSFS_RENAMED =BIT (12 ), -DCACHE_FSNOTIFY_PARENT_WATCHED =BIT (13 ),/* Parent inode is watched by some fsnotify listener */ DCACHE_DENTRY_KILLED =BIT (14 ),DCACHE_MOUNTED =BIT (15 ),/* is a mountpoint */ DCACHE_NEED_AUTOMOUNT = BIT(16), /* handle automount on this dir */
include/linux/fsnotify.h +1 -6
@@ -81,14 +81,9 @@ static inline int fsnotify_parent(struct dentry *dentry, __u32 mask,if (!fsnotify_sb_has_watchers (inode->i_sb))return 0 ; -if (S_ISDIR (inode->i_mode)) { +if (S_ISDIR (inode->i_mode)) mask |=FS_ISDIR ; -/* sb/mount marks are not interested in name of directory */ -if (!(dentry->d_flags &DCACHE_FSNOTIFY_PARENT_WATCHED )) - goto notify_child; - } -/* disconnected dentry cannot notify parent */ if (IS_ROOT (dentry)) goto notify_child;
include/linux/fsnotify_backend.h +5 -24
@@ -680,27 +680,6 @@ static inline int fsnotify_inode_watches_children(struct inode *inode)return parent_mask &FS_EVENTS_POSS_ON_CHILD ; } -/* -* Update the dentry with a flag indicating the interest of its parent to receive -* filesystem events when those events happens to this dentry->d_inode. -*/ -static inline void fsnotify_update_flags (struct dentry *dentry) -{ -assert_spin_locked (&dentry->d_lock); - -/* -* Serialisation of setting PARENT_WATCHED on the dentries is provided -* by d_lock. If inotify_inode_watched changes after we have taken -* d_lock, the following fsnotify_set_children_dentry_flags call will -* find our entry, so it will spin until we complete here, and update -* us with the new state. -*/ -if (fsnotify_inode_watches_children (dentry->d_parent->d_inode)) - dentry->d_flags |=DCACHE_FSNOTIFY_PARENT_WATCHED ; -else - dentry->d_flags &= ~DCACHE_FSNOTIFY_PARENT_WATCHED ; -} -/* called from fsnotify listeners, such as fanotify or dnotify */ /* create a new group */
@@ -943,6 +922,11 @@ static inline int __fsnotify_parent(struct dentry *dentry, __u32 mask,return 0 ; } +static inline int fsnotify_inode_watches_children (struct inode *inode) +{ +return 0 ; +} +static inline void __fsnotify_inode_delete (struct inode *inode) {}
@@ -958,9 +942,6 @@ static inline void __fsnotify_mntns_delete(struct mnt_namespace *mntns)static inline void fsnotify_sb_free (struct super_block *sb) {} -static inline void fsnotify_update_flags (struct dentry *dentry) -{} -static inline u32 fsnotify_get_cookie (void ) {return 0 ;
Jan Kara
maintainerQuoted 4 lines · Partha Sarathi Satapathy
This patch removes the cached-child dentry walk performed when a directory first starts watching child events. Instead, the event path takes a reference to the parent dentry and checks its child-watch mask. It also removes the
DCACHE_FSNOTIFY_PARENT_WATCHEDflag and its update sites.
If we can get rid of it, it would be a nice simplification but I have doubts this is feasible.
Quoted 10 lines
On the test host, 12 million files were populated and their positive dentries were warmed before each run. With eight concurrent unlink/recreate workers and 100 sole-watch add/close cycles,
inotify_add_watch()measured:Before After
run 1 average 107.420 ms 0.004 ms run 2 average 125.433 ms 0.004 ms run 1 maximum 122.811 ms 0.113 ms run 2 maximum 141.198 ms 0.095 ms
Quoted 5 lines
The displayed 0.004 ms averages are rounded to three decimal places. Maximum unlink/recreate latency was 777.852 and 770.569 ms before, versus 8.525 and 15.624 ms after. Those mutation maxima are supporting observations:
workers ran only during the watch-add loops, so the pre-change and post-change mutation measurement windows had very different lengths.
This looks good and is kind of expected. We don't have to traverse the huge children list.
Quoted 18 lines
One 100,000-iteration, single-worker open/close event-path run per mode gave:
Before After
none: p50/p99 ns 9564 / 15703 9684 / 15023 throughput 102221 ops/s 101432 ops/s other: p50/p99 ns 9554 / 15573 9684 / 14962 throughput 99442 ops/s 101497 ops/sparent: p50/p99 ns 12529 / 19179 12499 / 17716
throughput 78196 ops/s 78655 ops/sThe 'other' mode watches a different directory on the same filesystem, so it exercises the superblock watcher path without target-file event delivery. These are single runs; they do not establish a small event-path cost or its absence. No open/close regression is apparent at this measurement resolution. The test used worker CPU 2 and listener CPU 4 on kernels 6.19.0-rc8.V_fsn0.el9.omm0.x86_64 and 6.19.0-rc8.fsn3.el9.omm3.x86_64, respectively. The test host reported XFS for its working directory.
Quoted 3 lines
The inotify correctness test and broader fsnotify functional test passed on both kernels. The fanotify permission subtest skipped with EPERM in both runs, so
FAN_OPEN_PERMremains unvalidated by these results.
This isn't a load for which the DCACHE_FSNOTIFY_PARENT_WATCHED optimization is that interesting. Try the following:
Create a directory on tmpfs with say 1024 files, each 4k large. Place IN_MODIFY inotify watch on the directory.
Start X clients (where X can be 1,2,4,8,...,1024 to see the scaling)
The client will open the file based on its number (so different clients work on different file)
Do 1000000 writes of 1 byte at offset 0 to the file => measure time for
this
Close the file
I would bet you would see the difference already at 1 client and as the number of clients grows and the cacheline contention on the parent's refcount increases, it will get progressively worse. In particular if you try on a NUMA machine where the cacheline will ping-pong across NUMA nodes.
We've got performance regression reports for similar loads already when we added one cacheline load to fsnotify_parent(). Doing the "grab parent refcount" dance is much more expensive than that.
Honza
Quoted 12 lines
Partha Sarathi Satapathy (1):
fsnotify: Check parent watches without child dentry flagsfs/dcache.c | 4 -- fs/notify/fsnotify.c | 99 ++++++++------------------------ fs/notify/fsnotify.h | 6 -- fs/notify/mark.c | 35 ----------- include/linux/dcache.h | 1 - include/linux/fsnotify.h | 7 +-- include/linux/fsnotify_backend.h | 29 ++-------- 7 files changed, 29 insertions(+), 152 deletions(-)
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [External] : Re: [PATCH 0/1] fsnotify: Check parent watches without child dentry flags
Quoted 67 lines · Jan Kara
Quoted 4 lines · Partha Sarathi Satapathy
This patch removes the cached-child dentry walk performed when a directory first starts watching child events. Instead, the event path takes a reference to the parent dentry and checks its child-watch mask. It also removes the
DCACHE_FSNOTIFY_PARENT_WATCHEDflag and its update sites.If we can get rid of it, it would be a nice simplification but I have doubts this is feasible.
Quoted 10 lines
On the test host, 12 million files were populated and their positive dentries were warmed before each run. With eight concurrent unlink/recreate workers and 100 sole-watch add/close cycles,
inotify_add_watch()measured:Before After
run 1 average 107.420 ms 0.004 ms run 2 average 125.433 ms 0.004 ms run 1 maximum 122.811 ms 0.113 ms run 2 maximum 141.198 ms 0.095 msQuoted 5 lines
The displayed 0.004 ms averages are rounded to three decimal places. Maximum unlink/recreate latency was 777.852 and 770.569 ms before, versus 8.525 and 15.624 ms after. Those mutation maxima are supporting observations:
workers ran only during the watch-add loops, so the pre-change and post-change mutation measurement windows had very different lengths.This looks good and is kind of expected. We don't have to traverse the huge children list.
Quoted 18 lines
One 100,000-iteration, single-worker open/close event-path run per mode gave:
Before After
none: p50/p99 ns 9564 / 15703 9684 / 15023 throughput 102221 ops/s 101432 ops/s other: p50/p99 ns 9554 / 15573 9684 / 14962 throughput 99442 ops/s 101497 ops/sparent: p50/p99 ns 12529 / 19179 12499 / 17716
throughput 78196 ops/s 78655 ops/sThe 'other' mode watches a different directory on the same filesystem, so it exercises the superblock watcher path without target-file event delivery. These are single runs; they do not establish a small event-path cost or its absence. No open/close regression is apparent at this measurement resolution. The test used worker CPU 2 and listener CPU 4 on kernels 6.19.0-rc8.V_fsn0.el9.omm0.x86_64 and 6.19.0-rc8.fsn3.el9.omm3.x86_64, respectively. The test host reported XFS for its working directory.
Quoted 3 lines
The inotify correctness test and broader fsnotify functional test passed on both kernels. The fanotify permission subtest skipped with EPERM in both runs, so
FAN_OPEN_PERMremains unvalidated by these results.This isn't a load for which the
DCACHE_FSNOTIFY_PARENT_WATCHEDoptimization is that interesting. Try the following:Create a directory on tmpfs with say 1024 files, each 4k large. Place
IN_MODIFYinotify watch on the directory.
Start X clients (where X can be 1,2,4,8,...,1024 to see the scaling)
The client will open the file based on its number (so different clients work on different file)
Do 1000000 writes of 1 byte at offset 0 to the file => measure time for
this
Close the fileI would bet you would see the difference already at 1 client and as the number of clients grows and the cacheline contention on the parent's refcount increases, it will get progressively worse. In particular if you try on a NUMA machine where the cacheline will ping-pong across NUMA nodes.
Quoted 6 lines
We've got performance regression reports for similar loads already when we added one cacheline load to
fsnotify_parent(). Doing the "grab parent refcount" dance is much more expensive than that.Honza
Hi Honza,
Thanks for suggesting this workload.
The setup and before/after timing comparisons are below.
Architecture: x86_64 CPU(s): 512
On-line CPU(s) list: 0-511
NUMA:
NUMA node(s): 2 NUMA node0 CPU(s): 0-127,256-383 NUMA node1 CPU(s): 128-255,384-511
Testcase :
Using /dev/shm tmpfs to create private test directory.
Create 1,024 files each fully populated with 4kb.
Add IN_MODIFY inotify watch to the directory.
Start a listener thread to read notifications and count queue overflows. Start X(1,2,4..1024) client threads; each opens a different file once. Wait until every client is ready, then release them together. Each client starts its timer and performs 1000000
one-byte pwrite() at offset0 on its own file.
Each client stops its timer and closes its file.
Wait for all clients to finish, drain remaining notifications, and stop the listener.
Print write times, throughput, notification count, and queue-overflow count. Close inotify and delete the test files and directory.
Note : File creation, open, close, and cleanup are outside the timed write loops.
Run 1:
-------
| Clients | Before average time | After average time | Time change | |---:|---:|---:|---:| | 1 | 1.392 s | 1.484 s | +6.6% | | 2 | 2.205 s | 2.402 s | +8.9% | | 4 | 3.969 s | 3.644 s | −8.2% | | 8 | 5.851 s | 5.804 s | −0.8% | | 16 | 10.607 s | 11.538 s | +8.8% | | 32 | 21.093 s | 22.492 s | +6.6% | | 64 | 48.698 s | 49.576 s | +1.8% | | 128 | 100.208 s | 100.467 s | +0.3% | | 256 | 198.773 s | 197.669 s | −0.6% | | 512 | 400.056 s | 399.550 s | −0.1% |
Run2 :
--------
| Clients | Before average time | After average time | Time change | |---:|---:|---:|---:| | 1 | 1.491 s | 1.484 s | −0.4% | | 2 | 2.391 s | 2.402 s | +0.5% | | 4 | 4.050 s | 3.644 s | −10.0% | | 8 | 6.630 s | 5.804 s | −12.5% | | 16 | 11.931 s | 11.538 s | −3.3% | | 32 | 22.513 s | 22.492 s | −0.1% | | 64 | 50.231 s | 49.576 s | −1.3% | | 128 | 100.699 s | 100.467 s | −0.2% | | 256 | 198.771 s | 197.669 s | −0.6% | | 512 | 401.860 s | 399.550 s | −0.6% | | 1,024 | 803.812 s | 806.593 s | +0.3% |
Positive means After Fix took longer; negative means faster.
The measured write performance is broadly comparable before and after the fix, with no consistent substantial regression or progressively worsening slowdown as concurrency increases.
The differences vary between baseline batches: the increases at 16 and 32 clients in the first comparison disappear or reverse in the second. At 128–1024 clients, average write times differ by approximately 0.6% or less. These shifts are consistent with run-to-run variation; the results do not show a persistent substantial slowdown from the fix.
Thanks,
Partha
Quoted 16 lines
Quoted 12 lines
Partha Sarathi Satapathy (1):
fsnotify: Check parent watches without child dentry flagsfs/dcache.c | 4 -- fs/notify/fsnotify.c | 99 ++++++++------------------------ fs/notify/fsnotify.h | 6 -- fs/notify/mark.c | 35 ----------- include/linux/dcache.h | 1 - include/linux/fsnotify.h | 7 +-- include/linux/fsnotify_backend.h | 29 ++-------- 7 files changed, 29 insertions(+), 152 deletions(-)Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jan Kara
maintainerRe: [External] : Re: [PATCH 0/1] fsnotify: Check parent watches without child dentry flags
Quoted 74 lines · Partha Satapathy
Hi Honza,
Thanks for suggesting this workload.
The setup and before/after timing comparisons are below.Architecture: x86_64 CPU(s): 512On-line CPU(s) list: 0-511
NUMA:
NUMA node(s): 2 NUMA node0 CPU(s): 0-127,256-383 NUMA node1 CPU(s): 128-255,384-511Testcase :
Using/dev/shmtmpfs to create private test directory.
Create 1,024 files each fully populated with 4kb.
AddIN_MODIFYinotify watch to the directory.
Start a listener thread to read notifications and count queue overflows. StartX(1,2,4..1024)client threads; each opens a different file once. Wait until every client is ready, then release them together. Each client starts its timer and performs 1000000
one-bytepwrite()at offset0 on its own file.
Each client stops its timer and closes its file.
Wait for all clients to finish, drain remaining notifications, and stop the listener.
Print write times, throughput, notification count, and queue-overflow count. Close inotify and delete the test files and directory.Note : File creation, open, close, and cleanup are outside the timed write loops.
Run 1:
-------| Clients | Before average time | After average time | Time change | |---:|---:|---:|---:| | 1 | 1.392 s | 1.484 s | +6.6% | | 2 | 2.205 s | 2.402 s | +8.9% | | 4 | 3.969 s | 3.644 s | −8.2% | | 8 | 5.851 s | 5.804 s | −0.8% | | 16 | 10.607 s | 11.538 s | +8.8% | | 32 | 21.093 s | 22.492 s | +6.6% | | 64 | 48.698 s | 49.576 s | +1.8% | | 128 | 100.208 s | 100.467 s | +0.3% | | 256 | 198.773 s | 197.669 s | −0.6% | | 512 | 400.056 s | 399.550 s | −0.1% |Run2 :
--------| Clients | Before average time | After average time | Time change | |---:|---:|---:|---:| | 1 | 1.491 s | 1.484 s | −0.4% | | 2 | 2.391 s | 2.402 s | +0.5% | | 4 | 4.050 s | 3.644 s | −10.0% | | 8 | 6.630 s | 5.804 s | −12.5% | | 16 | 11.931 s | 11.538 s | −3.3% | | 32 | 22.513 s | 22.492 s | −0.1% | | 64 | 50.231 s | 49.576 s | −1.3% | | 128 | 100.699 s | 100.467 s | −0.2% | | 256 | 198.771 s | 197.669 s | −0.6% | | 512 | 401.860 s | 399.550 s | −0.6% | | 1,024 | 803.812 s | 806.593 s | +0.3% |Positive means After Fix took longer; negative means faster.
The measured write performance is broadly comparable before and after the fix, with no consistent substantial regression or progressively worsening slowdown as concurrency increases.
Quoted 5 lines
The differences vary between baseline batches: the increases at 16 and 32 clients in the first comparison disappear or reverse in the second. At 128–1024 clients, average write times differ by approximately 0.6% or less. These shifts are consistent with run-to-run variation; the results do not show a persistent substantial slowdown from the fix.
Thanks for running these tests. Results are very interesting. Can you please share your benchmarking program with me? I'll check it and try to play with it on my end. Thanks!
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [External] : Re: [PATCH 0/1] fsnotify: Check parent watches without child dentry flags
Quoted 81 lines · Jan Kara
Quoted 74 lines · Partha Satapathy
Hi Honza,
Thanks for suggesting this workload.
The setup and before/after timing comparisons are below.Architecture: x86_64 CPU(s): 512On-line CPU(s) list: 0-511
NUMA:
NUMA node(s): 2 NUMA node0 CPU(s): 0-127,256-383 NUMA node1 CPU(s): 128-255,384-511Testcase :
Using/dev/shmtmpfs to create private test directory.
Create 1,024 files each fully populated with 4kb.
AddIN_MODIFYinotify watch to the directory.
Start a listener thread to read notifications and count queue overflows. StartX(1,2,4..1024)client threads; each opens a different file once. Wait until every client is ready, then release them together. Each client starts its timer and performs 1000000
one-bytepwrite()at offset0 on its own file.
Each client stops its timer and closes its file.
Wait for all clients to finish, drain remaining notifications, and stop the listener.
Print write times, throughput, notification count, and queue-overflow count. Close inotify and delete the test files and directory.Note : File creation, open, close, and cleanup are outside the timed write loops.
Run 1:
-------| Clients | Before average time | After average time | Time change | |---:|---:|---:|---:| | 1 | 1.392 s | 1.484 s | +6.6% | | 2 | 2.205 s | 2.402 s | +8.9% | | 4 | 3.969 s | 3.644 s | −8.2% | | 8 | 5.851 s | 5.804 s | −0.8% | | 16 | 10.607 s | 11.538 s | +8.8% | | 32 | 21.093 s | 22.492 s | +6.6% | | 64 | 48.698 s | 49.576 s | +1.8% | | 128 | 100.208 s | 100.467 s | +0.3% | | 256 | 198.773 s | 197.669 s | −0.6% | | 512 | 400.056 s | 399.550 s | −0.1% |Run2 :
--------| Clients | Before average time | After average time | Time change | |---:|---:|---:|---:| | 1 | 1.491 s | 1.484 s | −0.4% | | 2 | 2.391 s | 2.402 s | +0.5% | | 4 | 4.050 s | 3.644 s | −10.0% | | 8 | 6.630 s | 5.804 s | −12.5% | | 16 | 11.931 s | 11.538 s | −3.3% | | 32 | 22.513 s | 22.492 s | −0.1% | | 64 | 50.231 s | 49.576 s | −1.3% | | 128 | 100.699 s | 100.467 s | −0.2% | | 256 | 198.771 s | 197.669 s | −0.6% | | 512 | 401.860 s | 399.550 s | −0.6% | | 1,024 | 803.812 s | 806.593 s | +0.3% |Positive means After Fix took longer; negative means faster.
The measured write performance is broadly comparable before and after the fix, with no consistent substantial regression or progressively worsening slowdown as concurrency increases.
Quoted 5 lines
The differences vary between baseline batches: the increases at 16 and 32 clients in the first comparison disappear or reverse in the second. At 128–1024 clients, average write times differ by approximately 0.6% or less. These shifts are consistent with run-to-run variation; the results do not show a persistent substantial slowdown from the fix.
Quoted 9 lines
Thanks for running these tests. Results are very interesting. Can you please share your benchmarking program with me? I'll check it and try to play with it on my end. Thanks!
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
$ cat run_parent_ref_scale.sh #!/usr/bin/env bash set -u -o pipefail
bench=./fsnotify_parent_ref_bench
if [[ ! -x "$bench" ]]; then
printf 'Build %s in the current directory first.\n' "$bench" >&2 exit 1
fi
results_dir=$(mktemp -d ./parent-ref-results-XXXXXXXX) || exit 1 printf 'kernel=%s\nbenchmark=%s\ntmpfs=/dev/shm\nwrites_per_client=1000000\nmode=watch\n'
\
"$(uname -r)" "$bench" > "$results_dir/run-info.txt"printf 'Results: %s\n' "$results_dir"
for i in 1 2 3 4 5; do
for clients in 1 2 4 8 16 32 64 128 256 512 1024; do
log="$results_dir/clients-${clients}.log"
printf '\n=== clients=%d ===\n' "$clients"
"$bench" /dev/shm "$clients" 1000000 watch 2>&1 | tee "$log"
status=${PIPESTATUS[0]}
printf 'exit_status=%d\n' "$status" | tee -a "$log"done
done
printf '\nAll results saved in %s\n' "$results_dir"
$ cat fsnotify_parent_ref_bench.c #define _GNU_SOURCE #include <errno.h> #include <fcntl.h> #include <inttypes.h> #include <limits.h> #include <poll.h> #include <pthread.h> #include <stdatomic.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/inotify.h> #include <sys/stat.h> #include <sys/statfs.h> #include <time.h> #include <unistd.h> #include <linux/magic.h>
#define FILES 1024
#define FILE_SIZE 4096
#define DEFAULT_WRITES 1000000UL
struct gate {
pthread_mutex_t mutex;
pthread_cond_t cond;
unsigned int ready;
bool start;
bool abort;
};struct worker {
char path[PATH_MAX];
unsigned long writes;
unsigned int id;
struct gate *gate;
uint64_t begin_ns;
uint64_t end_ns;
int error;
};struct listener {
int fd;
atomic_bool stop;
uint64_t events;
uint64_t overflows;
int error;
};static uint64_t now_ns(void)
{
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts)) {
perror("clock_gettime");
exit(EXIT_FAILURE);
}
return (uint64_t)ts.tv_sec * 1000000000ULL + ts.tv_nsec;
}static unsigned long parse_count(const char *s, const char *name)
{
char *end;
unsigned long value;
errno = 0;
value = strtoul(s, &end, 10);
if (errno || !*s || *end || !value) {
fprintf(stderr, "Invalid %s: %s\n", name, s);
exit(EXIT_FAILURE);
}
return value;
}static void file_path(char *out, size_t size, const char *dir, unsigned int i)
{
int n = snprintf(out, size, "%s/file-%04u", dir, i);
if (n < 0 || (size_t)n >= size) {
fputs("File path is too long\n", stderr);
exit(EXIT_FAILURE);
}
}static void *run_worker(void *arg)
{
struct worker *w = arg;
int fd;
char byte = (char)w->id;
unsigned long i;
bool abort;
fd = open(w->path, O_WRONLY | O_CLOEXEC);
if (fd < 0)
w->error = errno;
pthread_mutex_lock(&w->gate->mutex);
w->gate->ready++;
pthread_cond_broadcast(&w->gate->cond);
while (!w->gate->start)
pthread_cond_wait(&w->gate->cond, &w->gate->mutex);
abort = w->gate->abort;
pthread_mutex_unlock(&w->gate->mutex);
if (abort || w->error)
goto out;
w->begin_ns = now_ns();
for (i = 0; i < w->writes; i++) {
if (pwrite(fd, &byte, 1, 0) != 1) {
w->error = errno ? errno : EIO;
break;
}
}
w->end_ns = now_ns();
out:
if (fd >= 0 && close(fd) && !w->error)
w->error = errno;
return NULL;
}static void *drain_events(void *arg)
{
struct listener *l = arg;
char buf[65536] __attribute__((aligned(8)));
struct pollfd pfd = { .fd = l->fd, .events = POLLIN };
for (;;) {
int ready = poll(&pfd, 1, atomic_load(&l->stop) ? 0 : 50);
if (ready < 0) {
if (errno == EINTR)
continue;
l->error = errno;
break;
}
if (!ready) {
if (atomic_load(&l->stop))
break;
continue;
}
for (;;) {
ssize_t len = read(l->fd, buf, sizeof(buf));
size_t pos = 0;
if (len < 0) {
if (errno == EINTR)
continue;
if (errno == EAGAIN)
break;
l->error = errno;
return NULL;
}
while (pos + sizeof(struct inotify_event) <=
(size_t)len) {
struct inotify_event *ev =
(struct inotify_event *)(buf + pos);
size_t step = sizeof(*ev) + ev->len;
if (step > (size_t)len - pos) {
l->error = EPROTO;
return NULL;
}
l->events++;
if (ev->mask & IN_Q_OVERFLOW)
l->overflows++;
pos += step;
}
if (pos != (size_t)len) {
l->error = EPROTO;
return NULL;
}
}
}
return NULL;
}static void cleanup(const char *dir)
{
char path[PATH_MAX];
unsigned int i;
for (i = 0; i < FILES; i++) {
file_path(path, sizeof(path), dir, i);
if (unlink(path) && errno != ENOENT)
perror(path);
}
if (rmdir(dir))
perror(dir);
}int main(int argc, char **argv)
{
char dir[PATH_MAX], path[PATH_MAX];
unsigned long writes = DEFAULT_WRITES;
unsigned long count;
unsigned int clients, i, created = 0;
struct statfs fs;
struct gate gate = {
.mutex = PTHREAD_MUTEX_INITIALIZER,
.cond = PTHREAD_COND_INITIALIZER,
};
struct listener listener = { .fd = -1 };
struct worker *workers;
pthread_t *threads, listener_thread;
bool watched = true, listener_started = false;
uint64_t first = UINT64_MAX, last = 0, sum = 0;
uint64_t shortest = UINT64_MAX, longest = 0;
char zeroes[FILE_SIZE] = { 0 };
int rc = EXIT_FAILURE, err;
if (argc < 3 || argc > 5) {
fprintf(stderr, "Usage: %s TMPFS_ROOT CLIENTS
[WRITES_PER_CLIENT] [watch|none]\n", argv[0]);
return rc;
}
clients = parse_count(argv[2], "clients");
if (clients > FILES) {
fprintf(stderr, "Clients must be at most %d\n", FILES);
return rc;
}
if (argc > 3)
writes = parse_count(argv[3], "writes per client");
if (writes > ULONG_MAX / clients) {
fputs("Total write count is too large\n", stderr);
return rc;
}
if (argc > 4) {
if (!strcmp(argv[4], "none"))
watched = false;
else if (strcmp(argv[4], "watch")) {
fputs("Mode must be watch or none\n", stderr);
return rc;
}
}
if (statfs(argv[1], &fs)) {
perror(argv[1]);
return rc;
}
if (fs.f_type != TMPFS_MAGIC) {
fprintf(stderr, "%s must be a tmpfs directory\n", argv[1]);
return rc;
}
if (snprintf(dir, sizeof(dir), "%s/fsnotify-parent-ref-XXXXXX",
argv[1]) >=
(int)sizeof(dir) || !mkdtemp(dir)) {
perror("mkdtemp");
return rc;
}
workers = calloc(clients, sizeof(*workers));
threads = calloc(clients, sizeof(*threads));
if (!workers || !threads) {
fputs("Cannot allocate worker state\n", stderr);
goto out;
}
for (i = 0; i < FILES; i++) {
int fd;
file_path(path, sizeof(path), dir, i);
fd = open(path, O_CREAT | O_EXCL | O_WRONLY | O_CLOEXEC,
0600);
if (fd < 0) {
perror(path);
goto out;
}
/* Allocate the tmpfs page before the measured write
loop. */
if (write(fd, zeroes, sizeof(zeroes)) != sizeof(zeroes)) {
perror(path);
close(fd);
goto out;
}
if (close(fd)) {
perror(path);
goto out;
}
}
if (watched) {
listener.fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
if (listener.fd < 0 ||
inotify_add_watch(listener.fd, dir, IN_MODIFY) < 0) {
perror("inotify watch");
goto out;
}
err = pthread_create(&listener_thread, NULL,
drain_events, &listener);
if (err) {
errno = err;
perror("listener thread");
goto out;
}
listener_started = true;
}
for (i = 0; i < clients; i++) {
workers[i].id = i;
workers[i].writes = writes;
workers[i].gate = &gate;
file_path(workers[i].path, sizeof(workers[i].path), dir, i);
err = pthread_create(&threads[i], NULL, run_worker,
&workers[i]);
if (err) {
errno = err;
perror("worker thread");
gate.abort = true;
goto release;
}
created++;
}
pthread_mutex_lock(&gate.mutex);
while (gate.ready < clients)
pthread_cond_wait(&gate.cond, &gate.mutex);
pthread_mutex_unlock(&gate.mutex);
for (i = 0; i < clients; i++) {
if (workers[i].error) {
fprintf(stderr, "Worker %u open: %s\n", i,
strerror(workers[i].error));
gate.abort = true;
break;
}
}
printf("test_dir=%s files=%d file_size=%d clients=%u
writes_per_client=%lu mode=%s\n",
dir, FILES, FILE_SIZE, clients, writes,
watched ? "watch" : "none");
fflush(stdout);
release:
pthread_mutex_lock(&gate.mutex);
gate.start = true;
pthread_cond_broadcast(&gate.cond);
pthread_mutex_unlock(&gate.mutex);
for (i = 0; i < created; i++)
pthread_join(threads[i], NULL);
if (listener_started) {
atomic_store(&listener.stop, true);
pthread_join(listener_thread, NULL);
printf("inotify_events=%" PRIu64 " queue_overflows=%"PRIu64 "\n",
listener.events, listener.overflows);
if (listener.error)
fprintf(stderr, "Inotify listener: %s\n",
strerror(listener.error));
if (listener.overflows)
fputs("Inotify queue overflowed; event delivery
load changed during the run\n", stderr);
}
if (gate.abort || listener.error)
goto out;
for (i = 0; i < clients; i++) {
uint64_t duration;
if (workers[i].error) {
fprintf(stderr, "Worker %u write: %s\n", i,
strerror(workers[i].error));
goto out;
}
duration = workers[i].end_ns - workers[i].begin_ns;
if (workers[i].begin_ns < first)
first = workers[i].begin_ns;
if (workers[i].end_ns > last)
last = workers[i].end_ns;
if (duration < shortest)
shortest = duration;
if (duration > longest)
longest = duration;
sum += duration;
}
count = (unsigned long)clients * writes;
printf("total_writes=%lu wall_seconds=%.6f
throughput_writes_per_sec=%.0f mean_worker_ns_per_write=%.1f
shortest_worker_seconds=%.6f longest_worker_seconds=%.6f\n",
count, (last - first) / 1e9, count * 1e9 / (last - first),
(double)sum / count, shortest / 1e9, longest / 1e9);
printf("result=%s\n", listener.overflows ? "QUEUE_OVERFLOW" :
"PASS");
rc = listener.overflows ? EXIT_FAILURE : EXIT_SUCCESS;
out:
if (listener.fd >= 0)
close(listener.fd);
cleanup(dir);
free(workers);
free(threads);
return rc;
}Please compile : fsnotify_parent_ref_bench.c -ofsnotify_parent_ref_bench. After that
run the script ./run_parent_ref_scale.sh
Thanks
Partha
Re: [External] : Re: [PATCH 0/1] fsnotify: Check parent watches without child dentry flags
Quoted 509 lines · Partha Satapathy
Quoted 81 lines · Jan Kara
Quoted 74 lines · Partha Satapathy
Hi Honza,
Thanks for suggesting this workload.
The setup and before/after timing comparisons are below.Architecture: x86_64 CPU(s): 512On-line CPU(s) list: 0-511
NUMA:
NUMA node(s): 2 NUMA node0 CPU(s): 0-127,256-383 NUMA node1 CPU(s): 128-255,384-511Testcase :
Using/dev/shmtmpfs to create private test directory.
Create 1,024 files each fully populated with 4kb.
AddIN_MODIFYinotify watch to the directory.
Start a listener thread to read notifications and count queue overflows. StartX(1,2,4..1024)client threads; each opens a different file once. Wait until every client is ready, then release them together. Each client starts its timer and performs 1000000
one-bytepwrite()at offset0 on its own file.
Each client stops its timer and closes its file.
Wait for all clients to finish, drain remaining notifications, and stop the listener.
Print write times, throughput, notification count, and queue-overflow count. Close inotify and delete the test files and directory.Note : File creation, open, close, and cleanup are outside the timed write loops.
Run 1:
-------| Clients | Before average time | After average time | Time change | |---:|---:|---:|---:| | 1 | 1.392 s | 1.484 s | +6.6% | | 2 | 2.205 s | 2.402 s | +8.9% | | 4 | 3.969 s | 3.644 s | −8.2% | | 8 | 5.851 s | 5.804 s | −0.8% | | 16 | 10.607 s | 11.538 s | +8.8% | | 32 | 21.093 s | 22.492 s | +6.6% | | 64 | 48.698 s | 49.576 s | +1.8% | | 128 | 100.208 s | 100.467 s | +0.3% | | 256 | 198.773 s | 197.669 s | −0.6% | | 512 | 400.056 s | 399.550 s | −0.1% |Run2 :
--------| Clients | Before average time | After average time | Time change | |---:|---:|---:|---:| | 1 | 1.491 s | 1.484 s | −0.4% | | 2 | 2.391 s | 2.402 s | +0.5% | | 4 | 4.050 s | 3.644 s | −10.0% | | 8 | 6.630 s | 5.804 s | −12.5% | | 16 | 11.931 s | 11.538 s | −3.3% | | 32 | 22.513 s | 22.492 s | −0.1% | | 64 | 50.231 s | 49.576 s | −1.3% | | 128 | 100.699 s | 100.467 s | −0.2% | | 256 | 198.771 s | 197.669 s | −0.6% | | 512 | 401.860 s | 399.550 s | −0.6% | | 1,024 | 803.812 s | 806.593 s | +0.3% |Positive means After Fix took longer; negative means faster.
The measured write performance is broadly comparable before and after the fix, with no consistent substantial regression or progressively worsening slowdown as concurrency increases.
Quoted 5 lines
The differences vary between baseline batches: the increases at 16 and 32 clients in the first comparison disappear or reverse in the second. At 128–1024 clients, average write times differ by approximately 0.6% or less. These shifts are consistent with run-to-run variation; the results do not show a persistent substantial slowdown from the fix.
Quoted 9 lines
Thanks for running these tests. Results are very interesting. Can you please share your benchmarking program with me? I'll check it and try to play with it on my end. Thanks!
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR$ cat run_parent_ref_scale.sh #!/usr/bin/env bash set -u -o pipefailbench=./fsnotify_parent_ref_bench
if [[ ! -x "$bench" ]]; then
printf 'Build %s in the current directory first.\n' "$bench" >&2 exit 1
firesults_dir=$(mktemp -d ./parent-ref-results-XXXXXXXX) || exit 1 printf 'kernel=%s\nbenchmark=%s\ntmpfs=/dev/shm\nwrites_per_client=1000000\nmode=watch\n'
\ "$(uname -r)" "$bench" > "$results_dir/run-info.txt"printf 'Results: %s\n' "$results_dir"
for i in 1 2 3 4 5; do
for clients in 1 2 4 8 16 32 64 128 256 512 1024; dolog="$results_dir/clients-${clients}.log" printf '\n=== clients=%d ===\n' "$clients" "$bench" /dev/shm "$clients" 1000000 watch 2>&1 | tee "$log" status=${PIPESTATUS[0]} printf 'exit_status=%d\n' "$status" | tee -a "$log"done
doneprintf '\nAll results saved in %s\n' "$results_dir"
$ cat fsnotify_parent_ref_bench.c #define _GNU_SOURCE #include <errno.h> #include <fcntl.h> #include <inttypes.h> #include <limits.h> #include <poll.h> #include <pthread.h> #include <stdatomic.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/inotify.h> #include <sys/stat.h> #include <sys/statfs.h> #include <time.h> #include <unistd.h> #include <linux/magic.h>#define FILES 1024
#defineFILE_SIZE4096
#defineDEFAULT_WRITES1000000ULstruct gate { pthread_mutex_t mutex; pthread_cond_t cond; unsigned int ready; bool start; bool abort; };struct worker { char path[PATH_MAX]; unsigned long writes; unsigned int id; struct gate *gate; uint64_t begin_ns; uint64_t end_ns; int error; };struct listener { int fd; atomic_bool stop; uint64_t events; uint64_t overflows; int error; };static
uint64_tnow_ns(void){ struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts)) { perror("clock_gettime"); exit(EXIT_FAILURE); } return (uint64_t)ts.tv_sec * 1000000000ULL + ts.tv_nsec; }static unsigned long
parse_count(const char *s, const char *name){ char *end; unsigned long value; errno = 0; value = strtoul(s, &end, 10); if (errno || !*s || *end || !value) { fprintf(stderr, "Invalid %s: %s\n", name, s); exit(EXIT_FAILURE); } return value; }static void
file_path(char *out, size_t size, const char *dir, unsigned int i){ int n = snprintf(out, size, "%s/file-%04u", dir, i); if (n < 0 || (size_t)n >= size) { fputs("File path is too long\n", stderr); exit(EXIT_FAILURE); } }static void *run_worker(void *arg)
{ struct worker *w = arg; int fd; char byte = (char)w->id; unsigned long i; bool abort; fd = open(w->path, O_WRONLY | O_CLOEXEC); if (fd < 0) w->error = errno; pthread_mutex_lock(&w->gate->mutex); w->gate->ready++; pthread_cond_broadcast(&w->gate->cond); while (!w->gate->start) pthread_cond_wait(&w->gate->cond, &w->gate->mutex); abort = w->gate->abort; pthread_mutex_unlock(&w->gate->mutex); if (abort || w->error) goto out; w->begin_ns = now_ns(); for (i = 0; i < w->writes; i++) { if (pwrite(fd, &byte, 1, 0) != 1) { w->error = errno ? errno : EIO; break; } } w->end_ns = now_ns(); out: if (fd >= 0 && close(fd) && !w->error) w->error = errno; return NULL; }static void *drain_events(void *arg)
{ struct listener *l = arg; char buf[65536] __attribute__((aligned(8))); struct pollfd pfd = { .fd = l->fd, .events = POLLIN }; for (;;) { int ready = poll(&pfd, 1, atomic_load(&l->stop) ? 0 : 50); if (ready < 0) { if (errno == EINTR) continue; l->error = errno; break; } if (!ready) { if (atomic_load(&l->stop)) break; continue; } for (;;) { ssize_t len = read(l->fd, buf, sizeof(buf)); size_t pos = 0; if (len < 0) { if (errno == EINTR) continue; if (errno == EAGAIN) break; l->error = errno; return NULL; } while (pos + sizeof(struct inotify_event) <= (size_t)len) { struct inotify_event *ev = (struct inotify_event *)(buf + pos); size_t step = sizeof(*ev) + ev->len; if (step > (size_t)len - pos) { l->error = EPROTO; return NULL; } l->events++; if (ev->mask & IN_Q_OVERFLOW) l->overflows++; pos += step; } if (pos != (size_t)len) { l->error = EPROTO; return NULL; } } } return NULL; }static void
cleanup(const char *dir){ char path[PATH_MAX]; unsigned int i; for (i = 0; i < FILES; i++) { file_path(path, sizeof(path), dir, i); if (unlink(path) && errno != ENOENT) perror(path); } if (rmdir(dir)) perror(dir); }int
main(int argc, char **argv){ char dir[PATH_MAX], path[PATH_MAX]; unsigned long writes = DEFAULT_WRITES; unsigned long count; unsigned int clients, i, created = 0; struct statfs fs; struct gate gate = { .mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, }; struct listener listener = { .fd = -1 }; struct worker *workers; pthread_t *threads, listener_thread; bool watched = true, listener_started = false; uint64_t first = UINT64_MAX, last = 0, sum = 0; uint64_t shortest = UINT64_MAX, longest = 0; char zeroes[FILE_SIZE] = { 0 }; int rc = EXIT_FAILURE, err; if (argc < 3 || argc > 5) { fprintf(stderr, "Usage: %s TMPFS_ROOT CLIENTS [WRITES_PER_CLIENT] [watch|none]\n", argv[0]); return rc; } clients = parse_count(argv[2], "clients"); if (clients > FILES) { fprintf(stderr, "Clients must be at most %d\n", FILES); return rc; } if (argc > 3) writes = parse_count(argv[3], "writes per client"); if (writes > ULONG_MAX / clients) { fputs("Total write count is too large\n", stderr); return rc; } if (argc > 4) { if (!strcmp(argv[4], "none")) watched = false; else if (strcmp(argv[4], "watch")) { fputs("Mode must be watch or none\n", stderr); return rc; } } if (statfs(argv[1], &fs)) { perror(argv[1]); return rc; } if (fs.f_type != TMPFS_MAGIC) { fprintf(stderr, "%s must be a tmpfs directory\n", argv[1]); return rc; } if (snprintf(dir, sizeof(dir), "%s/fsnotify-parent-ref-XXXXXX", argv[1]) >= (int)sizeof(dir) || !mkdtemp(dir)) { perror("mkdtemp"); return rc; } workers = calloc(clients, sizeof(*workers)); threads = calloc(clients, sizeof(*threads)); if (!workers || !threads) { fputs("Cannot allocate worker state\n", stderr); goto out; } for (i = 0; i < FILES; i++) { int fd; file_path(path, sizeof(path), dir, i); fd = open(path, O_CREAT | O_EXCL | O_WRONLY | O_CLOEXEC, 0600); if (fd < 0) { perror(path); goto out; } /* Allocate the tmpfs page before the measured write loop. */ if (write(fd, zeroes, sizeof(zeroes)) != sizeof(zeroes)) { perror(path); close(fd); goto out; } if (close(fd)) { perror(path); goto out; } } if (watched) { listener.fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC); if (listener.fd < 0 || inotify_add_watch(listener.fd, dir, IN_MODIFY) < 0) { perror("inotify watch"); goto out; } err = pthread_create(&listener_thread, NULL, drain_events, &listener); if (err) { errno = err; perror("listener thread"); goto out; } listener_started = true; } for (i = 0; i < clients; i++) { workers[i].id = i; workers[i].writes = writes; workers[i].gate = &gate; file_path(workers[i].path, sizeof(workers[i].path), dir, i); err = pthread_create(&threads[i], NULL, run_worker, &workers[i]); if (err) { errno = err; perror("worker thread"); gate.abort = true; goto release; } created++; } pthread_mutex_lock(&gate.mutex); while (gate.ready < clients) pthread_cond_wait(&gate.cond, &gate.mutex); pthread_mutex_unlock(&gate.mutex); for (i = 0; i < clients; i++) { if (workers[i].error) { fprintf(stderr, "Worker %u open: %s\n", i, strerror(workers[i].error)); gate.abort = true; break; } } printf("test_dir=%s files=%d file_size=%d clients=%u writes_per_client=%lu mode=%s\n", dir, FILES, FILE_SIZE, clients, writes, watched ? "watch" : "none"); fflush(stdout); release: pthread_mutex_lock(&gate.mutex); gate.start = true; pthread_cond_broadcast(&gate.cond); pthread_mutex_unlock(&gate.mutex); for (i = 0; i < created; i++) pthread_join(threads[i], NULL); if (listener_started) { atomic_store(&listener.stop, true); pthread_join(listener_thread, NULL); printf("inotify_events=%" PRIu64 " queue_overflows=%"PRIu64 "\n",
listener.events, listener.overflows);
if (listener.error)
fprintf(stderr, "Inotify listener: %s\n",
strerror(listener.error));
if (listener.overflows)
fputs("Inotify queue overflowed; event delivery
load changed during the run\n", stderr);} if (gate.abort || listener.error) goto out; for (i = 0; i < clients; i++) { uint64_t duration; if (workers[i].error) { fprintf(stderr, "Worker %u write: %s\n", i, strerror(workers[i].error)); goto out; } duration = workers[i].end_ns - workers[i].begin_ns; if (workers[i].begin_ns < first) first = workers[i].begin_ns; if (workers[i].end_ns > last) last = workers[i].end_ns; if (duration < shortest) shortest = duration; if (duration > longest) longest = duration; sum += duration; } count = (unsigned long)clients * writes; printf("total_writes=%lu wall_seconds=%.6f throughput_writes_per_sec=%.0f mean_worker_ns_per_write=%.1f shortest_worker_seconds=%.6f longest_worker_seconds=%.6f\n", count, (last - first) / 1e9, count * 1e9 / (last - first), (double)sum / count, shortest / 1e9, longest / 1e9); printf("result=%s\n", listener.overflows ? "QUEUE_OVERFLOW" : "PASS"); rc = listener.overflows ? EXIT_FAILURE : EXIT_SUCCESS; out: if (listener.fd >= 0) close(listener.fd); cleanup(dir); free(workers); free(threads); return rc; }
Quoted 6 lines
Please compile :
fsnotify_parent_ref_bench.c-ofsnotify_parent_ref_bench. After that
run the script ./run_parent_ref_scale.shThanks
Partha
Hi Honza,
A gentle ping on the benchmark program, Have you had a chance to try it on your setup? Please let me know if any further tests or information would be helpful.
Thanks,
Partha
Re: [External] : Re: [PATCH 0/1] fsnotify: Check parent watches without child dentry flags
Quoted 517 lines · Partha Satapathy
Quoted 509 lines · Partha Satapathy
Quoted 81 lines · Jan Kara
Quoted 74 lines · Partha Satapathy
Hi Honza,
Thanks for suggesting this workload.
The setup and before/after timing comparisons are below.Architecture: x86_64 CPU(s): 512On-line CPU(s) list: 0-511
NUMA:
NUMA node(s): 2 NUMA node0 CPU(s): 0-127,256-383 NUMA node1 CPU(s): 128-255,384-511Testcase :
Using/dev/shmtmpfs to create private test directory.
Create 1,024 files each fully populated with 4kb.
AddIN_MODIFYinotify watch to the directory.
Start a listener thread to read notifications and count queue overflows. StartX(1,2,4..1024)client threads; each opens a different file once. Wait until every client is ready, then release them together. Each client starts its timer and performs 1000000
one-bytepwrite()at offset0 on its own file.
Each client stops its timer and closes its file.
Wait for all clients to finish, drain remaining notifications, and stop the listener.
Print write times, throughput, notification count, and queue-overflow count. Close inotify and delete the test files and directory.Note : File creation, open, close, and cleanup are outside the timed write loops.
Run 1:
-------| Clients | Before average time | After average time | Time change | |---:|---:|---:|---:| | 1 | 1.392 s | 1.484 s | +6.6% | | 2 | 2.205 s | 2.402 s | +8.9% | | 4 | 3.969 s | 3.644 s | −8.2% | | 8 | 5.851 s | 5.804 s | −0.8% | | 16 | 10.607 s | 11.538 s | +8.8% | | 32 | 21.093 s | 22.492 s | +6.6% | | 64 | 48.698 s | 49.576 s | +1.8% | | 128 | 100.208 s | 100.467 s | +0.3% | | 256 | 198.773 s | 197.669 s | −0.6% | | 512 | 400.056 s | 399.550 s | −0.1% |Run2 :
--------| Clients | Before average time | After average time | Time change | |---:|---:|---:|---:| | 1 | 1.491 s | 1.484 s | −0.4% | | 2 | 2.391 s | 2.402 s | +0.5% | | 4 | 4.050 s | 3.644 s | −10.0% | | 8 | 6.630 s | 5.804 s | −12.5% | | 16 | 11.931 s | 11.538 s | −3.3% | | 32 | 22.513 s | 22.492 s | −0.1% | | 64 | 50.231 s | 49.576 s | −1.3% | | 128 | 100.699 s | 100.467 s | −0.2% | | 256 | 198.771 s | 197.669 s | −0.6% | | 512 | 401.860 s | 399.550 s | −0.6% | | 1,024 | 803.812 s | 806.593 s | +0.3% |Positive means After Fix took longer; negative means faster.
The measured write performance is broadly comparable before and after the fix, with no consistent substantial regression or progressively worsening slowdown as concurrency increases.
Quoted 5 lines
The differences vary between baseline batches: the increases at 16 and 32 clients in the first comparison disappear or reverse in the second. At 128–1024 clients, average write times differ by approximately 0.6% or less. These shifts are consistent with run-to-run variation; the results do not show a persistent substantial slowdown from the fix.
Quoted 9 lines
Thanks for running these tests. Results are very interesting. Can you please share your benchmarking program with me? I'll check it and try to play with it on my end. Thanks!
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR$ cat run_parent_ref_scale.sh #!/usr/bin/env bash set -u -o pipefailbench=./fsnotify_parent_ref_bench
if [[ ! -x "$bench" ]]; then
printf 'Build %s in the current directory first.\n' "$bench" >&2 exit 1
firesults_dir=$(mktemp -d ./parent-ref-results-XXXXXXXX) || exit 1 printf 'kernel=%s\nbenchmark=%s\ntmpfs=/dev/shm\nwrites_per_client=1000000\nmode=watch\n'
\ "$(uname -r)" "$bench" > "$results_dir/run-info.txt"printf 'Results: %s\n' "$results_dir"
for i in 1 2 3 4 5; do
for clients in 1 2 4 8 16 32 64 128 256 512 1024; dolog="$results_dir/clients-${clients}.log" printf '\n=== clients=%d ===\n' "$clients" "$bench" /dev/shm "$clients" 1000000 watch 2>&1 | tee "$log" status=${PIPESTATUS[0]} printf 'exit_status=%d\n' "$status" | tee -a "$log"done
doneprintf '\nAll results saved in %s\n' "$results_dir"
$ cat fsnotify_parent_ref_bench.c #define _GNU_SOURCE #include <errno.h> #include <fcntl.h> #include <inttypes.h> #include <limits.h> #include <poll.h> #include <pthread.h> #include <stdatomic.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/inotify.h> #include <sys/stat.h> #include <sys/statfs.h> #include <time.h> #include <unistd.h> #include <linux/magic.h>#define FILES 1024
#defineFILE_SIZE4096
#defineDEFAULT_WRITES1000000ULstruct gate { pthread_mutex_t mutex; pthread_cond_t cond; unsigned int ready; bool start; bool abort; };struct worker { char path[PATH_MAX]; unsigned long writes; unsigned int id; struct gate *gate; uint64_t begin_ns; uint64_t end_ns; int error; };struct listener { int fd; atomic_bool stop; uint64_t events; uint64_t overflows; int error; };static
uint64_tnow_ns(void){ struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts)) { perror("clock_gettime"); exit(EXIT_FAILURE); } return (uint64_t)ts.tv_sec * 1000000000ULL + ts.tv_nsec; }static unsigned long
parse_count(const char *s, const char *name){ char *end; unsigned long value; errno = 0; value = strtoul(s, &end, 10); if (errno || !*s || *end || !value) { fprintf(stderr, "Invalid %s: %s\n", name, s); exit(EXIT_FAILURE); } return value; }static void
file_path(char *out, size_t size, const char *dir, unsigned int i){ int n = snprintf(out, size, "%s/file-%04u", dir, i); if (n < 0 || (size_t)n >= size) { fputs("File path is too long\n", stderr); exit(EXIT_FAILURE); } }static void *run_worker(void *arg)
{ struct worker *w = arg; int fd; char byte = (char)w->id; unsigned long i; bool abort; fd = open(w->path, O_WRONLY | O_CLOEXEC); if (fd < 0) w->error = errno; pthread_mutex_lock(&w->gate->mutex); w->gate->ready++; pthread_cond_broadcast(&w->gate->cond); while (!w->gate->start) pthread_cond_wait(&w->gate->cond, &w->gate->mutex); abort = w->gate->abort; pthread_mutex_unlock(&w->gate->mutex); if (abort || w->error) goto out; w->begin_ns = now_ns(); for (i = 0; i < w->writes; i++) { if (pwrite(fd, &byte, 1, 0) != 1) { w->error = errno ? errno : EIO; break; } } w->end_ns = now_ns(); out: if (fd >= 0 && close(fd) && !w->error) w->error = errno; return NULL; }static void *drain_events(void *arg)
{ struct listener *l = arg; char buf[65536] __attribute__((aligned(8))); struct pollfd pfd = { .fd = l->fd, .events = POLLIN }; for (;;) { int ready = poll(&pfd, 1, atomic_load(&l->stop) ? 0 : 50); if (ready < 0) { if (errno == EINTR) continue; l->error = errno; break; } if (!ready) { if (atomic_load(&l->stop)) break; continue; } for (;;) { ssize_t len = read(l->fd, buf, sizeof(buf)); size_t pos = 0; if (len < 0) { if (errno == EINTR) continue; if (errno == EAGAIN) break; l->error = errno; return NULL; } while (pos + sizeof(struct inotify_event) <= (size_t)len) { struct inotify_event *ev = (struct inotify_event *)(buf + pos); size_t step = sizeof(*ev) + ev->len; if (step > (size_t)len - pos) { l->error = EPROTO; return NULL; } l->events++; if (ev->mask & IN_Q_OVERFLOW) l->overflows++; pos += step; } if (pos != (size_t)len) { l->error = EPROTO; return NULL; } } } return NULL; }static void
cleanup(const char *dir){ char path[PATH_MAX]; unsigned int i; for (i = 0; i < FILES; i++) { file_path(path, sizeof(path), dir, i); if (unlink(path) && errno != ENOENT) perror(path); } if (rmdir(dir)) perror(dir); }int
main(int argc, char **argv){ char dir[PATH_MAX], path[PATH_MAX]; unsigned long writes = DEFAULT_WRITES; unsigned long count; unsigned int clients, i, created = 0; struct statfs fs; struct gate gate = { .mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, }; struct listener listener = { .fd = -1 }; struct worker *workers; pthread_t *threads, listener_thread; bool watched = true, listener_started = false; uint64_t first = UINT64_MAX, last = 0, sum = 0; uint64_t shortest = UINT64_MAX, longest = 0; char zeroes[FILE_SIZE] = { 0 }; int rc = EXIT_FAILURE, err; if (argc < 3 || argc > 5) { fprintf(stderr, "Usage: %s TMPFS_ROOT CLIENTS [WRITES_PER_CLIENT] [watch|none]\n", argv[0]); return rc; } clients = parse_count(argv[2], "clients"); if (clients > FILES) { fprintf(stderr, "Clients must be at most %d\n", FILES); return rc; } if (argc > 3) writes = parse_count(argv[3], "writes per client"); if (writes > ULONG_MAX / clients) { fputs("Total write count is too large\n", stderr); return rc; } if (argc > 4) { if (!strcmp(argv[4], "none")) watched = false; else if (strcmp(argv[4], "watch")) { fputs("Mode must be watch or none\n", stderr); return rc; } } if (statfs(argv[1], &fs)) { perror(argv[1]); return rc; } if (fs.f_type != TMPFS_MAGIC) { fprintf(stderr, "%s must be a tmpfs directory\n", argv[1]); return rc; } if (snprintf(dir, sizeof(dir), "%s/fsnotify-parent-ref-XXXXXX", argv[1]) >= (int)sizeof(dir) || !mkdtemp(dir)) { perror("mkdtemp"); return rc; } workers = calloc(clients, sizeof(*workers)); threads = calloc(clients, sizeof(*threads)); if (!workers || !threads) { fputs("Cannot allocate worker state\n", stderr); goto out; } for (i = 0; i < FILES; i++) { int fd; file_path(path, sizeof(path), dir, i); fd = open(path, O_CREAT | O_EXCL | O_WRONLY | O_CLOEXEC, 0600); if (fd < 0) { perror(path); goto out; } /* Allocate the tmpfs page before the measured write loop. */ if (write(fd, zeroes, sizeof(zeroes)) != sizeof(zeroes)) { perror(path); close(fd); goto out; } if (close(fd)) { perror(path); goto out; } } if (watched) { listener.fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC); if (listener.fd < 0 || inotify_add_watch(listener.fd, dir, IN_MODIFY) < 0) { perror("inotify watch"); goto out; } err = pthread_create(&listener_thread, NULL, drain_events, &listener); if (err) { errno = err; perror("listener thread"); goto out; } listener_started = true; } for (i = 0; i < clients; i++) { workers[i].id = i; workers[i].writes = writes; workers[i].gate = &gate; file_path(workers[i].path, sizeof(workers[i].path), dir, i); err = pthread_create(&threads[i], NULL, run_worker, &workers[i]); if (err) { errno = err; perror("worker thread"); gate.abort = true; goto release; } created++; } pthread_mutex_lock(&gate.mutex); while (gate.ready < clients) pthread_cond_wait(&gate.cond, &gate.mutex); pthread_mutex_unlock(&gate.mutex); for (i = 0; i < clients; i++) { if (workers[i].error) { fprintf(stderr, "Worker %u open: %s\n", i, strerror(workers[i].error)); gate.abort = true; break; } } printf("test_dir=%s files=%d file_size=%d clients=%u writes_per_client=%lu mode=%s\n", dir, FILES, FILE_SIZE, clients, writes, watched ? "watch" : "none"); fflush(stdout); release: pthread_mutex_lock(&gate.mutex); gate.start = true; pthread_cond_broadcast(&gate.cond); pthread_mutex_unlock(&gate.mutex); for (i = 0; i < created; i++) pthread_join(threads[i], NULL); if (listener_started) { atomic_store(&listener.stop, true); pthread_join(listener_thread, NULL); printf("inotify_events=%" PRIu64 " queue_overflows=%"PRIu64 "\n",
listener.events, listener.overflows);
if (listener.error)
fprintf(stderr, "Inotify listener: %s\n",
strerror(listener.error));
if (listener.overflows)
fputs("Inotify queue overflowed; event delivery
load changed during the run\n", stderr);} if (gate.abort || listener.error) goto out; for (i = 0; i < clients; i++) { uint64_t duration; if (workers[i].error) { fprintf(stderr, "Worker %u write: %s\n", i, strerror(workers[i].error)); goto out; } duration = workers[i].end_ns - workers[i].begin_ns; if (workers[i].begin_ns < first) first = workers[i].begin_ns; if (workers[i].end_ns > last) last = workers[i].end_ns; if (duration < shortest) shortest = duration; if (duration > longest) longest = duration; sum += duration; } count = (unsigned long)clients * writes; printf("total_writes=%lu wall_seconds=%.6f throughput_writes_per_sec=%.0f mean_worker_ns_per_write=%.1f shortest_worker_seconds=%.6f longest_worker_seconds=%.6f\n", count, (last - first) / 1e9, count * 1e9 / (last - first), (double)sum / count, shortest / 1e9, longest / 1e9); printf("result=%s\n", listener.overflows ? "QUEUE_OVERFLOW" : "PASS"); rc = listener.overflows ? EXIT_FAILURE : EXIT_SUCCESS; out: if (listener.fd >= 0) close(listener.fd); cleanup(dir); free(workers); free(threads); return rc; }Quoted 6 lines
Please compile :
fsnotify_parent_ref_bench.c-ofsnotify_parent_ref_bench. After that
run the script ./run_parent_ref_scale.shThanks
Partha
Quoted 8 lines
Hi Honza,
A gentle ping on the benchmark program, Have you had a chance to try it on your setup? Please let me know if any further tests or information would be helpful.
Thanks,
Partha
Hi Honza,
Have you had a chance to try the benchmark on your setup? Please let me know if you need any further tests from my side to move this patch forward.
Thanks,
Partha
Jan Kara
maintainerRe: [External] : Re: [PATCH 0/1] fsnotify: Check parent watches without child dentry flags
Quoted 20 lines · Partha Satapathy
Quoted 8 lines · Partha Satapathy
Quoted 6 lines · Partha Satapathy
Please compile :
fsnotify_parent_ref_bench.c-ofsnotify_parent_ref_bench. After that
run the script ./run_parent_ref_scale.shThanks
ParthaQuoted 8 lines
Hi Honza,
A gentle ping on the benchmark program, Have you had a chance to try it on your setup? Please let me know if any further tests or information would be helpful.
Thanks,
Partha
Quoted 4 lines
Hi Honza,
Have you had a chance to try the benchmark on your setup? Please let me know if you need any further tests from my side to move this patch forward.
I'm sorry for the delay. I didn't get to this yet because with the firehose of LLM generated reports & fixes things get postponed. But I'm looking into this now.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jan Kara
maintainerRe: [External] : Re: [PATCH 0/1] fsnotify: Check parent watches without child dentry flags
Quoted 21 lines · Jan Kara
Quoted 20 lines · Partha Satapathy
Quoted 16 lines · Partha Satapathy
Quoted 6 lines · Partha Satapathy
Please compile :
fsnotify_parent_ref_bench.c-ofsnotify_parent_ref_bench. After that
run the script ./run_parent_ref_scale.shThanks
ParthaHi Honza,
A gentle ping on the benchmark program, Have you had a chance to try it on your setup? Please let me know if any further tests or information would be helpful.
Thanks,
Partha
Quoted 8 lines
Quoted 4 lines
Hi Honza,
Have you had a chance to try the benchmark on your setup? Please let me know if you need any further tests from my side to move this patch forward.
I'm sorry for the delay. I didn't get to this yet because with the firehose of LLM generated reports & fixes things get postponed. But I'm looking into this now.
So I did the benchmarking with your benchmark (thank you for that!). I was running it like:
./fsnotify_benchmark /dev/shm/benchmark/ 64 1000000 none
and what I'm seeing (avg of 10 runs) is:
writes per second
vanilla 7.4-rc2: 79.75m
7.4-rc2 + your patch: 5.47m
and perf for the kernel with the patch applied clearly shows vast majority of time spent in lockref manipulations as I expected. The reason why you didn't see a difference is likely that fsnotify_parent() has this guard:
if (!fsnotify_sb_has_watchers(inode->i_sb))
return 0;which avoids even looking at the parent if nobody watches anything in the filesystem. So to really benchmark changed fsnotify code I had to do:
tail -f /dev/shm/watchfile
before running the benchmark to neutralize this shortcut. I guess now you see why PARENT_WATCHED flag is really essential in keeping decent performance when inotify is *not* used for some directory in a filesystem.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR