Skip to content

Commit 995599c

Browse files
edumazetopsiff
authored andcommitted
tcp: bring back NUMA dispersion in inet_ehash_locks_alloc()
[ Upstream commit f8ece40 ] We have platforms with 6 NUMA nodes and 480 cpus. inet_ehash_locks_alloc() currently allocates a single 64KB page to hold all ehash spinlocks. This adds more pressure on a single node. Change inet_ehash_locks_alloc() to use vmalloc() to spread the spinlocks on all online nodes, driven by NUMA policies. At boot time, NUMA policy is interleave=all, meaning that tcp_hashinfo.ehash_locks gets hash dispersion on all nodes. Tested: lack5:~# grep inet_ehash_locks_alloc /proc/vmallocinfo 0x00000000d9aec4d1-0x00000000a828b652 69632 inet_ehash_locks_alloc+0x90/0x100 pages=16 vmalloc N0=2 N1=3 N2=3 N3=3 N4=3 N5=2 lack5:~# echo 8192 >/proc/sys/net/ipv4/tcp_child_ehash_entries lack5:~# numactl --interleave=all unshare -n bash -c "grep inet_ehash_locks_alloc /proc/vmallocinfo" 0x000000004e99d30c-0x00000000763f3279 36864 inet_ehash_locks_alloc+0x90/0x100 pages=8 vmalloc N0=1 N1=2 N2=2 N3=1 N4=1 N5=1 0x00000000d9aec4d1-0x00000000a828b652 69632 inet_ehash_locks_alloc+0x90/0x100 pages=16 vmalloc N0=2 N1=3 N2=3 N3=3 N4=3 N5=2 lack5:~# numactl --interleave=0,5 unshare -n bash -c "grep inet_ehash_locks_alloc /proc/vmallocinfo" 0x00000000fd73a33e-0x0000000004b9a177 36864 inet_ehash_locks_alloc+0x90/0x100 pages=8 vmalloc N0=4 N5=4 0x00000000d9aec4d1-0x00000000a828b652 69632 inet_ehash_locks_alloc+0x90/0x100 pages=16 vmalloc N0=2 N1=3 N2=3 N3=3 N4=3 N5=2 lack5:~# echo 1024 >/proc/sys/net/ipv4/tcp_child_ehash_entries lack5:~# numactl --interleave=all unshare -n bash -c "grep inet_ehash_locks_alloc /proc/vmallocinfo" 0x00000000db07d7a2-0x00000000ad697d29 8192 inet_ehash_locks_alloc+0x90/0x100 pages=1 vmalloc N2=1 0x00000000d9aec4d1-0x00000000a828b652 69632 inet_ehash_locks_alloc+0x90/0x100 pages=16 vmalloc N0=2 N1=3 N2=3 N3=3 N4=3 N5=2 Signed-off-by: Eric Dumazet <[email protected]> Tested-by: Jason Xing <[email protected]> Reviewed-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit fb69189023279f35e2946fb0e4c95b04b2320f14)
1 parent acd4780 commit 995599c

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

net/ipv4/inet_hashtables.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,22 +1231,37 @@ int inet_ehash_locks_alloc(struct inet_hashinfo *hashinfo)
12311231
{
12321232
unsigned int locksz = sizeof(spinlock_t);
12331233
unsigned int i, nblocks = 1;
1234+
spinlock_t *ptr = NULL;
12341235

1235-
if (locksz != 0) {
1236-
/* allocate 2 cache lines or at least one spinlock per cpu */
1237-
nblocks = max(2U * L1_CACHE_BYTES / locksz, 1U);
1238-
nblocks = roundup_pow_of_two(nblocks * num_possible_cpus());
1236+
if (locksz == 0)
1237+
goto set_mask;
12391238

1240-
/* no more locks than number of hash buckets */
1241-
nblocks = min(nblocks, hashinfo->ehash_mask + 1);
1239+
/* Allocate 2 cache lines or at least one spinlock per cpu. */
1240+
nblocks = max(2U * L1_CACHE_BYTES / locksz, 1U) * num_possible_cpus();
12421241

1243-
hashinfo->ehash_locks = kvmalloc_array(nblocks, locksz, GFP_KERNEL);
1244-
if (!hashinfo->ehash_locks)
1245-
return -ENOMEM;
1242+
/* At least one page per NUMA node. */
1243+
nblocks = max(nblocks, num_online_nodes() * PAGE_SIZE / locksz);
1244+
1245+
nblocks = roundup_pow_of_two(nblocks);
1246+
1247+
/* No more locks than number of hash buckets. */
1248+
nblocks = min(nblocks, hashinfo->ehash_mask + 1);
12461249

1247-
for (i = 0; i < nblocks; i++)
1248-
spin_lock_init(&hashinfo->ehash_locks[i]);
1250+
if (num_online_nodes() > 1) {
1251+
/* Use vmalloc() to allow NUMA policy to spread pages
1252+
* on all available nodes if desired.
1253+
*/
1254+
ptr = vmalloc_array(nblocks, locksz);
1255+
}
1256+
if (!ptr) {
1257+
ptr = kvmalloc_array(nblocks, locksz, GFP_KERNEL);
1258+
if (!ptr)
1259+
return -ENOMEM;
12491260
}
1261+
for (i = 0; i < nblocks; i++)
1262+
spin_lock_init(&ptr[i]);
1263+
hashinfo->ehash_locks = ptr;
1264+
set_mask:
12501265
hashinfo->ehash_locks_mask = nblocks - 1;
12511266
return 0;
12521267
}

0 commit comments

Comments
 (0)