All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Fastabend <john.fastabend@gmail.com>
To: zhengguoyong <zhenggy@chinatelecom.cn>,
	"【外部账号】 John Fastabend" <john.fastabend@gmail.com>,
	jakub@cloudflare.com, bpf@vger.kernel.org
Subject: Re: [issue]: sockmap restrain send if receiver block
Date: Tue, 25 Jun 2024 12:51:07 -0700	[thread overview]
Message-ID: <667b1fab10204_5424208f@john.notmuch> (raw)
In-Reply-To: <4cf6d911-9dc4-4588-be1f-cfee675e174e@chinatelecom.cn>

zhengguoyong wrote:
> thanks for reply.
> 
> i mean the sk_msg with TCP protocol. in this case, sender use sk_stream_memory_free()
> to check if memory is free. and in __sk_stream_memory_free(), if
> sk->sk_wmem_queued is bigger then sk->sk_sndbuf or sk
> notsent_bytes(tp->write_seq - tp->snd_nxt) is too bigger then
> __sk_stream_memory_free() will return false and do sk_stream_wait_memory().
> 
> but in sk_msg mode, tcp_bpf_sendmsg() will not create skb structure and not use seq to
> recording sending info,so sk->sk_wmem_queued is not changed in tcp_bpf_sendmsg() path,
> and __sk_stream_memory_free() will always return true.
> 
> in bpf_tcp_ingress() will copy the sender msg and charge it, and in
> tcp_bpf_recvmsg(), it will uncharge the msg after sk_msg_recvmsg()
> receive it from psock ingress_msg queue, and if receiver is not to read again
> due to application bug, and sender continuous send, then the receiver
> psock ingress_msg queue will continuous increase and cannot be uncharged
> until tcp socket memory is not enough in the fllowing path.
> 
>     tcp_bpf_sendmsg
>         tcp_bpf_send_verdict
>             tcp_bpf_sendmsg_redir
>                 bpf_tcp_ingress
>                     sk_wmem_schedule

Shouldn't the sk_wmem_schedule push back through __sk_mem_schedule() and
cause us to return a ENOMEM here? The ENOMEM then will free the msg and
return ENOMEM all the way back through tcp_bpf_sendmsg and to the user
eventually. 

That sk_wmem_schedule() for ingress should be sk_rmem_schedule()?

I think the fix is to ensure that if we try to bpf_tcp_ingress onto a
receive socket that it pushes back if its memory limits are reached.

> 
> so if a sk_msg type sockmap receiver is block, then it may consume all the
> tcp socket memory and influence other tcp stream,
> can we limit per sockmap tcp stream link sk->sk_sndbuf ?
> 
> thanks.

      parent reply	other threads:[~2024-06-25 19:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-17  2:01 [issue]: sockmap restrain send if receiver block 郑国勇
2024-06-17 17:07 ` John Fastabend
2024-06-18  7:47   ` zhengguoyong
2024-06-18  8:08   ` zhengguoyong
2024-06-21  6:44     ` zhengguoyong
2024-06-25 19:51     ` John Fastabend [this message]

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=667b1fab10204_5424208f@john.notmuch \
    --to=john.fastabend@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=jakub@cloudflare.com \
    --cc=zhenggy@chinatelecom.cn \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.