Skip to content

Commit 2def8ff

Browse files
Abel-WYPaolo Abeni
authored and
Paolo Abeni
committed
sock: Code cleanup on __sk_mem_raise_allocated()
Code cleanup for both better simplicity and readability. No functional change intended. Signed-off-by: Abel Wu <[email protected]> Acked-by: Shakeel Butt <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent f6e1227 commit 2def8ff

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

net/core/sock.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3039,17 +3039,19 @@ EXPORT_SYMBOL(sk_wait_data);
30393039
*/
30403040
int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind)
30413041
{
3042-
bool memcg_charge = mem_cgroup_sockets_enabled && sk->sk_memcg;
3042+
struct mem_cgroup *memcg = mem_cgroup_sockets_enabled ? sk->sk_memcg : NULL;
30433043
struct proto *prot = sk->sk_prot;
3044-
bool charged = true;
3044+
bool charged = false;
30453045
long allocated;
30463046

30473047
sk_memory_allocated_add(sk, amt);
30483048
allocated = sk_memory_allocated(sk);
3049-
if (memcg_charge &&
3050-
!(charged = mem_cgroup_charge_skmem(sk->sk_memcg, amt,
3051-
gfp_memcg_charge())))
3052-
goto suppress_allocation;
3049+
3050+
if (memcg) {
3051+
if (!mem_cgroup_charge_skmem(memcg, amt, gfp_memcg_charge()))
3052+
goto suppress_allocation;
3053+
charged = true;
3054+
}
30533055

30543056
/* Under limit. */
30553057
if (allocated <= sk_prot_mem_limits(sk, 0)) {
@@ -3104,8 +3106,8 @@ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind)
31043106
*/
31053107
if (sk->sk_wmem_queued + size >= sk->sk_sndbuf) {
31063108
/* Force charge with __GFP_NOFAIL */
3107-
if (memcg_charge && !charged) {
3108-
mem_cgroup_charge_skmem(sk->sk_memcg, amt,
3109+
if (memcg && !charged) {
3110+
mem_cgroup_charge_skmem(memcg, amt,
31093111
gfp_memcg_charge() | __GFP_NOFAIL);
31103112
}
31113113
return 1;
@@ -3117,8 +3119,8 @@ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind)
31173119

31183120
sk_memory_allocated_sub(sk, amt);
31193121

3120-
if (memcg_charge && charged)
3121-
mem_cgroup_uncharge_skmem(sk->sk_memcg, amt);
3122+
if (charged)
3123+
mem_cgroup_uncharge_skmem(memcg, amt);
31223124

31233125
return 0;
31243126
}

0 commit comments

Comments
 (0)