From: Abel Wu <wuyun.abel@bytedance.com>
To: Paolo Abeni <pabeni@redhat.com>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>
Cc: Simon Horman <simon.horman@corigine.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: Re: [PATCH v3 4/5] sock: Consider memcg pressure when raising sockmem
Date: Tue, 23 May 2023 19:29:20 +0800 [thread overview]
Message-ID: <79945d0c-2430-c094-f3ba-12ee428eb8c7@bytedance.com> (raw)
In-Reply-To: <58241c427684e6da0ab454d344421c2fb29a0465.camel@redhat.com>
On 5/23/23 6:26 PM, Paolo Abeni wrote:
> On Tue, 2023-05-23 at 17:46 +0800, Abel Wu wrote:
>> For now __sk_mem_raise_allocated() mainly considers global socket
>> memory pressure and allows to raise if no global pressure observed,
>> including the sockets whose memcgs are in pressure, which might
>> result in longer memcg memstall.
>>
>> So take net-memcg's pressure into consideration when allocating
>> socket memory to alleviate long tail latencies.
>>
>> Signed-off-by: Abel Wu <wuyun.abel@bytedance.com>
>> ---
>> net/core/sock.c | 23 ++++++++++++++++-------
>> 1 file changed, 16 insertions(+), 7 deletions(-)
>>
>> diff --git a/net/core/sock.c b/net/core/sock.c
>> index 801df091e37a..b899e0b9feda 100644
>> --- a/net/core/sock.c
>> +++ b/net/core/sock.c
>> @@ -2976,22 +2976,31 @@ 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;
>> + bool charged = true, pressured = false;
>> struct proto *prot = sk->sk_prot;
>> - bool charged = true;
>> 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_charge) {
>> + charged = mem_cgroup_charge_skmem(sk->sk_memcg, amt,
>> + gfp_memcg_charge());
>> + if (!charged)
>> + goto suppress_allocation;
>> + if (mem_cgroup_under_socket_pressure(sk->sk_memcg))
>> + pressured = true;
>> + }
>>
>> /* Under limit. */
>> - if (allocated <= sk_prot_mem_limits(sk, 0)) {
>> + if (allocated <= sk_prot_mem_limits(sk, 0))
>> sk_leave_memory_pressure(sk);
>> + else
>> + pressured = true;
>
> The above looks not correct to me.
>
> allocated > sk_prot_mem_limits(sk, 0)
>
> does not mean the protocol has memory pressure. Such condition is
> checked later with:
>
> if (allocated > sk_prot_mem_limits(sk, 1))
Yes, this condition stands means the global socket memory is absolutely
under pressure, and the status is sustained until @allocated falls down
to sk_prot_mem_limits(sk, 0). I see some places in the source tree call
it 'soft pressure' if usage between index [0] and [1].
The idea behind this patch is to allow the socket memory to raise if
there is no pressure neither in global nor net-memcg. With the condition
@allocated > sk_prot_mem_limits(sk, 0)
we can't be sure whether there is pressure or not in global. And this
also aligns with the original logic if net-memcg is not used.
I am thinking changing the name of this variable to @might_pressured or
something to better illustrate the status of memory pressure. What do
you think?
>
> Here an allocation could fail even if memcg charge is successful and
> the protocol is not under pressure, which in turn sounds quite (too
> much?) conservative.
IIUC the failure can only be due to its memcg under vmpressure. In this
case allowing the allocation would burden the mm subsys with increased
fragmented unmovable/unreclaimable memory.
Thanks & Best,
Abel
next prev parent reply other threads:[~2023-05-23 11:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-23 9:46 [PATCH v3 0/5] sock: Improve condition on sockmem pressure Abel Wu
2023-05-23 9:46 ` [PATCH v3 1/5] net-memcg: Fold dependency into memcg pressure cond Abel Wu
2023-05-23 9:46 ` [PATCH v3 2/5] sock: Always take memcg pressure into consideration Abel Wu
2023-05-23 9:46 ` [PATCH v3 3/5] sock: Fix misuse of sk_under_memory_pressure() Abel Wu
2023-05-23 9:46 ` [PATCH v3 4/5] sock: Consider memcg pressure when raising sockmem Abel Wu
2023-05-23 10:26 ` Paolo Abeni
2023-05-23 11:29 ` Abel Wu [this message]
2023-05-23 9:46 ` [PATCH v3 5/5] sock: Remove redundant cond of memcg pressure Abel Wu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=79945d0c-2430-c094-f3ba-12ee428eb8c7@bytedance.com \
--to=wuyun.abel@bytedance.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=simon.horman@corigine.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®