Skip to contentSkip to conversation

readahead02: readahead hardcoded bytes limit

LTP New Lorenzo Pieralisi 3 participants 4 messages Dec 11, 2015 – Jan 4, 2016

lore
Share & tools
lore
#0 lore raw

Hi,

following kernel commit:

commit 600e19afc5f8a6 ("mm: use only per-device readahead limit")

LTP readahead02 test produces warnings such as:

readahead02    0  TINFO  :  creating test file of size: 67108864#
readahead02 (1698): drop_caches: 1#
readahead02    0  TINFO  :  read_testfile(0)#
readahead02 (1698): drop_caches: 1#
readahead02    0  TINFO  :  read_testfile(1)#
readahead02    1  TPASS  :  expected ret success - returned value = 0#
readahead02    2  TPASS  :  offset is still at 0 as expected#
readahead02    0  TINFO  :  read_testfile(0) took: 125319 usec#
readahead02    0  TINFO  :  read_testfile(1) took: 119364 usec#
readahead02    0  TINFO  :  read_testfile(0) read: 67357696 bytes#
readahead02    0  TINFO  :  read_testfile(1) read: 63098880 bytes#
readahead02    3  TPASS  :  readahead saved some I/O#
readahead02    0  TINFO  :  cache can hold at least: 67372 kB#
readahead02    0  TINFO  :  read_testfile(0) used cache: 65420 kB#
readahead02    0  TINFO  :  read_testfile(1) used cache: 4120 kB#
readahead02    0  TWARN  :  readahead02.c:323: using less cache than expected

It is caused by the hardcoded 2MB readahead02 limit used to issue the readahead syscall, the kernel now caps the number of pages using the per-device readahead limit, so the readahead count parameter should be updated accordingly.

There are multiple ways to fix it, simplest is reading the bdi backing the testfile and use its readahead limit as readahead syscall count parameter.

Please consider updating the test.

Thanks,
Lorenzo

#1 lore raw

Hi Lorenzo!

Thank you! I'll prepare a patch during next week.

--
Roman

11.12.2015, 16:52, "Lorenzo Pieralisi" <[email protected]>:

Quoted 38 lines

Hi,

following kernel commit:

commit 600e19afc5f8a6 ("mm: use only per-device readahead limit")

LTP readahead02 test produces warnings such as:

readahead02 0 TINFO : creating test file of size: 67108864# readahead02 (1698): drop_caches: 1#
readahead02 0 TINFO : read_testfile(0)#
readahead02 (1698): drop_caches: 1#
readahead02 0 TINFO : read_testfile(1)#
readahead02 1 TPASS : expected ret success - returned value = 0# readahead02 2 TPASS : offset is still at 0 as expected# readahead02 0 TINFO : read_testfile(0) took: 125319 usec# readahead02 0 TINFO : read_testfile(1) took: 119364 usec# readahead02 0 TINFO : read_testfile(0) read: 67357696 bytes# readahead02 0 TINFO : read_testfile(1) read: 63098880 bytes# readahead02 3 TPASS : readahead saved some I/O#
readahead02 0 TINFO : cache can hold at least: 67372 kB# readahead02 0 TINFO : read_testfile(0) used cache: 65420 kB# readahead02 0 TINFO : read_testfile(1) used cache: 4120 kB# readahead02 0 TWARN : readahead02.c:323: using less cache than expected

It is caused by the hardcoded 2MB readahead02 limit used to issue the readahead syscall, the kernel now caps the number of pages using the per-device readahead limit, so the readahead count parameter should be updated accordingly.

There are multiple ways to fix it, simplest is reading the bdi backing the testfile and use its readahead limit as readahead syscall count parameter.

Please consider updating the test.

Thanks,
Lorenzo

#2 lore raw

PATCH 1/1 syscalls/readahead02: fix error check

In reply to Lorenzo Pieralisi

After commit 600e19afc5f8a6 ("mm: use only per-device readahead limit") readahead size is not limited anymore by 2 megabytes. Instead, the per-bdi limit is used.

---
 testcases/kernel/syscalls/readahead/readahead02.c | 34 +++++++++++++++++++++--
 1 file changed, 31 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/readahead/readahead02.c +31 -3
index fe0b8a0..b5a7789 100644
@@ -184,6 +184,30 @@ static void create_testfile(void)
 	free(tmp);
 }
 
+static long get_device_readahead(const char *fname)
+{
+	FILE *f;
+	struct stat st;
+	unsigned long ra_kb = 0;
+	char buf[256];
+
+	if (stat(fname, &st) == -1)
+		return -1;
+	snprintf(buf, sizeof(buf), "/sys/dev/block/%d:%d/queue/read_ahead_kb",
+		 major(st.st_dev), minor(st.st_dev));
+	f = fopen(buf, "r");
+	if (!f)
+		return -1;
+
+	if (fscanf(f, "%lu", &ra_kb) != 1) {
+		fclose(f);
+		return -1;
+	}
+
+	fclose(f);
+	return ra_kb * 1024;
+}
+
 /* read_testfile - mmap testfile and read every page.
  * This functions measures how many I/O and time it takes to fully
  * read contents of test file.
@@ -206,16 +230,20 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize,
 	unsigned long time_start_usec, time_end_usec;
 	off_t offset;
 	struct timeval now;
+	long readahead_size;
+
+	readahead_size = get_device_readahead(fname);
+	if (readahead_size == -1)
+		tst_brkm(TBROK, cleanup, "Failed to get readahead size");
 
 	fd = open(fname, O_RDONLY);
 	if (fd < 0)
 		tst_brkm(TBROK | TERRNO, cleanup, "Failed to open %s", fname);
 
 	if (do_readahead) {
-		/* read ahead in chunks, 2MB is maximum since 3.15-rc1 */
-		for (i = 0; i < fsize; i += 2*1024*1024) {
+		for (i = 0; i < fsize; i += readahead_size) {
 			TEST(ltp_syscall(__NR_readahead, fd,
-				(off64_t) i, 2*1024*1024));
+				(off64_t) i, readahead_size));
 			if (TEST_RETURN != 0)
 				break;
 		}
Signature · 1 line
2.5.0
#3 lore raw

PATCH 1/1 syscalls/readahead02: fix error check

----- Original Message -----

Quoted 22 lines

From: "Roman Gushchin" <[email protected]>
To: "lorenzo pieralisi" <[email protected]>
Cc: "Roman Gushchin" <[email protected]>, [email protected]
Sent: Monday, 21 December, 2015 2:21:10 PM
Subject: [LTP] [PATCH] syscalls/readahead02: fix error check

After commit 600e19afc5f8a6 ("mm: use only per-device readahead limit") readahead size is not limited anymore by 2 megabytes. Instead, the per-bdi limit is used.

---
 testcases/kernel/syscalls/readahead/readahead02.c | 34
 +++++++++++++++++++++--
 1 file changed, 31 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/readahead/readahead02.c +0 -0
index fe0b8a0..b5a7789 100644

testcases/kernel/syscalls/readahead/readahead02.c static void create_testfile(void) · line 186

Quoted 3 lines
testcases/kernel/syscalls/readahead/readahead02.c +0 -0
@@ -184,6 +184,30 @@ static void create_testfile(void)
 	free(tmp);
 }
 

Hi,

approach looks OK to me, but as it is now, it will break on older kernels.

testcases/kernel/syscalls/readahead/readahead02.c static void create_testfile(void) · line 195

Quoted 9 lines
testcases/kernel/syscalls/readahead/readahead02.c +9 -0
+static long get_device_readahead(const char *fname)
+{
+	FILE *f;
+	struct stat st;
+	unsigned long ra_kb = 0;
+	char buf[256];
+
+	if (stat(fname, &st) == -1)
+		return -1;

kernels < 4.5 will still impose 2M limit. So if your bdi limit is something larger (say 4M) the test is going to fail. How about we keep the 2M default for kernels prior to 600e19afc5f8a6?

if ((tst_kvercmp(4, 5, 0)) < 0)

    return 2 * 1024 * 1024;

testcases/kernel/syscalls/readahead/readahead02.c static void create_testfile(void) · line 200

Quoted 5 lines
testcases/kernel/syscalls/readahead/readahead02.c +5 -0
+	snprintf(buf, sizeof(buf), "/sys/dev/block/%d:%d/queue/read_ahead_kb",
+		 major(st.st_dev), minor(st.st_dev));
+	f = fopen(buf, "r");
+	if (!f)
+		return -1;

This sysfs file may not exist on older kernels, test now fails with TBROK.

Regards,
Jan

Quoted 45 lines
testcases/kernel/syscalls/readahead/readahead02.c +17 -3
+
+	if (fscanf(f, "%lu", &ra_kb) != 1) {
+		fclose(f);
+		return -1;
+	}
+
+	fclose(f);
+	return ra_kb * 1024;
+}
+
 /* read_testfile - mmap testfile and read every page.
  * This functions measures how many I/O and time it takes to fully
  * read contents of test file.
@@ -206,16 +230,20 @@ static void read_testfile(int do_readahead, const char
 *fname, size_t fsize,
 	unsigned long time_start_usec, time_end_usec;
 	off_t offset;
 	struct timeval now;
+	long readahead_size;
+
+	readahead_size = get_device_readahead(fname);
+	if (readahead_size == -1)
+		tst_brkm(TBROK, cleanup, "Failed to get readahead size");
 
 	fd = open(fname, O_RDONLY);
 	if (fd < 0)
 		tst_brkm(TBROK | TERRNO, cleanup, "Failed to open %s", fname);
 
 	if (do_readahead) {
-		/* read ahead in chunks, 2MB is maximum since 3.15-rc1 */
-		for (i = 0; i < fsize; i += 2*1024*1024) {
+		for (i = 0; i < fsize; i += readahead_size) {
 			TEST(ltp_syscall(__NR_readahead, fd,
-				(off64_t) i, 2*1024*1024));
+				(off64_t) i, readahead_size));
 			if (TEST_RETURN != 0)
 				break;

}
--
2.5.0

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