All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v2] syscalls/readahead02: use bdi max readahead limit
@ 2016-03-15 14:40 Jan Stancek
  2016-03-15 14:52 ` Cyril Hrubis
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Stancek @ 2016-03-15 14:40 UTC (permalink / raw)
  To: ltp

From: Roman Gushchin <klamm@yandex-team.ru>

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 for kernels 4.4 and older.

Signed-off-by: Roman Gushchin <klamm@yandex-team.ru>
Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 testcases/kernel/syscalls/readahead/readahead02.c | 40 +++++++++++++++++++++--
 1 file changed, 37 insertions(+), 3 deletions(-)

Changes in v2:
- added check to use bdi readahead max only for kernels 4.4 and later
- tested on 3.10 kernel (RHEL7) and upstream 4.5 on x86_64

diff --git a/testcases/kernel/syscalls/readahead/readahead02.c b/testcases/kernel/syscalls/readahead/readahead02.c
index 90ad853f17fa..c014579c3b11 100644
--- a/testcases/kernel/syscalls/readahead/readahead02.c
+++ b/testcases/kernel/syscalls/readahead/readahead02.c
@@ -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,26 @@ 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;
+
+	if ((tst_kvercmp(4, 4, 0)) >= 0) {
+		readahead_size = get_device_readahead(fname);
+		if (readahead_size == -1)
+			tst_brkm(TBROK, cleanup, "get_device_readahead");
+	} else {
+		/* default to 2M, which should work on kernels prior to 4.4 */
+		readahead_size = 2 * 1024 * 1024;
+	}
+	tst_resm(TINFO, "max readahead size is: %ld", 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;
 		}
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [LTP] [PATCH v2] syscalls/readahead02: use bdi max readahead limit
  2016-03-15 14:40 [LTP] [PATCH v2] syscalls/readahead02: use bdi max readahead limit Jan Stancek
@ 2016-03-15 14:52 ` Cyril Hrubis
  2016-03-15 14:56   ` Jan Stancek
  0 siblings, 1 reply; 3+ messages in thread
From: Cyril Hrubis @ 2016-03-15 14:52 UTC (permalink / raw)
  To: ltp

Hi!
> +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);

Any reason why we don't do SAFE_FILE_SCANF() instead of fopen(),
fscanf(), fclose() here? We call tst_brkm(TBROK, ...) when this call
returs -1 in the read_testfile() anyway...

> +	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,26 @@ 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;
> +
> +	if ((tst_kvercmp(4, 4, 0)) >= 0) {
> +		readahead_size = get_device_readahead(fname);
> +		if (readahead_size == -1)
> +			tst_brkm(TBROK, cleanup, "get_device_readahead");
> +	} else {
> +		/* default to 2M, which should work on kernels prior to 4.4 */
> +		readahead_size = 2 * 1024 * 1024;
> +	}
> +	tst_resm(TINFO, "max readahead size is: %ld", 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;
>  		}
> -- 
> 1.8.3.1
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [LTP] [PATCH v2] syscalls/readahead02: use bdi max readahead limit
  2016-03-15 14:52 ` Cyril Hrubis
@ 2016-03-15 14:56   ` Jan Stancek
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Stancek @ 2016-03-15 14:56 UTC (permalink / raw)
  To: ltp





----- Original Message -----
> From: "Cyril Hrubis" <chrubis@suse.cz>
> To: "Jan Stancek" <jstancek@redhat.com>
> Cc: ltp@lists.linux.it, klamm@yandex-team.ru
> Sent: Tuesday, 15 March, 2016 3:52:17 PM
> Subject: Re: [LTP] [PATCH v2] syscalls/readahead02: use bdi max readahead limit
> 
> Hi!
> > +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);
> 
> Any reason why we don't do SAFE_FILE_SCANF() instead of fopen(),
> fscanf(), fclose() here? We call tst_brkm(TBROK, ...) when this call
> returs -1 in the read_testfile() anyway...

True. I was planning to ignore failure, since this sys file doesn't exist on
older kernels, but with added kvercmp this is no longer the case.
I'll replace it with SAFE_FILE_SCANF.

Regards,
Jan

> 
> > +	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,26 @@ 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;
> > +
> > +	if ((tst_kvercmp(4, 4, 0)) >= 0) {
> > +		readahead_size = get_device_readahead(fname);
> > +		if (readahead_size == -1)
> > +			tst_brkm(TBROK, cleanup, "get_device_readahead");
> > +	} else {
> > +		/* default to 2M, which should work on kernels prior to 4.4 */
> > +		readahead_size = 2 * 1024 * 1024;
> > +	}
> > +	tst_resm(TINFO, "max readahead size is: %ld", 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;
> >  		}
> > --
> > 1.8.3.1
> > 
> > 
> > --
> > Mailing list info: https://lists.linux.it/listinfo/ltp
> 
> --
> Cyril Hrubis
> chrubis@suse.cz
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-03-15 14:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-15 14:40 [LTP] [PATCH v2] syscalls/readahead02: use bdi max readahead limit Jan Stancek
2016-03-15 14:52 ` Cyril Hrubis
2016-03-15 14:56   ` Jan Stancek

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.