On Tue, 2013-05-28 at 22:10 -0400, Greg Smith wrote:
> I was just thinking of something to run in your test program, not 
> another build time check.  Just run the new allocation sequence, and 
> then check the resulting WAL file for a) correct length, and b) 16K of 
> zero bytes.  I would like to build some confidence that posix_fallocate 
> is operating correctly in this context on at least one platform.  My 
> experience with Linux handling this class of functions correctly has 
> left me skeptical of them working until that's proven to be the case.

As I understand it, you are basically asking if posix_fallocate() works
at all anywhere.

Simple test program attached, which creates two files and fills them:
one by 2048 8KB writes; and another by 1 posix_fallocate of 16MB. Then,
I just cmp the resulting files (and also "ls" them, to make sure they
are 16MB).

Passes on my workstation:
$ uname -a
Linux jdavis 3.5.0-34-generic #55-Ubuntu SMP Thu Jun 6 20:18:19 UTC 2013
x86_64 x86_64 x86_64 GNU/Linux

Regards,
        Jeff Davis

#include <fcntl.h>

char buf[8192] = {0};

int main()
{
	int i;
	int fda = open("/tmp/afile", O_CREAT | O_EXCL | O_WRONLY, 0600);
	int fdb = open("/tmp/bfile", O_CREAT | O_EXCL | O_WRONLY, 0600);

	for(i = 0; i < 2048; i++)
		{
			write(fda, buf, 8192);
		}

	posix_fallocate(fdb, 0, 16*1024*1024);

	close(fda);
	close(fdb);

	return 0;
}
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to