From: Eric Wong Date: 2010-11-07T23:22:58+09:00 Subject: [ruby-core:33092] Re: [Ruby 1.9-Feature#4015] File::DIRECT Constant for O_DIRECT Run Paint Run Run wrote: > Last suggestion from me, I promise. ;-) It's a great one and I second it. Promoting fadvise use would help to push kernel hackers to implement/improve support for it. > around posix_fadvise(2). As this advice is never binding, and > #respond_to? returns false for :advise on platforms that don't support > it, it is trivial to write portable code that only invokes #advise > where supported. Granted, this solution still requires defining > constants. However, there is no danger of defining them on all > platforms because platforms that don't support this syscall will raise > a NotImplementedError for #advise. I suggest making #advise just noop on platforms where it's not currently supported to avoid #respond_to? checks. Since "advice" is exactly that, the underlying implementation in the kernel never guarantees any effect (and neither can Ruby). For example, current versions of Linux just ignore POSIX_FADV_NOREUSE, but that doesn't stop me from putting it in my code anyways because it could one day be run on a machine where it is implemented. Since Ruby isn't strictly tied to POSIX, it could eventually take some liberties and affect/influence the userspace buffering behavior, too. > + * _advice_ is one of the following constants: > + * > + * * File::POSIX_FADV_NORMAL - No advice to give; the default assumption for > + * an open file. > + * * File::POSIX_FADV_SEQUENTIAL - The data will be accessed sequentially: > + * with lower offsets read before higher ones. > + * * File::POSIX_FADV_RANDOM - The data will be accessed in random order. > + * * File::POSIX_FADV_WILLNEED - The data will be accessed in the near future. > + * * FILE::POSIX_FADV_DONTNEED - The data will not be accessed in the near > + * future. > + * * File::POSIX_FADV_NOREUSE - The data will only be accessed once. One thing I like about the "fadvise" gem is that it takes symbolic arguments (much like the 1.9.2 socket API extensions) so I can use it like this: io.fadvise(0, io.stat.size, :dont_need) Though I'd probably use ":dontneed" or ":DONTNEED" instead. -- Eric Wong