All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthieu Baerts <matttbe@kernel.org>
To: Eric Dumazet <edumazet@kernel.org>
Cc: lei lei <llleigoing@outlook.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"mptcp@lists.linux.dev" <mptcp@lists.linux.dev>,
	"ncardwell@google.com" <ncardwell@google.com>,
	"kuniyu@google.com" <kuniyu@google.com>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"kuba@kernel.org" <kuba@kernel.org>,
	"pabeni@redhat.com" <pabeni@redhat.com>,
	"horms@kernel.org" <horms@kernel.org>,
	"martineau@kernel.org" <martineau@kernel.org>,
	"geliang@kernel.org" <geliang@kernel.org>
Subject: Re: [PATCH net 3/3] mptcp: exclude MSG_PEEK from receive buffer autotuning
Date: Thu, 19 Nov 2026 19:33:23 +0100	[thread overview]
Message-ID: <cab39a1c-056f-488f-b217-194af2056db2@kernel.org> (raw)
In-Reply-To: <CAL4WiioFmJXhfGSY7rs7aR3FA_xC_f0sjuArBo7CBjV_tXTbTw@mail.gmail.com>

Hi Eric, Lei,

Thank you for the patch, and for the review!

On 19/11/2026 08:59, Eric Dumazet wrote:
> Le mar. 17 nov. 2026 à 06:22, lei lei <llleigoing@outlook.com> a écrit :
>>
>> __mptcp_recvmsg_mskq() passes bytes copied by MSG_PEEK to
>> mptcp_rcv_space_adjust(), although those bytes remain in the receive
>> queue. Repeated peeks count the same data as new application
>> consumption and can inflate the receive-memory budget. Subtracting the
>> unread queue at a measurement boundary cannot undo that repeated count.
>>
>> The receive path originally skipped this adjustment for MSG_PEEK.
>> Commit 581302298524 ("mptcp: error out earlier on disconnect") moved
>> the adjustment calls without preserving that check.
>>
>> Only adjust receive space for non-peeking reads. Keep the returned
>> byte count unchanged.
> 
> This one looks good to me.
> 
> mptcp_rcv_space_adjust() accumulates @copied in msk->rcvq_space.copied,
> and mptcp_inq_hint() is subtracted once per measurement, so N peeks
> of the same bytes are indeed counted N times.
> 
> (TCP also calls tcp_rcv_space_adjust() for MSG_PEEK, but it uses
> tp->copied_seq, which is not changed by a peek, so it has no such
> issue.)
> 
> The Fixes: tag is correct, commit 581302298524 removed the
> "if (!(flags & MSG_PEEK))" test.

It looks good to me too, please send a v2 with the Signed-off-by:

Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>

>> A loopback test leaves a fixed 32 KiB queue unread and peeks 4096 times.
>> Before this change, sk_rcvbuf grows to the configured 8 MiB limit.
>> Afterwards, both the budget and the queue remain unchanged, and a
>> subsequent consuming read returns the original data intact.
> 
> It would be nice to have this test in
> tools/testing/selftests/net/mptcp/ (or as a packetdrill test),
> MPTCP maintainers can tell you what they prefer.

Good idea! We prefer a packetdrill test here, using the MPTCP fork [1]:
such tests are usually shorter and easier to read than a new selftest,
and our CI
runs them.

@Lei: could you open a PR on this separate repository with a new test,
please? For example in gtests/net/mptcp/syscalls/recv_peek_rcvbuf.pkt,
next to recv_peek_waitall.pkt. Feel free to use the following script if
it works on your side. You can test it with:

  ./packetdrill/run_all.py -lv mptcp/syscalls/recv_peek_rcvbuf.pkt


------------------------- 8< -------------------------
  // MSG_PEEK must not be counted as consumed data by the rcvbuf autotuning
  --tolerance_usecs=100000
  `../common/defaults.sh`

  // Small initial rcvbuf: without the fix, a few peeks are enough to grow it
  +0.0  `sysctl -q net.ipv4.tcp_rmem="4096 8192 15728640"`

  +0.0  socket(..., SOCK_STREAM, IPPROTO_MPTCP) = 3
  +0.0  setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
  +0.0  bind(3, ..., ...) = 0
  +0.0  listen(3, 1) = 0

  // With TS, the first data gives an RTT sample (~100ms), needed by autotuning
  +0.0    <  S   0:0(0)                win 65535  <mss 1460, sackOK, TS val 100 ecr 0,   nop, wscale 8, mpcapable v1 flags[flag_h] nokey>
  +0.0    >  S.  0:0(0)        ack 1              <mss 1460, sackOK, TS val 700 ecr 100, nop, wscale 8, mpcapable v1 flags[flag_h] key[skey]>
  +0.1    <   .  1:1(0)        ack 1     win 256  <nop, nop,         TS val 200 ecr 700,                mpcapable v1 flags[flag_h] key[ckey=2, skey]>
  +0.0  accept(3, ..., ...) = 4

  +0.0    <  P.  1:1001(1000)  ack 1     win 256  <nop, nop,         TS val 300 ecr 700,                mpcapable v1 flags[flag_h] key[skey, ckey] mpcdatalen 1000, nop, nop>
  +0.0    >   .  1:1(0)        ack 1001           <nop, nop,         TS val 700 ecr 300,                dss dack8=1001 dll=0 nocs>

  // Peek the same data multiple times within one RTT...
  +0.0  recv(4, ..., 1000, MSG_PEEK) = 1000
  +0.0  recv(4, ..., 1000, MSG_PEEK) = 1000
  +0.0  recv(4, ..., 1000, MSG_PEEK) = 1000
  +0.0  recv(4, ..., 1000, MSG_PEEK) = 1000
  +0.0  recv(4, ..., 1000, MSG_PEEK) = 1000

  // ... then once more after one RTT: nothing consumed, the rcvbuf is unchanged
  +0.2  recv(4, ..., 1000, MSG_PEEK) = 1000
  +0.0  getsockopt(4, SOL_SOCKET, SO_RCVBUF, [8192], [4]) = 0

------------------------- 8< -------------------------

[1] https://github.com/multipath-tcp/packetdrill

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.


  reply	other threads:[~2026-11-19 18:33 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  5:22 [PATCH net 0/3] tcp, mptcp: fix receive buffer sizing and peek accounting lei lei
2026-11-17  5:22 ` [PATCH net 1/3] tcp: saturate window-to-memory conversions at INT_MAX lei lei
2026-11-18  5:22   ` sashiko-bot
2026-11-19  7:54   ` Eric Dumazet
2026-11-20  8:22   ` netdev-bot+sashiko
2026-11-17  5:22 ` [PATCH net 2/3] net: bound receive window predictions before narrowing lei lei
2026-11-18  5:22   ` sashiko-bot
2026-11-19  7:56   ` Eric Dumazet
2026-11-20  8:22   ` netdev-bot+sashiko
2026-11-17  5:22 ` [PATCH net 3/3] mptcp: exclude MSG_PEEK from receive buffer autotuning lei lei
2026-11-18  5:22   ` sashiko-bot
2026-11-19  7:59   ` Eric Dumazet
2026-11-19 18:33     ` Matthieu Baerts [this message]
2026-11-20  8:05       ` Lin Lei
2026-11-20  8:22   ` netdev-bot+sashiko
2026-11-17  7:04 ` [PATCH net 0/3] tcp, mptcp: fix receive buffer sizing and peek accounting MPTCP CI

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=cab39a1c-056f-488f-b217-194af2056db2@kernel.org \
    --to=matttbe@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=geliang@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=llleigoing@outlook.com \
    --cc=martineau@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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 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.