[sheepdog] [RFC PATCH 3/3] sheep: introduce journal file to boost IO performance

Liu Yuan namei.unix at gmail.com
Mon Nov 5 09:06:26 CET 2012


On 11/05/2012 03:50 PM, MORITA Kazutaka wrote:
> At Sat,  3 Nov 2012 23:09:47 +0800,
> Liu Yuan wrote:
>> diff --git a/include/util.h b/include/util.h
>> index 5fb19c2..a0d8186 100644
>> --- a/include/util.h
>> +++ b/include/util.h
>> @@ -38,6 +38,7 @@
>>  #endif
>>  
>>  #define notrace __attribute__((no_instrument_function))
>> +#define __packed __attribute((packed))
>>  
>>  #define uninitialized_var(x) (x = x)
>>  
>> @@ -68,6 +69,10 @@ static inline void *zalloc(size_t size)
>>  	return calloc(1, size);
>>  }
>>  
>> +#define __round_mask(x, y) ((__typeof__(x))((y)-1))
>> +#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
> 
> Can I use roundup() which is already defined in util.h?
> 

oops, I didn't see roundup() helper.

> Though we use a packed attribute here, it looks better to align each
> member on an 8-byte boundary so that GCC makes an efficient code.
> 
>   struct journal_descriptor {
>   	uint32_t magic;
>   	uint32_t reserved;
>   	uint64_t oid;
>   	uint64_t offset;
>   	uint64_t size;
>   	uint8_t create;
>   	uint8_t __pad[475];
>   } __packed;
> 

Okay.

>> +
>> +/* JOURNAL_DESC + JOURNAL_MARKER must be 512 algined for DIO */
>> +#define JOURNAL_DESC_MAGIC 0xfee1900d
>> +#define JOURNAL_DESC_SIZE 508
>> +#define JOURNAL_MARKER_SIZE 4 /* Use marker to detect partial write */
>> +#define JOURNAL_META_SIZE SECTOR_SIZE
>> +
>> +#define JOURNAL_FILE_SIZE (1024*1024*256) /* 256M */
>> +#define JOURNAL_END_MARKER 0xdeadbeef
>> +
>> +static const char *jfile_name[2] = { "journal_file0", "journal_file1", };
>> +static int jfile_fds[2];
>> +
>> +static struct journal_file jfile;
>> +static pthread_spinlock_t jfile_lock;
>> +
>> +static int zero_out_jfile(int fd)
>> +{
>> +	char *buf;
>> +	ssize_t wlen;
>> +
>> +	buf = valloc(JOURNAL_FILE_SIZE);
>> +	memset(buf, 0, JOURNAL_FILE_SIZE);
>> +	wlen = xpwrite(fd, buf, JOURNAL_FILE_SIZE, 0);
> 
> Isn't it efficent to use truncate and fallocate like as follows?
> 
>     ftruncate(fd, 0);
>     prealloc(fd, JOURNAL_FILE_SIZE);
> 
> 

fallocate will allocate physical blocks but the extents of those blocks
is marked as 'unwritten'. So the some writes will be delayed slightly to
change those 'unwritten' extents into 'written' ones of meta data.

Thanks,
Yuan



More information about the sheepdog mailing list