[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-optimize
Subject: Re: Using madvise for ld.so
From: Andrew Morton <akpm () osdl ! org>
Date: 2004-03-16 20:21:28
Message-ID: 20040316122128.1cda0589.akpm () osdl ! org
[Download RAW message or body]
Alexander Kellett <lypanov@kde.org> wrote:
>
> On Tue, 16 Mar 2004 21:00:26 +0100, Dirk Mueller <mueller@kde.org> wrote:
> > might be a stupid question, but how did you "clear the cache" ?
>
> the usual "use memory till oom" thing (included in an earlier email iirc)
> i wish the kernel guys would sort this out which a proper solution.
In 2.6 you can run posix_fadvise(fd, start, length, POSIX_FADV_DONTNEED).
I've attached a little proggy which uses fadvise to shoot down some or all
of a file's pagecache.
This tool is maintained in ext3 CVS. See
http://www.zip.com.au/~akpm/linux/ext3/
["fadvise.c" (application/octet-stream)]
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include "fadvise.h"
char *progname;
static void usage(void)
{
fprintf(stderr, "Usage: %s filename offset length advice\n", progname);
fprintf(stderr, " advice: normal sequential willneed noreuse "
"dontneed\n");
exit(1);
}
int
main(int argc, char *argv[])
{
int c;
int fd;
char *sadvice;
char *filename;
loff_t offset;
unsigned long length;
int advice = 0;
int ret;
progname = argv[0];
while ((c = getopt(argc, argv, "")) != -1) {
switch (c) {
}
}
if (optind == argc)
usage();
filename = argv[optind++];
if (optind == argc)
usage();
offset = strtoull(argv[optind++], NULL, 0);
if (optind == argc)
usage();
length = strtol(argv[optind++], NULL, 0);
if (optind == argc)
usage();
sadvice = argv[optind++];
if (optind != argc)
usage();
if (!strcmp(sadvice, "normal"))
advice = POSIX_FADV_NORMAL;
else if (!strcmp(sadvice, "sequential"))
advice = POSIX_FADV_SEQUENTIAL;
else if (!strcmp(sadvice, "willneed"))
advice = POSIX_FADV_WILLNEED;
else if (!strcmp(sadvice, "noreuse"))
advice = POSIX_FADV_NOREUSE;
else if (!strcmp(sadvice, "dontneed"))
advice = POSIX_FADV_DONTNEED;
else
usage();
fd = open(filename, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "%s: cannot open `%s': %s\n",
progname, filename, strerror(errno));
exit(1);
}
ret = __posix_fadvise64(fd, offset, length, advice);
if (ret) {
fprintf(stderr, "%s: fadvise() failed: %s\n",
progname, strerror(errno));
exit(1);
}
close(fd);
exit(0);
}
["fadvise.h" (application/octet-stream)]
_______________________________________________
Kde-optimize mailing list
Kde-optimize@kde.org
https://mail.kde.org/mailman/listinfo/kde-optimize
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic