Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Force Commit file writes

by fluffyvoidwarrior (Monk)
on Jan 31, 2006 at 09:17 UTC ( [id://526688]=perlquestion: print w/replies, xml ) Need Help??

fluffyvoidwarrior has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,
Can anyone tell me how to force a windows system to commit it's write buffers to disk. This doesn't work on windows ...
sysopen(FILE, $filename_path, O_RDWR | O_SYNC );
O_SYNC being undefined on win32. I don't care how the data is written (syswrite, print, write etc) so long as its actually committed to disk immediately by the OS.
Thanks again all ...

Replies are listed 'Best First'.
Re: Force Commit file writes
by tirwhan (Abbot) on Jan 31, 2006 at 11:36 UTC

    I don't know enough about Windows to tell you how to do this, but maybe this will help anyway:

    There are three layers of buffering you need to overcome if you want your data physically written to disk.

    1. The Perl I/O buffer. This can be bypassed by using syswrite or setting $|.
    2. The OS disk cache. This is the one you want to bypass by opening O_SYNC. On *NIX, other ways to get around the disk cache would be to call the sync() or fsync() system calls or mount the filesystem in sync mode.
    3. The on-disk/controller write cache. This is the cache which the disk and/or disk controller use to speed up their operation (note these may actually be two different caches, but from your perspective they act as one). Most disks these days come with write-cache enabled by default and require a FLUSH CACHE(ATA) or SYNCHRONIZE CACHE(SCSI) command from the OS to actually write the data to platter. You'll have to check your OS and device driver to find out whether it does that. Further trouble is that many disks will silently ignore these command in order to speed up benchmarks. You should be able to disable the write cache in your system settings, but that will lead to a disk slowdown as well as a dramatically reduced MTBF.
      This issue becomes even more interesting if you're dealing with battery-backed RAID devices which may completely ignore flush commands and keep data in RAM forever without flushing to disk.

    There are ten types of people: those that understand binary and those that don't.
      Thanks,
      I'll try that but I'm beginning to think its not do-able.
      All I want is to be able cause the OS to write it's buffer. The disk controller hardware and internal disk cache are voodoo beyond my ken and anyway they're too hardware specific to be a viable option.
Re: Force Commit file writes
by jesuashok (Curate) on Jan 31, 2006 at 09:55 UTC
    Hi

    why can't you try $|
    If set to nonzero, forces a flush right away and after every
    write or print on the currently selected output channel.

    "Keep pouring your ideas"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://526688]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-03-19 09:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found