How to sync a file on FreeBSD?
Hi all How to sync a file on FreeBSD (esp. on 8.1) to disk? I used fsync(2), but does not immediately flush to disk. I want my writing to a file (a log file) immediately available to other users to read. Best regards Unga ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: How to sync a file on FreeBSD?
On Thu, 21 Jul 2011 23:44:00 -0700 (PDT), Unga wrote: How to sync a file on FreeBSD (esp. on 8.1) to disk? I used fsync(2), but does not immediately flush to disk. I want my writing to a file (a log file) immediately available to other users to read. Maybe you can use system(/bin/sync); or sync(); in your program? Check man 8 sync: force completion of pending disk writes (flush cache) as well as man 2 sync: The sync() system call forces a write of dirty (modified) buffers in the block buffer cache out to disk. Is this immediately enough for your needs? -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: How to sync a file on FreeBSD?
If you used fsync it should write to permanent storage immediately, and it's no longer the OS' problem. If it's not flushing immediately, maybe the mystery is at the filesystem level or even hardware, both of which you didn't provide. When you say 'users' are they looking at the file via NFS or HTTP? if the latter they could be seeing a cached copy (proxy, browser, etc.). On Fri, Jul 22, 2011 at 2:44 AM, Unga unga...@yahoo.com wrote: Hi all How to sync a file on FreeBSD (esp. on 8.1) to disk? I used fsync(2), but does not immediately flush to disk. I want my writing to a file (a log file) immediately available to other users to read. Best regards Unga ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: How to sync a file on FreeBSD?
On Fri, Jul 22, 2011 at 8:44 AM, Unga unga...@yahoo.com wrote: Hi all How to sync a file on FreeBSD (esp. on 8.1) to disk? I used fsync(2), but does not immediately flush to disk. I want my writing to a file (a log file) immediately available to other users to read. It shouldn't matter: as soon as write(2) completes, the system-wide file cache -- not the disk -- is updated, and other users will transparently read(2) from that cache, not from the disk. What you probably want is to flush the userspace buffers of your I/O library as soon as you write a line of output: See fflush(3), set[v]buf(3)... You may also use a non-buffered stream for writing logs. fsync(2) has other uses. In particular, it is of NO use as long as the logging application doesn't flush its I/O caches itself. Best regards Unga -cpghost. -- Cordula's Web. http://www.cordula.ws/ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: How to sync a file on FreeBSD?
On Fri Jul 22 11, C. P. Ghost wrote: On Fri, Jul 22, 2011 at 8:44 AM, Unga unga...@yahoo.com wrote: Hi all How to sync a file on FreeBSD (esp. on 8.1) to disk? I used fsync(2), but does not immediately flush to disk. I want my writing to a file (a log file) immediately available to other users to read. if you *really* want to see data being written to disk immediately and don't care about performance, do the following: 1) disable the write cache of your hdd (see ada(4) and ata(4) man pages) 2) mount your partition(s) with '-o sync' cheers. alex It shouldn't matter: as soon as write(2) completes, the system-wide file cache -- not the disk -- is updated, and other users will transparently read(2) from that cache, not from the disk. What you probably want is to flush the userspace buffers of your I/O library as soon as you write a line of output: See fflush(3), set[v]buf(3)... You may also use a non-buffered stream for writing logs. fsync(2) has other uses. In particular, it is of NO use as long as the logging application doesn't flush its I/O caches itself. Best regards Unga -cpghost. -- Cordula's Web. http://www.cordula.ws/ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: How to sync a file on FreeBSD?
On Friday, July 22, 2011 08:44:00 AM Unga wrote: How to sync a file on FreeBSD (esp. on 8.1) to disk? I used fsync(2), but does not immediately flush to disk. I want my writing to a file (a log file) immediately available to other users to read. A file doesn't need to be synced to disk for other users to read the latest data. The application just needs to call write(2) and the data is available. It will be written to and read from the operating system's file cache. If you're using stdio you can force a write(2) by calling fflush(3). - Pieter ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: How to sync a file on FreeBSD? [SOLVED]
--- On Fri, 7/22/11, Pieter de Goeje pie...@degoeje.nl wrote: From: Pieter de Goeje pie...@degoeje.nl Subject: Re: How to sync a file on FreeBSD? To: freebsd-questions@freebsd.org Cc: Unga unga...@yahoo.com Date: Friday, July 22, 2011, 7:37 PM On Friday, July 22, 2011 08:44:00 AM Unga wrote: How to sync a file on FreeBSD (esp. on 8.1) to disk? I used fsync(2), but does not immediately flush to disk. I want my writing to a file (a log file) immediately available to other users to read. A file doesn't need to be synced to disk for other users to read the latest data. The application just needs to call write(2) and the data is available. It will be written to and read from the operating system's file cache. If you're using stdio you can force a write(2) by calling fflush(3). - Pieter Hi all Thanks for the replies. fflush(3) after fputs seems to work. Best regards Unga ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: How to sync a file on FreeBSD? [SOLVED]
This is extremely important, esp. with Softupdates, since fsync() does not guarantee a flush of all buffers to the medium. In order to implement a stable queue, it would be best to use a different filesystem. On Fri, Jul 22, 2011 at 6:16 AM, Unga unga...@yahoo.com wrote: --- On Fri, 7/22/11, Pieter de Goeje pie...@degoeje.nl wrote: From: Pieter de Goeje pie...@degoeje.nl Subject: Re: How to sync a file on FreeBSD? To: freebsd-questions@freebsd.org Cc: Unga unga...@yahoo.com Date: Friday, July 22, 2011, 7:37 PM On Friday, July 22, 2011 08:44:00 AM Unga wrote: How to sync a file on FreeBSD (esp. on 8.1) to disk? I used fsync(2), but does not immediately flush to disk. I want my writing to a file (a log file) immediately available to other users to read. A file doesn't need to be synced to disk for other users to read the latest data. The application just needs to call write(2) and the data is available. It will be written to and read from the operating system's file cache. If you're using stdio you can force a write(2) by calling fflush(3). - Pieter Hi all Thanks for the replies. fflush(3) after fputs seems to work. Best regards Unga ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: How to sync a file on FreeBSD? [SOLVED]
On Fri, 22 Jul 2011 07:37:48 -0700, Michael Sierchio wrote: This is extremely important, esp. with Softupdates, since fsync() does not guarantee a flush of all buffers to the medium. But wouldn't sync() (see man 2 sync) make sure that all buffers, even in regards to soft updates, get immediately flushed / written? In order to implement a stable queue, it would be best to use a different filesystem. What type of filesystem would match those requirements? -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: How to sync a file on FreeBSD? [SOLVED]
On Fri, Jul 22, 2011 at 7:42 AM, Polytropon free...@edvax.de wrote: But wouldn't sync() (see man 2 sync) make sure that all buffers, even in regards to soft updates, get immediately flushed / written? Apparently not. I think most of Matt Dillon's notes are still relevant. http://leaf.dragonflybsd.org/mailarchive/kernel/2010-01/msg5.html In order to implement a stable queue, it would be best to use a different filesystem. What type of filesystem would match those requirements? I would make a UFS filesystem without Softupdates enabled, use fflush() and wait for a proper ack before promising to the caller that the bits will survive something like pulling the plug. Softupdates guarantees metadata consistency. I would probably make decisions about block and fragment sizes based on knowledge of the physical device's buffer mechanism, sector sizes, etc. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org