RFC getting rid of busy-wait in shrink_dcache_parent()
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v3 RFC Latest4 patches 5 repliesIn review
- v2 RFC4 patches 13 repliesSuperseded
Changes in v3 from the cover letter
* separate select_data from the completion list elements - add a separate
struct completion_list (private to fs/dcache.c at the moment, but it's completely independent from struct dentry and can be lifted e.g. into linux/completion.h if there are other potential users).
Patches in v3 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/4 | for_each_alias(): helper macro for iterating through dentries of given inodeDocumentation/ fs/ fs/ +8 more | +25 | 0 replies | |
| 2/4 | struct dentry: make ->d_u anonymousfs/ fs/ fs/ +3 more | +30 | 0 replies | |
| 3/4 | dcache.c: more idiomatic "positives are not allowed" sanity checksfs/ | +5 | 0 replies | |
| 4/4 | get rid of busy-waiting in shrink_dcache_tree()fs/ include/ | +88 | 0 replies |
Reviews trailers per patch
None of the 4 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.
| Patch | Jeff Layton |
|---|---|
| Series | R-b R-b |
| 1/4 | |
| 2/4 | |
| 3/4 | |
| 4/4 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [RFC PATCH v3 0/4] getting rid of busy-wait in shrink_dcache_parent()
Changes since v2:
* separate select_data from the completion list elements - add a separate
struct completion_list (private to fs/dcache.c at the moment, but it's completely independent from struct dentry and can be lifted e.g. into linux/completion.h if there are other potential users).
Branch (currently -rc6-based) lives ingit://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git #work.dcache-busy-wait individual patches in followups. Please, review.
Shortlog:
Al Viro (4):
for_each_alias(): helper macro for iterating through dentries of given inode struct dentry: make ->d_u anonymous
dcache.c: more idiomatic "positives are not allowed" sanity checks get rid of busy-waiting in shrink_dcache_tree()
Diffstat:
Documentation/filesystems/porting.rst | 10 ++ fs/affs/amigaffs.c | 2 +- fs/ceph/mds_client.c | 4 +- fs/dcache.c | 129 +++++++++++++++++++------- fs/exportfs/expfs.c | 2 +- fs/inode.c | 2 +- fs/nfs/dir.c | 4 +- fs/nfs/getroot.c | 2 +- fs/notify/fsnotify.c | 2 +- fs/ocfs2/dcache.c | 2 +- fs/overlayfs/dir.c | 2 +- fs/smb/client/inode.c | 2 +- include/linux/dcache.h | 24 ++++- 13 files changed, 140 insertions(+), 47 deletions(-)
Series overview
First a couple of cleanups to reduce the amount of noise:
1) for_each_alias(): helper macro for iterating through dentries of given inode
Most of the places using d_alias are loops iterating through all aliases for given inode; introduce a helper macro (for_each_alias(dentry, inode)) and convert open-coded instances of such loop to it.
They are easier to read that way and it reduces the noise on the next steps.
2) struct dentry: make ->d_u anonymous
Making ->d_rcu and (then) ->d_child overlapping dates back to 2006; anon unions support had been added to gcc only in 4.6 (2011) and the minimal gcc version hadn't been bumped to that until 4.19 (2018).
These days there's no reason not to keep that union named.
Next we get rid of the aforementioned pathologies:
3) dcache.c: more idiomatic "positives are not allowed" sanity checks
Several functions have BUG_ON/WARN_ON sanity checks that want to verify that dentry is not positive and instead of looking at ->d_inode (as we do in all other places that check that) they look at ->d_alias. Just use the normal helpers instead - that way we no longer even look at ->d_alias for negative dentries
Now that everything is ready for adding a new member and killing busy-wait:
4) get rid of busy-waiting in shrink_dcache_tree()
If shrink_dcache_tree() runs into a potential victim that is already dying, it must wait for that dentry to go away. To avoid busy-waiting we need some object to wait on and a way for dentry_unlist() to see that we need to be notified.
The obvious place for the object to wait on would be on our stack frame. We will store a pointer to that object (struct completion_list) in victim dentry; if there's more than one thread wanting to wait for the same dentry to finish dying, we'll have their instances linked into a list, with reference in dentry pointing to the head of that list.
* new object - struct completion_list. A pair of struct completion and pointer to the next instance. That's what shrink_dcache_tree() will wait on if needed.
* add a new member (->waiters, opaque pointer to struct completion_list) to struct dentry. It is defined for negative live dentries that are not in-lookup ones and it will remain NULL for almost all of them.
It does not conflict with ->d_rcu (defined for killed dentries), ->d_alias (defined for positive dentries, all live) or ->d_in_lookup_hash (defined for in-lookup dentries, all live negative). That allows to colocate all four members.
* make sure that all places where dentry enters the state where ->waiters is defined (live, negative, not-in-lookup) initialize ->waiters to NULL.
* if select_collect2() runs into a dentry that is already dying, have its caller insert a local instance of struct completion_list into the head of the list hanging off dentry->waiters and wait for completion.
* if dentry_unlist() sees non-NULL ->waiters, have it carefully walk through the completion_list instances in that list, calling complete() for each.
For now struct completion_list is local to fs/dcache.c; it's obviously dentry-agnostic, and it can be trivially lifted into linux/completion.h if somebody finds a reason to do so...
--
2.47.3