Page MenuHomeFreeBSD

vfs: change si_usecount management to count used vnodes
ClosedPublic

Authored by mjg on Oct 31 2019, 12:27 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Apr 24, 11:45 PM
Unknown Object (File)
Sat, Apr 13, 1:05 PM
Unknown Object (File)
Sat, Mar 30, 4:26 PM
Unknown Object (File)
Feb 29 2024, 6:53 PM
Unknown Object (File)
Dec 23 2023, 12:22 AM
Unknown Object (File)
Dec 20 2023, 5:33 AM
Unknown Object (File)
Nov 28 2023, 9:20 PM
Unknown Object (File)
Nov 23 2023, 2:34 PM
Subscribers

Details

Summary

Currently si_usecount is effectively a sum of usecounts from all associated vnodes. This is maintained by special-casing for VCHR every time usecount is modified. Apart from complicating the code a little bit, it has a scalability impact since it forces a read from a cacheline shared with said count.

There are no consumers of the feature in the ports tree. In head there are only 2: revoke and devfs_close. Both can get away with a weaker requirement than the exact usecount, namely just the count of active vnodes. Changing the meaning to the latter means we only need to modify it on 0<->1 transitions, avoiding the check plenty of times (and entirely in something like vrefact).

I did a simple verification: just logging in over ssh and logging out runs into vp->v_usecount == 2 and count_dev() == 2 in stock head, and 2 and 1 respectively with the patch.

Test Plan

pho tested the change, no problems found.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

sys/fs/devfs/devfs_vnops.c
594 ↗(On Diff #63818)

These two checks for v_usecount == 2 are optimizations and can be committed separately.

OTOH I should note that changing v_usecount updates to atomic make these checks racy.

sys/kern/vfs_syscalls.c
4151 ↗(On Diff #63818)

This is just an optimization, right ? It can be tested/committed separately before the rest of the patch is reviewed.

sys/fs/devfs/devfs_vnops.c
594 ↗(On Diff #63818)

I think the code was racy even beforehand. Moreover, I suspect there is a different bug here as well: if the target device gets a ref from another devfs mount point, this code will decline clearing it which probably was not intended. At least dragonfly only checks the current vnode and changing this would be a noop for typical use cases. That said, I consider the patch to maintain to be bug compatible.

sys/kern/vfs_syscalls.c
4151 ↗(On Diff #63818)

With the patch in place, if this is the only vnode, vcount will return 1 on account of v_usecount > 0. Thus the check is needed to actually revoke if there are other users of the vnode.

ping? the change passed tests by pho

This revision is now accepted and ready to land.Nov 20 2019, 1:43 AM