Linux Test Project
 help / color / mirror / Atom feed
From: Andrea Cervesato via ltp <ltp@lists.linux.it>
To: "Victor Cheng-Yen Yang" <cyyang772@andestech.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] readahead02: Fall back to the parent disk's BDI for partitions
Date: Tue, 25 Aug 2026 14:45:55 +0000	[thread overview]
Message-ID: <6a8daaa4.e9adc614.a6594.5b0f@mx.google.com> (raw)
In-Reply-To: <20260821063248.2208776-1-cyyang772@andestech.com>

Hi Victor,

> 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.
> 
> Signed-off-by: Victor Cheng-Yen Yang <cyyang772@andestech.com>
> ---
>  testcases/kernel/syscalls/readahead/readahead02.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/readahead/readahead02.c b/testcases/kernel/syscalls/readahead/readahead02.c
> index b65213ad0..6707a1c63 100644
> --- a/testcases/kernel/syscalls/readahead/readahead02.c
> +++ b/testcases/kernel/syscalls/readahead/readahead02.c
> @@ -399,8 +399,14 @@ 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;
> +
> +	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;
> +	}
>  
>  	SAFE_FILE_SCANF(sys_bdi_ra_path, "%d", &orig_bdi_limit);
>  
> -- 
> 2.34.1
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

you can handle this by using the internal tst_sys_conf_save()
function:

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 = {



--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

      parent reply	other threads:[~2026-08-25 14:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21  6:32 [LTP] [PATCH] readahead02: Fall back to the parent disk's BDI for partitions Victor Cheng-Yen Yang via ltp
2026-08-21  6:53 ` [LTP] " linuxtestproject.agent
2026-08-25 14:45 ` Andrea Cervesato via ltp [this message]

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=6a8daaa4.e9adc614.a6594.5b0f@mx.google.com \
    --to=ltp@lists.linux.it \
    --cc=andrea.cervesato@suse.com \
    --cc=cyyang772@andestech.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox