in reply to Re: flock and read-ahead buffering on input
in thread flock and read-ahead buffering on input

I am worried about perl or the OS performing read-ahead buffering as a result of the sysopen call. I am aware that flock is advisory locking, not mandatory. And I am assuming a local file system.

Clearly read-ahead buffering is normally done (at least on linux), since this post, for example, discusses controlling linux's read-ahead buffer size, and this post discusses controlling the read-ahead buffer size from perl. Therefore, given that read-ahead buffering is normally done, how can the above code possibly be safe? I am fully prepared to believe that it is, but I have not been able to find any authoritative evidence to support that belief, and I want my code to be safe.

For example, if flock was guaranteed to invalidate the read-ahead buffer, or if the act of another process writing to the file was guaranteed to immediately invalidate the read-ahead buffer, or if the read-ahead buffer was guaranteed to not be filled until this process did a read on the file handle, then the above code would indeed be safe. Can anyone point me to any evidence that that any of these is true, or any other evidence that indicates why the above code is safe, given the fact that read-ahead buffering normally occurs when reading a file?

  • Comment on Re^2: flock and read-ahead buffering on input

Replies are listed 'Best First'.
Re^3: flock and read-ahead buffering on input
by dave_the_m (Monsignor) on Apr 18, 2014 at 07:55 UTC
    Perl won't do any read-ahead buffering of the file until you perform the first read action. If the kernel performs read-ahead, it has a global picture of the file and and all processes, and will be capable of invalidating any buffered data if necessary.

    So that code is perfectly safe for your needs.

    Dave.

      Thanks, that's the key piece of information that I needed. Unfortunately it is not documented in the sysopen, flock or read documentation. Can you point me to where that is documented?
        Thanks, that's the key piece of information that I needed. Unfortunately it is not documented in the sysopen, flock or read documentation. Can you point me to where that is documented?
        Which are you referring to? That perl won't read-ahead, or that the kernel knows what it's doing? For the former, the whole purpose of sysopen/sysread etc is to avoid buffer layers; the man page for sysread specifically states this.

        As for the kernel, this is basic; if the kernel didn't do that it would be broken beyond belief.

        Dave.