[PATCH 2/5] tftp: warn when seek-heavy access wastes network bandwidth

Ahmad Fatoum a.fatoum at pengutronix.de
Thu Mar 12 07:44:22 PDT 2026


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 at 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




More information about the barebox mailing list