linux bcache

本文介绍Linux平台上的Bcache缓存加速技术框架,详细步骤包括安装bcache-tools、设置缓存设备和后端设备、配置缓存模式等。通过这些步骤实现对慢速设备的性能提升。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Bcache是Linux平台上具备缓存加速的技术框架,是一种针对慢速设备的性能提升策略。

1、需要安装bcache-tools 具体可以参照https://bcache.evilpiepirate.org/

2、bcache包含cache device 和 blacking device:blacking device一般是大容量的机械硬盘,统属block device

    make-bcache -B /dev/sdx   将生成/dev/bcache0

3、cache device 一般由ssd构成(随机读写性能高)

    make-bcache -C /dev/sdy  

In this example the default block and bucket sizes of 512B and 128kB are used. The block size should match the backing devices sector size which will usually be either 512 or 4k. The bucket size should match the erase block size of the caching device with the intent of reducing write amplification. For example, using a HDD with 4k sectors and an SSD with an erase block size of 2MB this command would look like

     make-bcache --block 4k --bucket 2m -C /dev/sdy

4. Register the cache device against your backing device. To find its cache set UUID, run # bcache-super-show /dev/sdy2 | grep cset.uuid and then add it to the bcache device initially. Udev rules will take care of this on reboot and will only need to be done once.

    echo cset.uuid > /sys/block/bcache0/bcache/attach

    echo /dev/sdy > /sys/fs/bcache/register

5. Change your cache mode (if you want to cache writes as well as reads):

    echo writeback > /sys/block/bcache0/bcache/cache_mode

6. If you want to have this partition available during the initcpio (i.e. you require it at some point in the boot process) you need to add 'bcache' to your modules array in /etc/mkinitcpio.conf as well as adding the 'bcache' hook in your list between block and filesystems. You must then rebuild the initramfs image. This is typically done with

   mkinitcpio -p linux

7. 启动 

      mkfs.ext4 /dev/bcache0

      mount /dev/bcache0 /mnt

1、查看运行状态:

cat /sys/block/bcache0/bcache/state

The output can be:

  • no cache: this means you have not attached a caching device to your backing bcache device
  • clean: this means everything is ok. The cache is clean.
  • dirty: this means everything is setup fine and that you have enabled writeback and that the cache is dirty.
  • inconsistent: you are in trouble because the backing device is not in sync with the caching device

You can have a /dev/bcache0 device associated with a backing device with no caching device attached. This means that all I/O (read/write) are passed directly to the backing device (pass-through mode)

2. See what caching mode is in use

   cat /sys/block/bcache0/bcache/cache_mode 

[writethrough] writeback writearound none

In the above example, the writethrough mode is enabled.

3. Show info about a bcached device:

   bcache-super-show /dev/sdXY

4. Stop the backing device:

   echo 1 > /sys/block/sdX/sdX[Y]/bcache/stop

5. Detach a caching device:

   echo 1 > /sys/block/sdX/sdX[Y]/bcache/detach

6. Safely remove the cache device

   echo <cache-set-uuid> > /sys/block/bcache0/bcache/detach

7. Release attached devices

   echo 1 > /sys/fs/bcache/<cache-set-uuid>/stop

 

Configuring

There are many options that can be configured (such as cache mode, cache flush interval, sequential write heuristic, etc.) This is currently done by writing to files in /sys. See the bcache user documentation.(http://atlas.evilpiepirate.org/git/linux-bcache.git/tree/Documentation/bcache.txt)

Changing the cache mode is done by echoing one of 'writethrough', 'writeback', 'writearound' or 'none' to /sys/block/bcache[0-9]/bcache/cache_mode.

Note that changes to /sys are temporary, and will revert back after a reboot. To set custom configurations at boot create a .conf file in /etc/tmpfile.d. To set, in a persistent fashion, the sequential cutoff for bcache0 to 1 MB and write back you could create a file /etc/tmpfile.d/my-bcache.conf with the contents

  w /sys/block/bcache0/bcache/sequential_cutoff - - - - 1

  w /sys/block/bcache0/bcache/cache_mode - - - - writeback

 

blacking device 在/sys/block/bache<number>/bcache

cache device 在/sys/fs/bcache/<UUID>/

 



转载于:https://www.cnblogs.com/hike2008/p/5161334.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值