diff options
author | Rom Lemarchand <romlem@android.com> | 2016-05-16 20:17:41 -0700 |
---|---|---|
committer | Rom Lemarchand <romlem@google.com> | 2016-05-16 20:19:55 -0700 |
commit | ba2475cd4d750288d24432ca51f3d62ec52bd9c1 (patch) | |
tree | d1421ba65d0328dc15d881d2908eded94851a5f7 /tests | |
parent | b1b964214babaddd0f0bd758c54f7fac4fbe4bf7 (diff) | |
download | extras-ba2475cd4d750288d24432ca51f3d62ec52bd9c1.tar.gz |
pagingtest: switch to advising random accesses
Switch to using madvise(MADV_RANDOM) and posix_fadvise(POSIX_FADV_RANDOM)
to disable caching as opposed to reading the file backwards, which still
went through some caching.
Measured a 80% drop in worst case performance after switching.
Change-Id: I03115dfb94ae7dfc58e0e187af3936c4e371817f
Diffstat (limited to 'tests')
-rw-r--r-- | tests/pagingtest/pageinout_test.c | 13 | ||||
-rw-r--r-- | tests/pagingtest/thrashing_test.c | 12 |
2 files changed, 18 insertions, 7 deletions
diff --git a/tests/pagingtest/pageinout_test.c b/tests/pagingtest/pageinout_test.c index b9b20de6..eaa116c1 100644 --- a/tests/pagingtest/pageinout_test.c +++ b/tests/pagingtest/pageinout_test.c @@ -13,7 +13,7 @@ int pageinout_test(int test_runs, unsigned long long file_size) { char tmpname[] = "pageinoutXXXXXX"; unsigned char *vec; int i; - long long j; + unsigned long long j; volatile char *buf; int ret = -1; int rc; @@ -43,10 +43,17 @@ int pageinout_test(int test_runs, unsigned long long file_size) { goto err; } + //madvise and fadvise as random to prevent prefetching + rc = madvise((void *)buf, file_size, MADV_RANDOM) || + posix_fadvise(fd, 0, file_size, POSIX_FADV_RANDOM); + if (rc) { + goto err; + } + for (i = 0; i < test_runs; i++) { gettimeofday(&begin_time, NULL); - //Read backwards to prevent mmap prefetching - for (j = ((file_size - 1) & ~(pagesize - 1)); j >= 0; j -= pagesize) { + //read every page into the page cache + for (j = 0; j < file_size; j += pagesize) { buf[j]; } gettimeofday(&end_time, NULL); diff --git a/tests/pagingtest/thrashing_test.c b/tests/pagingtest/thrashing_test.c index 7ecd3ade..b0193d85 100644 --- a/tests/pagingtest/thrashing_test.c +++ b/tests/pagingtest/thrashing_test.c @@ -14,7 +14,7 @@ int thrashing_test(int test_runs) { int fds[4] = {-1, -1, -1, -1}; char tmpnames[4][17] = { "thrashing1XXXXXX", "thrashing2XXXXXX", "thrashing3XXXXXX", "thrashing4XXXXXX" }; volatile char *bufs[4] = {0}; - long long k; + unsigned long long k; int ret = -1; struct timeval begin_time, end_time, elapsed_time, total_time; unsigned long long filesize; @@ -45,14 +45,18 @@ int thrashing_test(int test_runs) { fprintf(stderr, "Failed to mmap file: %s\n", strerror(errno)); goto err; } + //madvise and fadvise as random to prevent prefetching + ret = madvise((void *)bufs[i], filesize, MADV_RANDOM) || + posix_fadvise(fds[i], 0, filesize, POSIX_FADV_RANDOM); + if (ret) { + goto err; + } } for (int i = 0; i < test_runs; i++) { for (size_t j = 0; j < ARRAY_SIZE(fds); j++) { gettimeofday(&begin_time, NULL); - //Unfortunately when under memory pressure, fadvise and madvise stop working... - //Read backwards to prevent mmap prefetching - for (k = ((filesize - 1) & ~(pagesize - 1)); k >= 0; k -= pagesize) { + for (k = 0; k < filesize; k += pagesize) { bufs[j][k]; } gettimeofday(&end_time, NULL); |