Re: Re: Re: darwin equivalent to linux readahead(2) function ?
Re: Re: Re: darwin equivalent to linux readahead(2) function ?
- Subject: Re: Re: Re: darwin equivalent to linux readahead(2) function ?
- From: "Shawn Erickson" <email@hidden>
- Date: Mon, 18 Dec 2006 11:41:40 -0800
On 12/18/06, Cédric Luthi <email@hidden> wrote:
On 12/18/06, Philippe Devallois <email@hidden> wrote:
> fcntl(inFD,F_RDAHEAD,1);
>
> man fcntl
>
> Not so complicated ;)
>
> Hope this helps,
Actually, I'm not sure how to use it :-(
I tried like that:
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, const char* argv[])
{
FILE* bigfile;
int fd;
struct stat sb;
char buf[4];
bigfile = fopen("bigfile", "r");
if (!bigfile)
return 1;
fd = fileno(bigfile);
if (fstat(fd, &sb)) {
fclose(bigfile);
return 1;
}
fcntl(fd, F_RDAHEAD, 1);
read(fd, buf, 4);
printf("bigfile size is %lld bytes\n", sb.st_size);
fclose(bigfile);
return 0;
}
But it seems it's not the way I want it to behave.
Here is the (timed) result of the execution:
$ time ./rdaheadtest
bigfile size is 118053508 bytes
real 0m0.055s
user 0m0.002s
sys 0m0.015s
It obviously has NOT loaded the whole 113 MB file into memory because
(1) I haven't heard my hard disk at all and (2) my PowerBook G4 is
probably not able to load 113 MB in less than 0.055 s.
I must be doing something wrong but the fcntl man is not really
verbose about F_RDAHEAD and it's usage.
That would be nice if you could tell me a bit more on how to actually use it.
Note that Mac OS X will use any available physical RAM pages to cache
file data (unified buffer cache). It is possible that prior tests you
ran resulted in the test file getting fully loading into pages sitting
in the file cache. Any access to those pages would happen at RAM
access speeds and wouldn't involve disk access.
For example picking a file I know I haven't touched since last reboot...
[serickson@serickson-pmg5:~/Documents/Downloads]
[0:506] > dd if=xnu-792.13.8.tar of=/dev/null bs=1m
31+1 records in
31+1 records out
33351680 bytes transferred in 0.651121 secs (51221928 bytes/sec)
[serickson@serickson-pmg5:~/Documents/Downloads]
[0:507] > dd if=xnu-792.13.8.tar of=/dev/null bs=1m
31+1 records in
31+1 records out
33351680 bytes transferred in 0.056653 secs (588700803 bytes/sec)
-Shawn
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden