netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v3 1/3] sock: Code cleanup on __sk_mem_raise_allocated()
@ 2023-10-19 12:00 Abel Wu
  2023-10-19 12:00 ` [PATCH net v3 2/3] sock: Doc behaviors for pressure heurisitics Abel Wu
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Abel Wu @ 2023-10-19 12:00 UTC (permalink / raw)
  To: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Shakeel Butt
  Cc: netdev, linux-kernel, Abel Wu

Code cleanup for both better simplicity and readability.
No functional change intended.

Signed-off-by: Abel Wu <wuyun.abel@bytedance.com>
Acked-by: Shakeel Butt <shakeelb@google.com>
---
 net/core/sock.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/net/core/sock.c b/net/core/sock.c
index 16584e2dd648..4412c47466a7 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -3041,17 +3041,19 @@ EXPORT_SYMBOL(sk_wait_data);
  */
 int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind)
 {
-	bool memcg_charge = mem_cgroup_sockets_enabled && sk->sk_memcg;
+	struct mem_cgroup *memcg = mem_cgroup_sockets_enabled ? sk->sk_memcg : NULL;
 	struct proto *prot = sk->sk_prot;
-	bool charged = true;
+	bool charged = false;
 	long allocated;
 
 	sk_memory_allocated_add(sk, amt);
 	allocated = sk_memory_allocated(sk);
-	if (memcg_charge &&
-	    !(charged = mem_cgroup_charge_skmem(sk->sk_memcg, amt,
-						gfp_memcg_charge())))
-		goto suppress_allocation;
+
+	if (memcg) {
+		if (!mem_cgroup_charge_skmem(memcg, amt, gfp_memcg_charge()))
+			goto suppress_allocation;
+		charged = true;
+	}
 
 	/* Under limit. */
 	if (allocated <= sk_prot_mem_limits(sk, 0)) {
@@ -3106,8 +3108,8 @@ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind)
 		 */
 		if (sk->sk_wmem_queued + size >= sk->sk_sndbuf) {
 			/* Force charge with __GFP_NOFAIL */
-			if (memcg_charge && !charged) {
-				mem_cgroup_charge_skmem(sk->sk_memcg, amt,
+			if (memcg && !charged) {
+				mem_cgroup_charge_skmem(memcg, amt,
 					gfp_memcg_charge() | __GFP_NOFAIL);
 			}
 			return 1;
@@ -3119,8 +3121,8 @@ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind)
 
 	sk_memory_allocated_sub(sk, amt);
 
-	if (memcg_charge && charged)
-		mem_cgroup_uncharge_skmem(sk->sk_memcg, amt);
+	if (charged)
+		mem_cgroup_uncharge_skmem(memcg, amt);
 
 	return 0;
 }
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-10-24  8:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-19 12:00 [PATCH net v3 1/3] sock: Code cleanup on __sk_mem_raise_allocated() Abel Wu
2023-10-19 12:00 ` [PATCH net v3 2/3] sock: Doc behaviors for pressure heurisitics Abel Wu
2023-10-23  7:49   ` Simon Horman
2023-10-19 12:00 ` [PATCH net v3 3/3] sock: Ignore memcg pressure heuristics when raising allocated Abel Wu
2023-10-23  7:49   ` Simon Horman
2023-10-24  7:08   ` Paolo Abeni
2023-10-24  7:35     ` Shakeel Butt
2023-10-24  8:21     ` Abel Wu
2023-10-23  7:49 ` [PATCH net v3 1/3] sock: Code cleanup on __sk_mem_raise_allocated() Simon Horman
2023-10-24  8:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).