[LTP] [PATCH v1] readahead02.c: Use fsync instead of sync

Wei Gao wegao@suse.com
Mon Jan 16 08:41:01 CET 2023


Use fsync on test file instead of sync should faster than syncing
whole system.

Signed-off-by: Wei Gao <wegao@suse.com>
---
 .../kernel/syscalls/readahead/readahead02.c     | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/testcases/kernel/syscalls/readahead/readahead02.c b/testcases/kernel/syscalls/readahead/readahead02.c
index 7acf4bb18..e04046bc3 100644
--- a/testcases/kernel/syscalls/readahead/readahead02.c
+++ b/testcases/kernel/syscalls/readahead/readahead02.c
@@ -99,6 +99,17 @@ static void drop_caches(void)
 	SAFE_FILE_PRINTF(DROP_CACHES_FNAME, "1");
 }
 
+static void sync_drop_caches(void)
+{
+	int fd;
+
+	fd  = SAFE_OPEN(testfile, O_RDONLY);
+	if (fsync(fd) == -1)
+		tst_brk(TBROK | TERRNO, "fsync()");
+	SAFE_CLOSE(fd);
+	drop_caches();
+}
+
 static unsigned long get_bytes_read(void)
 {
 	unsigned long ret;
@@ -233,8 +244,7 @@ static void test_readahead(unsigned int n)
 	read_testfile(tc, 0, testfile, testfile_size, &read_bytes, &usec,
 		      &cached);
 	cached_high = get_cached_size();
-	sync();
-	drop_caches();
+	sync_drop_caches();
 	cached_low = get_cached_size();
 	cached_max = MAX(cached_max, cached_high - cached_low);
 
@@ -246,8 +256,7 @@ static void test_readahead(unsigned int n)
 	else
 		cached = 0;
 
-	sync();
-	drop_caches();
+	sync_drop_caches();
 	cached_low = get_cached_size();
 	tst_res(TINFO, "read_testfile(1)");
 	ret = read_testfile(tc, 1, testfile, testfile_size, &read_bytes_ra,
-- 
2.35.3



More information about the ltp mailing list