* [BUG] fadvise POSIX_FADV_NOREUSE does nothing
@ 2007-07-29 7:57 Eric St-Laurent
0 siblings, 0 replies; only message in thread
From: Eric St-Laurent @ 2007-07-29 7:57 UTC (permalink / raw)
To: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 742 bytes --]
Related to my other bug report today, calling posix_fadvise (which uses
fadvise64) with the POSIX_FADV_NOREUSE flag does nothing. The pages are
not dropped behind.
I also tried call fadvise with POSIX_FADV_SEQUENTIAL first.
This is expected as the POSIX_FADV_NOREUSE is a no-op in the recent
kernels.
Also, POSIX_FADV_SEQUENTIAL only does the readahead window. It doesn't
hint the VM in any way to possibly drop-behind the pages.
(See the previous bug report for more details of the test case)
Relevant numbers:
Copying (using fadvise_cp) a large file test:
1st run: 0m9.018s
2nd run: 0m3.444s
Copying large file...
3rd run: 0m14.024s <<< page cache trashed
4th run: 0m3.449s
Test programs and batch files are attached.
- Eric
[-- Attachment #2: fadvise_cp.c --]
[-- Type: text/x-csrc, Size: 875 bytes --]
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int in;
int out;
int pagesize;
void *buf;
off_t pos;
if (argc != 3) {
printf("Usage: %s <src> <dest>\n", argv[0]);
return EXIT_FAILURE;
}
in = open(argv[1], O_RDONLY, 0);
out = open(argv[2], O_CREAT | O_WRONLY | O_TRUNC, 0666);
posix_fadvise(in, 0, 0, POSIX_FADV_SEQUENTIAL);
posix_fadvise(out, 0, 0, POSIX_FADV_SEQUENTIAL);
pagesize = getpagesize();
buf = malloc(pagesize);
pos = 0;
for (;;) {
ssize_t count;
count = read(in, buf, pagesize);
if (!count || count == -1)
break;
write(out, buf, count);
/* right usage pattern? */
posix_fadvise(in, pos, count, POSIX_FADV_NOREUSE);
posix_fadvise(out, pos, count, POSIX_FADV_NOREUSE);
pos += count;
}
free(buf);
close(in);
close(out);
return EXIT_SUCCESS;
}
[-- Attachment #3: Makefile --]
[-- Type: text/x-makefile, Size: 84 bytes --]
all:
gcc fadvise_cp.c -o fadvise_cp
gcc working_set_simul.c -o working_set_simul
[-- Attachment #4: use-once-test.sh --]
[-- Type: application/x-shellscript, Size: 2864 bytes --]
[-- Attachment #5: working_set_simul.c --]
[-- Type: text/x-csrc, Size: 636 bytes --]
#include <fcntl.h>
#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int fd;
off_t size;
char *mapping;
unsigned r;
unsigned i;
if (argc != 2) {
printf("Usage: %s <file>\n", argv[0]);
return EXIT_FAILURE;
}
fd = open(argv[1], O_RDONLY, 0);
size = lseek(fd, 0, SEEK_END);
mapping = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
/* access (read) the file a couple of times*/
for (r = 0; r < 4; r++) {
for (i = 0; i < size; i++) {
char t = mapping[i];
}
}
munmap(mapping, size);
close(fd);
return EXIT_SUCCESS;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2007-07-29 7:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-29 7:57 [BUG] fadvise POSIX_FADV_NOREUSE does nothing Eric St-Laurent
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox