Skip to contentSkip to conversation

net/ipv4/inet_fragment: Batch fqdir destroy works

PATCH Applied SeongJae Park 3 participants 4 messages Dec 11, 2020 – Dec 12, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 net/ipv4/inet_fragment: Batch fqdir destroy works

From: SeongJae Park <[email protected]>

On a few of our systems, I found frequent 'unshare(CLONE_NEWNET)' calls make the number of active slab objects including 'sock_inode_cache' type rapidly and continuously increase. As a result, memory pressure occurs.

In more detail, I made an artificial reproducer that resembles the workload that we found the problem and reproduce the problem faster. It merely repeats 'unshare(CLONE_NEWNET)' 50,000 times in a loop. It takes about 2 minutes. On 40 CPU cores / 70GB DRAM machine, the available memory continuously reduced in a fast speed (about 120MB per second, 15GB in total within the 2 minutes). Note that the issue don't reproduce on every machine. On my 6 CPU cores machine, the problem didn't reproduce.

'cleanup_net()' and 'fqdir_work_fn()' are functions that deallocate the relevant memory objects. They are asynchronously invoked by the work queues and internally use 'rcu_barrier()' to ensure safe destructions. 'cleanup_net()' works in a batched maneer in a single thread worker, while 'fqdir_work_fn()' works for each 'fqdir_exit()' call in the 'system_wq'. Therefore, 'fqdir_work_fn()' called frequently under the workload and made the contention for 'rcu_barrier()' high. In more detail, the global mutex, 'rcu_state.barrier_mutex' became the bottleneck.

This commit avoids such contention by doing the 'rcu_barrier()' and subsequent lightweight works in a batched manner, as similar to that of 'cleanup_net()'. The fqdir hashtable destruction, which is done before the 'rcu_barrier()', is still allowed to run in parallel for fast processing, but this commit makes it to use a dedicated work queue instead of the 'system_wq', to make sure that the number of threads is bounded.

---

Changes from v3
(https://lore.kernel.org/lkml/[email protected]/)
- Use system_wq for the batched works and a dedicated non-ordered work queue for rhashtable destruction (Eric Dumazet)

Changes from v2
(https://lore.kernel.org/lkml/[email protected]/)
- Add numbers after the patch (Eric Dumazet)
- Make only 'rcu_barrier()' and subsequent lightweight works serialized (Eric Dumazet)

Changes from v1
(https://lore.kernel.org/netdev/[email protected]/)
- Keep xmas tree variable ordering (Jakub Kicinski)
- Add more numbers (Eric Dumazet)
- Use 'llist_for_each_entry_safe()' (Eric Dumazet)

---
 include/net/inet_frag.h  |  1 +
 net/ipv4/inet_fragment.c | 47 +++++++++++++++++++++++++++++++++-------
 2 files changed, 40 insertions(+), 8 deletions(-)
include/net/inet_frag.h +1 -0
index bac79e817776..48cc5795ceda 100644
@@ -21,6 +21,7 @@ struct fqdir {
 	/* Keep atomic mem on separate cachelines in structs that include it */
 	atomic_long_t		mem ____cacheline_aligned_in_smp;
 	struct work_struct	destroy_work;
+	struct llist_node	free_list;
 };
 
 /**
net/ipv4/inet_fragment.c +39 -8

71 lines not on this page · raw message

Signature · 1 line
2.17.1
Reviewed-by on v4 1/1
#1 lore raw
Quoted 11 lines · SeongJae Park

From: SeongJae Park <[email protected]>

On a few of our systems, I found frequent 'unshare(CLONE_NEWNET)' calls make the number of active slab objects including 'sock_inode_cache' type rapidly and continuously increase. As a result, memory pressure occurs.

---

Jakub or David might change the patch title, no need to resend.

Thanks for this nice improvement.

#2 lore raw
Quoted 13 lines · On Fri, 11 Dec 2020 15:36:53 +0100 Eric Dumazet <[email protected]> wrote:
Quoted 11 lines · SeongJae Park

From: SeongJae Park <[email protected]>

On a few of our systems, I found frequent 'unshare(CLONE_NEWNET)' calls make the number of active slab objects including 'sock_inode_cache' type rapidly and continuously increase. As a result, memory pressure occurs.

---

Quoted 5 lines

Jakub or David might change the patch title, no need to resend.

Thanks for this nice improvement.

My very best pleasure! Thank you always for your nice advices and reviews!

Thanks,
SeongJae Park

maintainer Applied
#3 lore raw
In reply to Eric Dumazet
Quoted 10 lines · On Fri, 11 Dec 2020 15:36:53 +0100 Eric Dumazet wrote:
Quoted 5 lines · SeongJae Park

From: SeongJae Park <[email protected]>

On a few of our systems, I found frequent 'unshare(CLONE_NEWNET)' calls make the number of active slab objects including 'sock_inode_cache' type rapidly and continuously increase. As a result, memory pressure occurs.

Jakub or David might change the patch title, no need to resend.

"inet: frags: batch fqdir destroy works" it is.

Applied, thanks!