site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=rxe6B24uWxgoF3iHSak2ggxD8Yo+hx/FjuMKMKqCm28v8jrwhMEcbi6a6qjHeKDj5MPofDBb1GuIVQ3K/tPvvhEWrX2q0tpmQubYBk7JxSw9pRcXA/HlBwekwZe0ROBDtftNizX2U0gDvKfAaUfV3Ucm4yzta/VKgBlHtKvnigA= On 12/18/06, Philippe Devallois <phdevallois@intego.com> 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.
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 (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... On 12/18/06, Cédric Luthi <cedric.luthi@gmail.com> wrote: That would be nice if you could tell me a bit more on how to actually use it. This email sent to site_archiver@lists.apple.com