[sbm] Alternative Linux ways to monitor send buffers

Jonathan Lennox <jonathan.lennox42@gmail.com> Thu, 03 April 2025 20:38 UTC

Return-Path: <jonathan.lennox42@gmail.com>
X-Original-To: sbm@mail2.ietf.org
Delivered-To: sbm@mail2.ietf.org
Received: from localhost (localhost [127.0.0.1]) by mail2.ietf.org (Postfix) with ESMTP id 4D4261734013 for <sbm@mail2.ietf.org>; Thu, 3 Apr 2025 13:38:12 -0700 (PDT)
X-Virus-Scanned: amavisd-new at ietf.org
X-Spam-Flag: NO
X-Spam-Score: -1.848
X-Spam-Level:
X-Spam-Status: No, score=-1.848 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Authentication-Results: mail2.ietf.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com
Received: from mail2.ietf.org ([166.84.6.31]) by localhost (mail2.ietf.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QUdACjTkGquH for <sbm@mail2.ietf.org>; Thu, 3 Apr 2025 13:38:11 -0700 (PDT)
Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by mail2.ietf.org (Postfix) with ESMTPS id E4D981734003 for <sbm@ietf.org>; Thu, 3 Apr 2025 13:38:11 -0700 (PDT)
Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-879d2e419b9so1075559a12.2 for <sbm@ietf.org>; Thu, 03 Apr 2025 13:38:11 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743712691; x=1744317491; darn=ietf.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=XObDpc9QlYsMNtlN593BL0ZJ7G08UpvfW2LtypeKmg8=; b=XHQ6vfDUJkIiNngl8Nofmh4tFVf9HP5gMSdVmlhP9al2dBpiIk7OXz3zYSMrUjcH3p 0u4OpMx4EDDFRrcEbnuPxpjfjW/IzD0zgweWjHx1BBR0FZyLo6d4yrJwuYSNLBsF90TJ tRxahIZ3VmGrWQR8l7PBlI7XWr2YfMzqFlTM1QAfPFYPJ6w5CrQPgMT4/EdSHDc3PPXC kcXeH/I+li7udvnmtZsxFZ2F40GplkSAskM1Xd8lpar3+J8BWEwkpbKRQ6/gzsrEH0GX Sd5kWrmeJv/TvT6VPyh1yC0jyjTpJjmpuFChf0hYBHX+xmffbYRT7WYJdCxwAx5B7ZSp A9Lw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743712691; x=1744317491; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=XObDpc9QlYsMNtlN593BL0ZJ7G08UpvfW2LtypeKmg8=; b=Whst4rloYKc88b60oD/EB7n4Mfx/S8k9UI81FIwvT+ugAZI9bRbLlPh8bYTJdJGpha rXb8WIWrUL88hT6CaM/BwonqPQVlA0xs7PM6KgFz1dHDM7NcP9dAvEfQKX4IwoPgVPdZ aCuu40AuFwiltdTYhTm0nBTW1BYKiAzVJ3XqXqzb8UQ5fTC9oizN2vOKg9oaYN+RSIIa FpPzZeHCcROVUB3bmBH4fi/q6UVvtPpWlRwqW7QY5qum3XPGEfP0FtQFXpLkBBDVEneu jrsPdsqq0XxPF4E0vBcGVSXw//mZcwnXc3yt6T4hRlkuLbpTqeWXPaWL/41eNqk+TYhI I7pQ==
X-Gm-Message-State: AOJu0Ywn1UahXOZmIKWEPJYsADlDOO1tIUrPiolUvPR62Kot1i7WvMXH wr5POVdtnrpOMfp8Po8CIPbMnw6j7YKVM+kp1uKH1L3C4Pbo+7aQWvjBlwFQ0EHXKVPuNhcryCR d+uuw0mtR+F/JZSyCfpX5z4XVG4IRiyTp7S0=
X-Gm-Gg: ASbGncsctQH+YwZCWM/HUs4m0mm6Sl4WSfGvpTL4uWhUyF8pVdHmyuC/n06UnZ+0Q0v 6OP9SgqL2paADUwoi5x/Dfqj0Klz6GkLIh649MnZyPvXXe6XY5jTzlUbL7v7Sltwu2pH3TfiZdd 1W/cplGRcDI7XpqKxG2J20/hI8muRojudjX6HA+XU1/rMhj3I8eBRCleZbRg==
X-Google-Smtp-Source: AGHT+IGLRK2nmILXjrfWFwJzmBiPTRJzT4Rqsqk0d99CGVIDJzCFaZ1iwB24xRdlgROUVeAYPTr0i5GDiunH0bHPLxI=
X-Received: by 2002:a17:90b:5688:b0:2f9:bcd8:da33 with SMTP id 98e67ed59e1d1-306a485efcemr1278034a91.21.1743712690712; Thu, 03 Apr 2025 13:38:10 -0700 (PDT)
MIME-Version: 1.0
From: Jonathan Lennox <jonathan.lennox42@gmail.com>
Date: Thu, 03 Apr 2025 16:37:59 -0400
X-Gm-Features: AQ5f1JqZEu4qIRyuwHVynVMYD5wakusMFyavyiYKXDfsOpKXN2GE7wQjXYpXAFc
Message-ID: <CAKx+b+bLE2C7ogyG8czoqSSLV2hKU=PdoGhtQKv25bVi9779rg@mail.gmail.com>
To: sbm@ietf.org
Content-Type: multipart/alternative; boundary="0000000000008546230631e5bf64"
Message-ID-Hash: 62NPKZPA7EXCACBEY4S2WFKRJ3ETATJS
X-Message-ID-Hash: 62NPKZPA7EXCACBEY4S2WFKRJ3ETATJS
X-MailFrom: jonathan.lennox42@gmail.com
X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header
X-Mailman-Version: 3.3.9rc6
Precedence: list
Subject: [sbm] Alternative Linux ways to monitor send buffers
List-Id: Source Buffer Management <sbm.ietf.org>
Archived-At: <https://mailarchive.ietf.org/arch/msg/sbm/MJI6m_oKVFrnoYOvjG8p1QwDkYo>
List-Archive: <https://mailarchive.ietf.org/arch/browse/sbm>
List-Help: <mailto:sbm-request@ietf.org?subject=help>
List-Owner: <mailto:sbm-owner@ietf.org>
List-Post: <mailto:sbm@ietf.org>
List-Subscribe: <mailto:sbm-join@ietf.org>
List-Unsubscribe: <mailto:sbm-leave@ietf.org>

In the absence of TCP_REPLENISH_TIME or a "working" TCP_NOTSENT_LOWAT on
Linux, I thought I'd mention some other Linux approaches that could be used
to monitor send buffers.

1.  The linux ioctl SIOCOUTQNSD returns the current amount of unsent data
waiting in a socket, so a socket could be periodically monitored until this
value falls below a desired threshold.  This would likely be a significant
amount of overhead in a production application, however, so probably isn't
a great solution.

2. The Linux SO_TIMESTAMPING sockopt can be used to give an application
callback whenever the data in a write (or send, or sendmsg) call has been
queued for transmission to a network device.  WIth the flags
SOF_TIMESTAMPING_TX_SCHED | SOF_TIMESTAMPING_SOFTWARE |
SOF_TIMESTAMPING_OPT_ID | SOF_TIMESTAMPING_OPT_ID_TCP |
SOF_TIMESTAMPING_OPT_TSONLY, a notification will be available on the
socket's error queue which includes the offset of the data transmitted, so
if the application keeps track of the total amount of data sent, it can
compute the remaining amount of unsent data, with somewhat less overhead
than option 1.  This does, however, have the disadvantage that you get an
extra kernel notification for every write, and the granularity of the
notifications you get depend on the granularity of your write calls, which
depending on your application architecture might be a poor fit to when you
want your notifications; but potentially some sort of double-buffering
approach could be done.

Does anyone have any other suggestions?