From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/5] tftp: warn when seek-heavy access wastes network bandwidth
Date: Thu, 12 Mar 2026 15:44:22 +0100 [thread overview]
Message-ID: <20260312144428.2158727-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260312144428.2158727-1-a.fatoum@pengutronix.de>
Patterns that work ok-ish on local file systems like opening a file
repeatedly and/or seeking to different offsets can have catastrophic
performance on TFTP, because every seek must read and discard data up to
the desired offset.
Add a lightweight heuristic accumulating the total bytes discarded by
seeks and emit a one-time warning, once we exceed 4 MiB of wasted reads.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/tftp.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/fs/tftp.c b/fs/tftp.c
index dd4804041cde..e5a276ed5cae 100644
--- a/fs/tftp.c
+++ b/fs/tftp.c
@@ -902,6 +902,7 @@ static int tftp_read(struct file *f, void *buf, size_t insize)
static int tftp_lseek(struct file *f, loff_t pos)
{
+ static loff_t seek_discard_total;
int ret = 0;
char *buf;
loff_t f_pos = f->f_pos;
@@ -931,6 +932,13 @@ static int tftp_lseek(struct file *f, loff_t pos)
out_free:
free(buf);
+
+ seek_discard_total += f_pos - f->f_pos;
+ if (seek_discard_total > SZ_4M)
+ pr_warn_once("excessive seeking (%lld bytes discarded so far);"
+ " consider copying file to RAM first?\n",
+ seek_discard_total);
+
if (ret < 0) {
/*
* Update f->pos even if the overall request
--
2.47.3
next prev parent reply other threads:[~2026-03-12 14:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-12 14:44 [PATCH 1/5] tftp: skip memory allocation when seeking to current position Ahmad Fatoum
2026-03-12 14:44 ` Ahmad Fatoum [this message]
2026-03-12 14:44 ` [PATCH 3/5] tftp: emulate backwards seek by reopening the file Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 4/5] libfile: drop TFTP-specific hack in open_fdt() Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 5/5] fs: fix relative path resolution when CWD is on a TFTP mount Ahmad Fatoum
2026-03-17 10:21 ` [PATCH 1/5] tftp: skip memory allocation when seeking to current position Sascha Hauer
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=20260312144428.2158727-2-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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