aboutsummaryrefslogtreecommitdiffstats
path: root/net/socket.c
diff options
context:
space:
mode:
authorNick Piggin <npiggin@kernel.dk>2011-01-07 01:50:11 -0500
committerNick Piggin <npiggin@kernel.dk>2011-01-07 01:50:33 -0500
commitb3e19d924b6eaf2ca7d22cba99a517c5171007b6 (patch)
tree8c1fa4074114a883a4e2de2f7d12eb29ed91bdf1 /net/socket.c
parentc6653a838b1b2738561aff0b8c0f62a9b714bdd9 (diff)
fs: scale mntget/mntput
The problem that this patch aims to fix is vfsmount refcounting scalability. We need to take a reference on the vfsmount for every successful path lookup, which often go to the same mount point. The fundamental difficulty is that a "simple" reference count can never be made scalable, because any time a reference is dropped, we must check whether that was the last reference. To do that requires communication with all other CPUs that may have taken a reference count. We can make refcounts more scalable in a couple of ways, involving keeping distributed counters, and checking for the global-zero condition less frequently. - check the global sum once every interval (this will delay zero detection for some interval, so it's probably a showstopper for vfsmounts). - keep a local count and only taking the global sum when local reaches 0 (this is difficult for vfsmounts, because we can't hold preempt off for the life of a reference, so a counter would need to be per-thread or tied strongly to a particular CPU which requires more locking). - keep a local difference of increments and decrements, which allows us to sum the total difference and hence find the refcount when summing all CPUs. Then, keep a single integer "long" refcount for slow and long lasting references, and only take the global sum of local counters when the long refcount is 0. This last scheme is what I implemented here. Attached mounts and process root and working directory references are "long" references, and everything else is a short reference. This allows scalable vfsmount references during path walking over mounted subtrees and unattached (lazy umounted) mounts with processes still running in them. This results in one fewer atomic op in the fastpath: mntget is now just a per-CPU inc, rather than an atomic inc; and mntput just requires a spinlock and non-atomic decrement in the common case. However code is otherwise bigger and heavier, so single threaded performance is basically a wash. Signed-off-by: Nick Piggin <npiggin@kernel.dk>
Diffstat (limited to 'net/socket.c')
-rw-r--r--net/socket.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/net/socket.c b/net/socket.c
index 0ee74c325320..815bba3d2fe0 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -2390,6 +2390,8 @@ EXPORT_SYMBOL(sock_unregister);
2390 2390
2391static int __init sock_init(void) 2391static int __init sock_init(void)
2392{ 2392{
2393 int err;
2394
2393 /* 2395 /*
2394 * Initialize sock SLAB cache. 2396 * Initialize sock SLAB cache.
2395 */ 2397 */
@@ -2406,8 +2408,15 @@ static int __init sock_init(void)
2406 */ 2408 */
2407 2409
2408 init_inodecache(); 2410 init_inodecache();
2409 register_filesystem(&sock_fs_type); 2411
2412 err = register_filesystem(&sock_fs_type);
2413 if (err)
2414 goto out_fs;
2410 sock_mnt = kern_mount(&sock_fs_type); 2415 sock_mnt = kern_mount(&sock_fs_type);
2416 if (IS_ERR(sock_mnt)) {
2417 err = PTR_ERR(sock_mnt);
2418 goto out_mount;
2419 }
2411 2420
2412 /* The real protocol initialization is performed in later initcalls. 2421 /* The real protocol initialization is performed in later initcalls.
2413 */ 2422 */
@@ -2420,7 +2429,13 @@ static int __init sock_init(void)
2420 skb_timestamping_init(); 2429 skb_timestamping_init();
2421#endif 2430#endif
2422 2431
2423 return 0; 2432out:
2433 return err;
2434
2435out_mount:
2436 unregister_filesystem(&sock_fs_type);
2437out_fs:
2438 goto out;
2424} 2439}
2425 2440
2426core_initcall(sock_init); /* early initcall */ 2441core_initcall(sock_init); /* early initcall */