mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
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 <wuyun.abel@bytedance.com> Acked-by: Shakeel Butt <shakeelb@google.com> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://lore.kernel.org/r/20231019120026.42215-1-wuyun.abel@bytedance.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
parent
f6e1227701
commit
2def8ff3fd
1 changed files with 12 additions and 10 deletions
|
@ -3039,17 +3039,19 @@ EXPORT_SYMBOL(sk_wait_data);
|
||||||
*/
|
*/
|
||||||
int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind)
|
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;
|
struct proto *prot = sk->sk_prot;
|
||||||
bool charged = true;
|
bool charged = false;
|
||||||
long allocated;
|
long allocated;
|
||||||
|
|
||||||
sk_memory_allocated_add(sk, amt);
|
sk_memory_allocated_add(sk, amt);
|
||||||
allocated = sk_memory_allocated(sk);
|
allocated = sk_memory_allocated(sk);
|
||||||
if (memcg_charge &&
|
|
||||||
!(charged = mem_cgroup_charge_skmem(sk->sk_memcg, amt,
|
if (memcg) {
|
||||||
gfp_memcg_charge())))
|
if (!mem_cgroup_charge_skmem(memcg, amt, gfp_memcg_charge()))
|
||||||
goto suppress_allocation;
|
goto suppress_allocation;
|
||||||
|
charged = true;
|
||||||
|
}
|
||||||
|
|
||||||
/* Under limit. */
|
/* Under limit. */
|
||||||
if (allocated <= sk_prot_mem_limits(sk, 0)) {
|
if (allocated <= sk_prot_mem_limits(sk, 0)) {
|
||||||
|
@ -3104,8 +3106,8 @@ suppress_allocation:
|
||||||
*/
|
*/
|
||||||
if (sk->sk_wmem_queued + size >= sk->sk_sndbuf) {
|
if (sk->sk_wmem_queued + size >= sk->sk_sndbuf) {
|
||||||
/* Force charge with __GFP_NOFAIL */
|
/* Force charge with __GFP_NOFAIL */
|
||||||
if (memcg_charge && !charged) {
|
if (memcg && !charged) {
|
||||||
mem_cgroup_charge_skmem(sk->sk_memcg, amt,
|
mem_cgroup_charge_skmem(memcg, amt,
|
||||||
gfp_memcg_charge() | __GFP_NOFAIL);
|
gfp_memcg_charge() | __GFP_NOFAIL);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -3117,8 +3119,8 @@ suppress_allocation:
|
||||||
|
|
||||||
sk_memory_allocated_sub(sk, amt);
|
sk_memory_allocated_sub(sk, amt);
|
||||||
|
|
||||||
if (memcg_charge && charged)
|
if (charged)
|
||||||
mem_cgroup_uncharge_skmem(sk->sk_memcg, amt);
|
mem_cgroup_uncharge_skmem(memcg, amt);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue