1

I was trying out bcache but i don't have an SSD so wanted to use free memory as a substitute. As ramdisk is listed in /proc/devices as block device i assumed this would work OK but with below simple test i can't get it working.

This is on Ubuntu 15.10 with latest 4.5 kernel installed and i'm using the default /dev/ram devices as my SSD substitute.

losetup -f
dd if=/dev/zero of=/tmp/bcache_origin bs=1M count=200
losetup /dev/loop2 /tmp/bcache_origin 

make-bcache -B /dev/loop2 -C /dev/ram9 

No error or output was given from make-bcache. At this point i expect for the new bcache device to be listed in below paths either by UUID or name but there is nothing.

ls -al /sys/fs/bcache/
ls -al /sys/block/bcache*

Here is outputs from cache-super-show

for cache

bcache-super-show /dev/ram9

sb.magic                ok
sb.first_sector         8 [match]
sb.csum                 53EDD9C169F73E1B [match]
sb.version              0 [cache device]

dev.label               (empty)
dev.uuid                2189aa3b-67e7-4296-bb25-6b5ba886befa
dev.sectors_per_block   1
dev.sectors_per_bucket  1024
dev.cache.first_sector  1024
dev.cache.cache_sectors 130048
dev.cache.total_sectors 131072
dev.cache.ordered       no
dev.cache.discard       no
dev.cache.pos           0
dev.cache.replacement   0 [lru]

cset.uuid               0a6b3824-72c1-489e-9d96-d976cb49e8a9

and origin

bcache-super-show /dev/loop2

sb.magic                ok
sb.first_sector         8 [match]
sb.csum                 ECBC84E42E6F52B9 [match]
sb.version              1 [backing device]

dev.label               (empty)
dev.uuid                aff690a4-7ee1-4b62-85cc-ad41c775d7d8
dev.sectors_per_block   1
dev.sectors_per_bucket  1024
dev.data.first_sector   16
dev.data.cache_mode     0 [writethrough]
dev.data.cache_state    0 [detached]

cset.uuid               0a6b3824-72c1-489e-9d96-d976cb49e8a9

I also tried using loop devices for both but that failed even worse. Running below command results in nasty kernel BUG dump in dmesg.

losetup -f
dd if=/dev/zero of=/tmp/bcache_data bs=1M count=200
dd if=/dev/zero of=/tmp/bcache_cache bs=1M count=200

losetup /dev/loop5 /tmp/bcache_data
losetup /dev/loop6 /tmp/bcache_cache
make-bcache -B /dev/loop5 -C /dev/loop6
ll /sys/fs/bcache/

Has anyone successfully got a ramdisk to work as caching device with bcache ? Without any sort of stdout/err to indicate where it's failing i'm not sure if this is my miss-configuration or a bug.

Thanks fLo

0

some devices need to be registered in order to be used

after making the cache devices with

# make-bcache -B /dev/loop2 -C /dev/ram9 

you need to register both (at least the ramdisk though, loop devices and harddisks seem to autoregister most of the time) with

# echo /dev/ram9 >/sys/fs/bcache/register

the uuid enry in /sys/fs/bcache should then show up and the device should be automatically attached as visible in

# cat /sys/block/bcache0/bcache/state 
clean

if you make-bcache the cache and backing device separately with

# make-bcache -B /dev/loop2
# make-bcache -C /dev/ram9

this is not the case and even after you register the ram disk, it will say

# cat /sys/block/bcache0/bcache/state 
no-cache

although the entry in /sys/fs/bcache will show up:

# ls /sys/fs/bcache
f876ea9b-af2c-4b01-84ba-43a87d60501c  register  register_quiet

you then need to attach it with

# echo f876ea9b-af2c-4b01-84ba-43a87d60501c >/sys/block/bcache0/bcache/attach
# cat /sys/block/bcache0/bcache/state 
clean

tricky pitfall: once attached to a bcache, you cannot remove the loop device with

# losetup -d /dev/loop2

this will fail silently, even though the exit code is 0 (success!)

you need to first undo everything with

# echo 1 >/sys/block/bcache0/bcache/stop
# echo 1 >/sys/fs/bcache/f876ea9b-af2c-4b01-84ba-43a87d60501c/unregister

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.