This commit is contained in:
Kent Overstreet 2011-02-13 07:01:10 -08:00
parent 04a54144fd
commit 0b4b6fe2d3
4 changed files with 66 additions and 15 deletions

View File

@ -13,8 +13,8 @@ install: make-bcache probe-bcache
# install -m0755 bcache-test ${PREFIX}/sbin/
clean:
rm -f make-bcache bcache-test *.o
rm -f make-bcache probe-bcache bcache-test *.o
bcache-test: LDFLAGS += -lm -lssl -lcrypto
make-bcache: LDFLAGS += -luuid
probe-bcache: LDFLAGS += -luuid
bcache-test: LDLIBS += -lm -lssl -lcrypto
make-bcache: LDLIBS += -luuid
probe-bcache: LDLIBS += -luuid

24
README Normal file
View File

@ -0,0 +1,24 @@
These are the userspace tools required for bcache.
Bcache is a patch for the Linux kernel to use SSDs to cache other block
devices. For more information, see http://bcache.evilpiepirate.org.
Documentation for the run time interface is included in the kernel tree, in
Documentantion/bcache.txt.
Included tools:
make-bcache
Formats a block device for use with bcache. A device can be formatted for use
as a cache or as a backing device (requires yet to be implemented kernel
support). The most important option is for specifying the bucket size.
Allocation is done in terms of buckets, and cache hits are counted per bucket;
thus a smaller bucket size will give better cache utilization, but poorer write
performance. The bucket size is intended to be equal to the size of your SSD's
erase blocks, which seems to be 128k-512k for most SSDs; feel free to
experiment.
probe-bcache
Only necessary until support for the bcache superblock is included
in blkid; in the meantime, provides just enough functionality for a udev script
to create the /dev/disk/by-uuid symlink. The arguments it does support are the
same as for blkid.

26
make-bcache.8 Normal file
View File

@ -0,0 +1,26 @@
.TH make-bcache 8
.SH NAME
make-bcache \- create a cache device
.SH SYNOPSIS
.B make-bcache
[\fB \-U\ \fIUUID\fR ]
[\fB \-b\ \fIbucket-size\fR ]
.I device
.SH OPTIONS
.TP
.BR \-C
Create a cache
.TP
.BR \-B
Create a backing device (kernel functionality not yet implemented)
.TP
.BR \-U\ \fIUUID
Create a cache device with the specified UUID
.TP
.BR \-b\ \fIbucket-size
Spcifies the bucket size. Allocation is done in terms of buckets, and cache
hits are counted per bucket; thus a smaller bucket size will give better cache
utilization, but poorer write performance. The bucket size is intended to be
equal to the size of your SSD's erase blocks, which seems to be 128k-512k for
most SSDs. Must be a power of two; accepts human readable units. Defaults to
128k.

View File

@ -70,14 +70,14 @@ void usage()
int main(int argc, char **argv)
{
bool cache = false, backingdev = false;
int64_t nblocks, bucketsize = 0, blocksize = 8;
int64_t nblocks;
int fd, i, c;
struct cache_sb sb;
char uuid[40];
struct cache_sb sb = { .block_size = 8, .bucket_size = 0 };
uuid_generate(sb.uuid);
while ((c = getopt(argc, argv, "CBU:b:")) != -1)
while ((c = getopt(argc, argv, "CBU:w:b:")) != -1)
switch (c) {
case 'C':
cache = true;
@ -86,7 +86,10 @@ int main(int argc, char **argv)
backingdev = true;
break;
case 'b':
bucketsize = hatoi(optarg) / 512;
sb.bucket_size = hatoi(optarg) / 512;
break;
case 'w':
sb.block_size = hatoi(optarg) / 512;
break;
case 'U':
if (uuid_parse(optarg, sb.uuid)) {
@ -96,8 +99,8 @@ int main(int argc, char **argv)
break;
}
if (!bucketsize)
bucketsize = cache ? 256 : 8192;
if (!sb.bucket_size)
sb.bucket_size = cache ? 256 : 8192;
if (cache == backingdev) {
printf("Must specify one of -C or -B\n");
@ -117,16 +120,14 @@ int main(int argc, char **argv)
nblocks = getblocks(fd);
printf("device is %li sectors\n", nblocks);
if (bucketsize < blocksize ||
bucketsize > nblocks / 8) {
printf("Bad bucket size %li\n", bucketsize);
if (sb.bucket_size < sb.block_size ||
sb.bucket_size > nblocks / 8) {
printf("Bad bucket size %i\n", sb.bucket_size);
exit(EXIT_FAILURE);
}
memcpy(sb.magic, bcache_magic, 16);
sb.version = backingdev ? CACHE_BACKING_DEVICE : 0;
sb.block_size = blocksize;
sb.bucket_size = bucketsize;
sb.nbuckets = nblocks / sb.bucket_size;
uuid_unparse(sb.uuid, uuid);