[LTP] [PATCH v2] readahead02: Fall back to the parent disk's BDI for partitions

Victor Cheng-Yen Yang cyyang772@andestech.com
Wed Aug 26 04:03:37 CEST 2026


Partitions (e.g. mmcblk0p3) do not have their own BDI sysfs entry;
the BDI belongs to the parent disk.

In sysfs a partition is a subdirectory of its disk, so retry one
level up. That resolves for every partition naming scheme without
parsing the device name.

Without this fix, setup_readahead_length() silently returns the
default readahead_length, causing lots of readahead() calls per
test case and a multi-hour runtime on MMC-backed FPGA boards.

Also use tst_sys_conf_save() instead of manually save/restore
orig_bdi_limit. It only worked when orig_bdi_limit was non-zero.
A parent BDI starting at 0 would be left at the raised limit after
the test, along with every sibling partition sharing that BDI.

Signed-off-by: Victor Cheng-Yen Yang <cyyang772@andestech.com>
---
Changes in v2:
- Use tst_sys_conf_save to handle orig_bdi_limit save and restore.
- Amend the commit message.

 .../kernel/syscalls/readahead/readahead02.c   | 21 ++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/testcases/kernel/syscalls/readahead/readahead02.c b/testcases/kernel/syscalls/readahead/readahead02.c
index b65213ad0..4f201d65d 100644
--- a/testcases/kernel/syscalls/readahead/readahead02.c
+++ b/testcases/kernel/syscalls/readahead/readahead02.c
@@ -47,7 +47,6 @@ static unsigned long cached_max;
 static int ovl_mounted;
 static int readahead_length  = 4096;
 static char sys_bdi_ra_path[PATH_MAX];
-static int orig_bdi_limit;
 
 static const char mntpoint[] = OVL_BASE_MNTPOINT;
 
@@ -388,6 +387,11 @@ static void setup_readahead_length(void)
 	struct stat sbuf;
 	char tmp[PATH_MAX], *backing_dev;
 	int ra_new_limit, ra_limit;
+	struct tst_path_val bdi_ra = {
+		.path = sys_bdi_ra_path,
+		.val = NULL,
+		.flags = TST_SR_TBROK
+	};
 
 	/* Find out backing device name */
 	SAFE_LSTAT(tst_device->dev, &sbuf);
@@ -399,10 +403,16 @@ static void setup_readahead_length(void)
 	backing_dev = basename(tmp);
 	sprintf(sys_bdi_ra_path, "/sys/class/block/%s/bdi/read_ahead_kb",
 		backing_dev);
-	if (access(sys_bdi_ra_path, F_OK))
-		return;
 
-	SAFE_FILE_SCANF(sys_bdi_ra_path, "%d", &orig_bdi_limit);
+	if (access(sys_bdi_ra_path, F_OK)) {
+		/* Partitions use the parent disk's BDI sysfs entry */
+		snprintf(sys_bdi_ra_path, sizeof(sys_bdi_ra_path),
+			"/sys/class/block/%s/../bdi/read_ahead_kb", backing_dev);
+		if (access(sys_bdi_ra_path, F_OK))
+			return;
+	}
+
+	tst_sys_conf_save(&bdi_ra);
 
 	/* raise bdi limit as much as kernel allows */
 	ra_new_limit = testfile_size / 1024;
@@ -446,9 +456,6 @@ static void cleanup(void)
 {
 	if (ovl_mounted)
 		SAFE_UMOUNT(OVL_MNT);
-
-	if (orig_bdi_limit)
-		SAFE_FILE_PRINTF(sys_bdi_ra_path, "%d", orig_bdi_limit);
 }
 
 static struct tst_test test = {
-- 
2.34.1



More information about the ltp mailing list