[Sheepdog] [PATCH 3/3] store: use fallocate when allocating new objects
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Fri Nov 11 10:06:16 CET 2011
At Thu, 10 Nov 2011 14:22:30 -0500,
Christoph Hellwig wrote:
>
> Writing zeroes into the last sector of an object is not going to
> preallocate it, but just allocates the last sector. This leads
> to fairly nasty fragmentation. Use fallocate on the whole object
> instead. On my test setup with XFS this speeds up writes to an
> unallocate volume from ~73MB/s to ~80MB/s.
>
> This was benchmarked using an O_DIRECT dd call of 1GB size.
>
> Signed-off-by: Christoph Hellwig <hch at lst.de>
>
> Index: sheepdog/sheep/store.c
> ===================================================================
> --- sheepdog.orig/sheep/store.c 2011-11-10 19:15:46.796295077 +0100
> +++ sheepdog/sheep/store.c 2011-11-10 19:25:14.603795482 +0100
> @@ -639,19 +640,8 @@ static int store_queue_request_local(str
> free(buf);
> buf = NULL;
> } else {
> - int size = SECTOR_SIZE;
> - buf = valloc(size);
> - if (!buf) {
> - eprintf("failed to allocate memory\n");
> - ret = SD_RES_NO_MEM;
> - goto out;
> - }
> - memset(buf, 0, size);
> - ret = pwrite64(fd, buf, size, SD_DATA_OBJ_SIZE - size);
> - free(buf);
> - buf = NULL;
> -
> - if (ret != size) {
> + ret = posix_fallocate(fd, 0, SD_DATA_OBJ_SIZE);
> + if (ret == -1) {
posix_fallocate() shows very poor performance if the underlying
filesystem doesn't support fallocate() (e.g. ext3). How about using
fallocate() instead of posix_fallocate(), and if it returns
EOPNOTSUPP, writing SD_DATA_OBJ_SIZE bytes with one pwrite() call?
The other four patches you sent are okay to me. I've applied them,
thanks a lot!
Kazutaka
> if (errno == ENOSPC)
> ret = SD_RES_NO_SPACE;
> else {
>
> --
> sheepdog mailing list
> sheepdog at lists.wpkg.org
> http://lists.wpkg.org/mailman/listinfo/sheepdog
More information about the sheepdog
mailing list