From c03cbf4b4a94cc8a2f44a94f82dbfd6196c4dba9 Mon Sep 17 00:00:00 2001 From: Michel Machado Date: Thu, 15 Dec 2011 12:00:37 -0500 Subject: [PATCH] Advising the kernel * f3read As long as the kernel honors our advice, f3read doesn't ever read data from the system cache instead of reading from the memory card, and reading speed measurement is improved. * f3write Progress printout goes smoothly now. --- f3read.c | 15 +++++++++++++++ f3write.c | 2 ++ 2 files changed, 17 insertions(+) diff --git a/f3read.c b/f3read.c index bffbe3c..9853cfc 100644 --- a/f3read.c +++ b/f3read.c @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #include "utils.h" @@ -44,6 +46,7 @@ static void validate_file(const char *path, const char *filename, { uint8_t sector[SECTOR_SIZE], *p, *ptr_end; FILE *f; + int fd; int offset_match, error_count; size_t sectors_read; uint64_t offset, expected_offset; @@ -56,9 +59,21 @@ static void validate_file(const char *path, const char *filename, f = fopen(full_fn, "rb"); if (!f) err(errno, "Can't open file %s", full_fn); + fd = fileno(f); + assert(fd >= 0); + + /* If the kernel follows our advice, f3read won't ever read from cache + * even when testing small memory cards without a remount, and + * we should have better reading speed measurement. + */ + assert(!fdatasync(fd)); + assert(!posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED)); /* Obtain initial time. */ assert(!gettimeofday(&t1, NULL)); + /* Help the kernel to help us. */ + assert(!posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL)); + ptr_end = sector + SECTOR_SIZE; sectors_read = fread(sector, SECTOR_SIZE, 1, f); expected_offset = offset_from_filename(filename); diff --git a/f3write.c b/f3write.c index fed832d..7dc10d5 100644 --- a/f3write.c +++ b/f3write.c @@ -107,6 +107,8 @@ static int create_and_fill_file(const char *path, int number, fflush(stdout); pt1 = pt2; } + /* Help the progress to go smoothly. */ + assert(!fdatasync(fd)); } } assert(!fine || size == 0);