Skip to contentSkip to conversation

net-memcg: avoid stalls when under memory pressure

PATCH Applied Jakub Kicinski 5 participants 8 messages Oct 21, 2022 – Oct 24, 2022

Subsystems (4)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 net-memcg: avoid stalls when under memory pressure

As Shakeel explains the commit under Fixes had the unintended side-effect of no longer pre-loading the cached memory allowance. Even tho we previously dropped the first packet received when over memory limit - the consecutive ones would get thru by using the cache. The charging was happening in batches of 128kB, so we'd let in 128kB (truesize) worth of packets per one drop.

After the change we no longer force charge, there will be no cache filling side effects. This causes significant drops and connection stalls for workloads which use a lot of page cache, since we can't reclaim page cache under GFP_NOWAIT.

Some of the latency can be recovered by improving SACK reneg handling but nowhere near enough to get back to the pre-5.15 performance (the application I'm experimenting with still sees 5-10x worst latency).

Apply the suggested workaround of using GFP_ATOMIC. We will now be more permissive than previously as we'll drop _no_ packets in softirq when under pressure. But I can't think of any good and simple way to address that within networking.

Fixes 4b1327be9fe5 ("net-memcg: pass in gfp_t mask to mem_cgroup_charge_skmem()")

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 include/net/sock.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/sock.h +1 -1
index 9e464f6409a7..22f8bab583dd 100644
@@ -2585,7 +2585,7 @@ static inline gfp_t gfp_any(void)
 
 static inline gfp_t gfp_memcg_charge(void)
 {
-	return in_softirq() ? GFP_NOWAIT : GFP_KERNEL;
+	return in_softirq() ? GFP_ATOMIC : GFP_KERNEL;
 }
 
 static inline long sock_rcvtimeo(const struct sock *sk, bool noblock)
Signature · 1 line
2.37.3
#1 lore raw
Quoted 41 lines · Jakub Kicinski

As Shakeel explains the commit under Fixes had the unintended side-effect of no longer pre-loading the cached memory allowance. Even tho we previously dropped the first packet received when over memory limit - the consecutive ones would get thru by using the cache. The charging was happening in batches of 128kB, so we'd let in 128kB (truesize) worth of packets per one drop.

After the change we no longer force charge, there will be no cache filling side effects. This causes significant drops and connection stalls for workloads which use a lot of page cache, since we can't reclaim page cache under GFP_NOWAIT.

Some of the latency can be recovered by improving SACK reneg handling but nowhere near enough to get back to the pre-5.15 performance (the application I'm experimenting with still sees 5-10x worst latency).

Apply the suggested workaround of using GFP_ATOMIC. We will now be more permissive than previously as we'll drop _no_ packets in softirq when under pressure. But I can't think of any good and simple way to address that within networking.

Fixes 4b1327be9fe5 ("net-memcg: pass in gfp_t mask to mem_cgroup_charge_skmem()")

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 include/net/sock.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/sock.h +0 -0
index 9e464f6409a7..22f8bab583dd 100644

include/net/sock.h static inline gfp_t gfp_any(void) · line 2590

Quoted 7 lines
include/net/sock.h +1 -1
@@ -2585,7 +2585,7 @@ static inline gfp_t gfp_any(void)
 
 static inline gfp_t gfp_memcg_charge(void)
 {
-       return in_softirq() ? GFP_NOWAIT : GFP_KERNEL;
+       return in_softirq() ? GFP_ATOMIC : GFP_KERNEL;
 }
 

How about just using gfp_any() and we can remove gfp_memcg_charge()?

#2 lore raw
Quoted 44 lines · Shakeel Butt
Quoted 42 lines · Jakub Kicinski

As Shakeel explains the commit under Fixes had the unintended side-effect of no longer pre-loading the cached memory allowance. Even tho we previously dropped the first packet received when over memory limit - the consecutive ones would get thru by using the cache. The charging was happening in batches of 128kB, so we'd let in 128kB (truesize) worth of packets per one drop.

After the change we no longer force charge, there will be no cache filling side effects. This causes significant drops and connection stalls for workloads which use a lot of page cache, since we can't reclaim page cache under GFP_NOWAIT.

Some of the latency can be recovered by improving SACK reneg handling but nowhere near enough to get back to the pre-5.15 performance (the application I'm experimenting with still sees 5-10x worst latency).

Apply the suggested workaround of using GFP_ATOMIC. We will now be more permissive than previously as we'll drop _no_ packets in softirq when under pressure. But I can't think of any good and simple way to address that within networking.

Fixes 4b1327be9fe5 ("net-memcg: pass in gfp_t mask to mem_cgroup_charge_skmem()")

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 include/net/sock.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/sock.h +0 -0
index 9e464f6409a7..22f8bab583dd 100644
@@ -2585,7 +2585,7 @@ static inline gfp_t gfp_any(void)
 
Quoted 8 lines

include/net/sock.h static inline gfp_t gfp_any(void) · line 2590

Quoted 6 lines
include/net/sock.h +1 -1
 static inline gfp_t gfp_memcg_charge(void)
 {
-       return in_softirq() ? GFP_NOWAIT : GFP_KERNEL;
+       return in_softirq() ? GFP_ATOMIC : GFP_KERNEL;
 }
 

How about just using gfp_any() and we can remove gfp_memcg_charge()?

How about keeping gfp_memcg_charge() and adding a comment on its intent ?

gfp_any() is very generic :/

#3 lore raw
Quoted 55 lines · Eric Dumazet
Quoted 44 lines · Shakeel Butt
Quoted 42 lines · Jakub Kicinski

As Shakeel explains the commit under Fixes had the unintended side-effect of no longer pre-loading the cached memory allowance. Even tho we previously dropped the first packet received when over memory limit - the consecutive ones would get thru by using the cache. The charging was happening in batches of 128kB, so we'd let in 128kB (truesize) worth of packets per one drop.

After the change we no longer force charge, there will be no cache filling side effects. This causes significant drops and connection stalls for workloads which use a lot of page cache, since we can't reclaim page cache under GFP_NOWAIT.

Some of the latency can be recovered by improving SACK reneg handling but nowhere near enough to get back to the pre-5.15 performance (the application I'm experimenting with still sees 5-10x worst latency).

Apply the suggested workaround of using GFP_ATOMIC. We will now be more permissive than previously as we'll drop _no_ packets in softirq when under pressure. But I can't think of any good and simple way to address that within networking.

Fixes 4b1327be9fe5 ("net-memcg: pass in gfp_t mask to mem_cgroup_charge_skmem()")

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 include/net/sock.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/sock.h +0 -0
index 9e464f6409a7..22f8bab583dd 100644
@@ -2585,7 +2585,7 @@ static inline gfp_t gfp_any(void)
 
Quoted 8 lines

include/net/sock.h static inline gfp_t gfp_any(void) · line 2590

Quoted 6 lines
include/net/sock.h +1 -1
 static inline gfp_t gfp_memcg_charge(void)
 {
-       return in_softirq() ? GFP_NOWAIT : GFP_KERNEL;
+       return in_softirq() ? GFP_ATOMIC : GFP_KERNEL;
 }
 

How about just using gfp_any() and we can remove gfp_memcg_charge()?

Quoted 3 lines

How about keeping gfp_memcg_charge() and adding a comment on its intent ?

gfp_any() is very generic :/

SGTM.

author maintainer
#4 lore raw
Quoted 5 lines · On Fri, 21 Oct 2022 09:34:20 -0700 Shakeel Butt wrote:
Quoted 5 lines
Quoted 1 line

How about just using gfp_any() and we can remove gfp_memcg_charge()?

How about keeping gfp_memcg_charge() and adding a comment on its intent ?

gfp_any() is very generic :/

That was my thinking, and I'm not sure what I could put in a comment. Wouldn't it be some mix of words 'flags', 'memory', 'cgroup' and 'charge'... which is just spelling out the name of the function?

I mean:

	/* Alloc flags for passing to cgroup socket memory charging */

does not add much value, right?

Acked-by
#5 lore raw
Quoted 12 lines · Jakub Kicinski
Quoted 5 lines · On Fri, 21 Oct 2022 09:34:20 -0700 Shakeel Butt wrote:
Quoted 5 lines
Quoted 1 line

How about just using gfp_any() and we can remove gfp_memcg_charge()?

How about keeping gfp_memcg_charge() and adding a comment on its intent ?

gfp_any() is very generic :/

That was my thinking, and I'm not sure what I could put in a comment. Wouldn't it be some mix of words 'flags', 'memory', 'cgroup' and 'charge'... which is just spelling out the name of the function?

Quoted 5 lines

I mean:

        /* Alloc flags for passing to cgroup socket memory charging */

does not add much value, right?

Yeah I agree. Let's just go with the original patch.

You can add:

Acked-by on v1 1/1
#6 lore raw
In reply to Jakub Kicinski
Quoted 22 lines · Jakub Kicinski

As Shakeel explains the commit under Fixes had the unintended side-effect of no longer pre-loading the cached memory allowance. Even tho we previously dropped the first packet received when over memory limit - the consecutive ones would get thru by using the cache. The charging was happening in batches of 128kB, so we'd let in 128kB (truesize) worth of packets per one drop.

After the change we no longer force charge, there will be no cache filling side effects. This causes significant drops and connection stalls for workloads which use a lot of page cache, since we can't reclaim page cache under GFP_NOWAIT.

Some of the latency can be recovered by improving SACK reneg handling but nowhere near enough to get back to the pre-5.15 performance (the application I'm experimenting with still sees 5-10x worst latency).

Apply the suggested workaround of using GFP_ATOMIC. We will now be more permissive than previously as we'll drop _no_ packets in softirq when under pressure. But I can't think of any good and simple way to address that within networking.

Quoted 4 lines
Fixes 4b1327be9fe5 ("net-memcg: pass in gfp_t mask to mem_cgroup_charge_skmem()")

Thanks!

#7 lore raw
In reply to Jakub Kicinski
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Fri, 21 Oct 2022 09:03:04 -0700 you wrote:

As Shakeel explains the commit under Fixes had the unintended side-effect of no longer pre-loading the cached memory allowance. Even tho we previously dropped the first packet received when over memory limit - the consecutive ones would get thru by using the cache. The charging was happening in batches of 128kB, so we'd let in 128kB (truesize) worth of packets per one drop.

[...]

Here is the summary with links:
- [net] net-memcg: avoid stalls when under memory pressure

    https://git.kernel.org/netdev/net/c/720ca52bcef2

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html