What does sync() _really_ do?

Piercarlo Grandi pcg at cs.aber.ac.uk
Sun Dec 23 04:15:27 AEST 1990


On 17 Dec 90 12:15:50 GMT, mpledger at cti1.UUCP (Mark Pledger) said:

mpledger> steinar at ifi.uio.no (Steinar Kj{rnsr|d) writes:

	[ ... whether sync guarantees freeing of buffers from the
	cache, or not like he thinks ... ]

mpledger> If memory serves me right, sync() does not CLEAR the file
mpledger> buffers, but only writes all dirty buffers to disk and clears
mpledger> the dirty bit flag in the file buffer header structure.  Your
mpledger> right that there is no guarantee the dirty buffers will be
mpledger> wiped out.

Yep. The *only* portable way to make sure that the buffers associated to
a file's block are freed is to unmount the filesystem on which the file
resides.

Here is the simple minded but effective technology I use to measure peak
read/write rates thru the filesystem, e.g. for the purpose of
determining the optimal logical interleave.

First a simple program:

	main()
	{
		int i; char b[32*1024];
		for (i = 0; i < 64; i++)
			read(0,b, sizeof b); /* or write(1,b,sizeof b); */
	}


compiled as ./write and ./read, then I choose a spare partition, and I
do

	mkfs /dev/rdsk/0s2 4836:1216 6 156 # or any other parameters

	mount /dev/dsk/0s2 /mnt

	time ./write >/mnt/x
	umount /dev/dsk/0s2	# To flush the ...
	mount /dev/dsk/0s2 /mnt # ... buffer cache
	time ./read </mnt/x

	umount /dev/dsk/0s2
--
Piercarlo Grandi                   | ARPA: pcg%uk.ac.aber.cs at nsfnet-relay.ac.uk
Dept of CS, UCW Aberystwyth        | UUCP: ...!mcsun!ukc!aber-cs!pcg
Penglais, Aberystwyth SY23 3BZ, UK | INET: pcg at cs.aber.ac.uk



More information about the Comp.unix.internals mailing list