Repository navigation
Give each network namespace its own socktab - #156
Stuartwastaken wants to merge 3 commits into
Conversation
Before this change all namespaces shared homa->socktab, with the namespace as part of the hash key. Now each homa_net has its own socktab, and homa->nets links the homa_nets together so that homa_timer can scan the sockets of all namespaces. This fixes a bug in homa_abort_rpcs: an ICMP error received in one namespace aborted RPCs to the same address in every namespace.
johnousterhout
left a comment
There was a problem hiding this comment.
This is a good start. I made a quick scan and added a few comments. Let's discuss the ones labeled "Let's discuss".
| * holding either @nets_mutex or the RCU read lock. | ||
| */ | ||
| struct homa_socktab *socktab; | ||
| struct list_head nets; |
There was a problem hiding this comment.
Can you make this an RCU list so that nets_mutex doesn't need to be held while traversing it? Or, if this is already an RCU list, document that explicitly. If it can be scanned with only an RCU read lock, why would anyone want to use nets_mutex? Let's discuss.
| struct list_head nets; | ||
|
|
||
| /** @nets_mutex: Synchronizes access to @nets. */ | ||
| struct mutex nets_mutex; |
There was a problem hiding this comment.
The convention in Homa is to use spinlocks for everything, unless there is a particular reason why a sleep lock is needed.
| * homa->nets_mutex, all locks should be considered "leaf" locks: don't | ||
| * acquire other locks while holding them. | ||
| * 2. The lock order is: | ||
| * * homa->nets_mutex |
There was a problem hiding this comment.
Adding a new layer in the locking hierarchy is a major change; it's not obvious to me that this is necessary. Let's discuss.
| void homa_net_pre_exit(struct net *net) | ||
| { | ||
| homa_net_unlink(homa_net(net)); | ||
| } |
There was a problem hiding this comment.
This is a pass-through function; why not just put homa_net_unlink into the struct pernet_operations? Let's discuss.
|
|
||
| return homa_socktab_next(scan); | ||
| } | ||
|
|
There was a problem hiding this comment.
Is this function needed? Why not just let callers do the 2-level scan themselves (iterate over the list of hnets, then invoke homa_socktab_start_scan on each)? Let's discuss.
| * struct homa_socktab - A hash table that maps from port numbers (either | ||
| * client or server) to homa_sock objects. | ||
| * client or server) to homa_sock objects. There is one of these for each | ||
| * network namespace. |
There was a problem hiding this comment.
I'm not sure this additional comment is needed. Is there anything in this module that needs to care about the existence of network namespaces? Ideally all of the network namespace can be built on top of this module, without this module needing to know how it is being used.
| * RCU to keep network namespaces from being deleted during the scan, | ||
| * because the scan may block. | ||
| */ | ||
| mutex_lock(&homa->nets_mutex); |
There was a problem hiding this comment.
Where/how does the scan block? Given that RCU is already used below when scanning an individual socket, why not just use it for namespace scan also? Let's discuss.
| list_for_each_entry_safe(hnet, next, &homa->nets, links) { | ||
| homa_net_unlink(hnet); | ||
| homa_socktab_destroy(hnet->socktab); | ||
| kfree(hnet->socktab); |
There was a problem hiding this comment.
Having a bunch of code here that only matters for unit tests is awkward (and can't be upstreamed). Can you find a way to get that code out of here and put it someplace in the unit testing framework instead?
|
Thanks for starting this. I have been testing Homa between namespaces
I have local fixes for 1 and 2, but they are not cleaned up for |
Happy to discuss, @johnousterhout. Our call this week was cancelled by Thiya but we can pick this up next week. Happy Thanksgiving! Perusing through here I can understand my own naive mistake of doing a mutex lock on the whole namespace table, and not taking care of layering correctly by involving the socket code. And actually while doing this I learned that linux keeps track of the namespaces for us, so that makes this easier. Pushing some fixes now to use the linux namespace, keeping the socktab code separate and namespace-unaware, and making sure the unit test code stays out of the main code. To answer your question about where the scan blocks: it's only the |
Replaces homa->nets and homa->nets_mutex. homa_timer now walks the kernel's list of namespaces under RCU and holds a reference on each namespace while it scans that namespace's sockets. The socktab code no longer knows about namespaces, and the unit-test cleanup of homa_nets has moved from homa_destroy to mock.c.
This is the first step of the namespace work. Today the sockets of all network namespaces share homa->socktab, and each lookup compares hsk->hnet. This moves the socktab into struct homa_net, so each namespace has its own table and its own port space.
homa_timer still has to visit every socket. It walks the kernel's net_namespace_list with for_each_net_rcu and scans each namespace's socktab. The scan calls schedule(), so it can't stay inside the RCU read lock: it takes a reference on the namespace with maybe_get_net, drops the RCU lock for the scan, and takes it again before put_net. The scans in homa_devel.c don't block, so they use for_each_net_rcu alone. Homa keeps no list of namespaces of its own, and there is no new lock.
This also fixes homa_abort_rpcs, which scanned the shared table without checking the namespace, so an ICMP unreachable received in one namespace aborted RPCs to the same address in all of them. It now takes the hnet from the error handler and scans only that table; homa_abort_rpcs__ignore_other_hnets fails without the change. Ashish's #143 contains the same fix for homa_abort_rpcs (an hnet argument plus a check in the loop), so you can take either one; whichever goes in second needs a small rebase.
Each namespace now allocates its own socktab (1024 buckets, a little over 8 KB) while Homa is loaded. homa_destroy no longer deletes sockets, so each unit-test fixture's teardown calls mock_hnets_destroy first.
Besides the unit tests, I ran this on 6.17.8 with the same port bound in four namespaces at once, RPCs between two namespaces over a veth pair, and 300 namespace create/delete cycles under load. That kernel has neither KASAN nor lockdep, so those have not been run.