linux bcache

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>/



时间: 2024-11-10 00:17:55

linux bcache的相关文章

[troubleshoot][archlinux][bcache] 修改linux文件系统 / 分区方案 / 做混合硬盘 / 系统转生大!手!术!(调整底层架构,不!重!装!)

目标: 我要做的事情是:修改文件系统,硬盘分区方案,但是不重装系统,整个操作不被应用层感知. 背景: 我的笔记本 ThinkPad T450.8G内存 + 16GB SSD + 1TB HDD.预装windows7. 在预装系统里16GB的SSD好像是被win7用作睡眠之类的功能.电脑拿到手之后的第一件事我就是想办法把linux装进去.我当初的方案是: 1. 备份win7.比较是预装的,也算是正版.我把1TB硬盘C盘中的文件压缩拷贝出来了.然后又把硬盘开始1GB dd了出来.这样有一点可以装回去

【linux】free命令中cached和buffers的区别

一.命令 [[email protected] ~]# free -m total used free shared buffers cached Mem: 7869 7651 218 1 191 5081 -/+ buffers/cache: 2378 5490 Swap: 478 139 339 二.计算 这里使用1.2 分别代表第一行和第二行的数据 total1:表示物理 内存总量 used1:表示总计分配给缓存(包含buffers 与cache )使用的数量,但其中可能部分缓存并未实际使

Bcache

bcache是按照SSD特性来设计的,只按擦除桶大小进行分配,使用btree和日志混合方法来跟踪缓存数据,缓存数据可以是桶上的任意一个扇区.bcache最大程度上减少了随机写的代价,它按顺序填充一个桶,重新使用时只需将桶设置为无效.bcache支持写直达和回写策略.回写默认情况下是关闭的,可以在运行时改变.bcache还在最大程度上保护你的数据,在系统异常关机时数据仍然是可靠的.因为它被设计为只有在数据完全写回存储设备才确认写成功.回写策略能够缓存绝大多数的写请求,然后再按照索引将脏数据按次序写

[archlinux][hardware] ThankPad T450自带SSD做bcache之后的使用寿命分析

这个分析的起因,是由于我之前干了这两个事: [troubleshoot][archlinux][bcache] 修改linux文件系统 / 分区方案 / 做混合硬盘 / 系统转生大!手!术!(调整底层架构,不!重!装!) [archlinux][hardware] 查看SSD的使用寿命 在12月06日完成了底层硬盘的调整之后,做了如下的硬盘指标统计: /home/tong/Workspace/system/bcache [[email protected]] [17:18] > cat 2016

Linux mem/swap/buffers/cached 区别

Free free 命令相对于top 提供了更简洁的查看系统内存使用情况: $ free total used free shared buffers cached Mem: 255268 238332 16936 0 85540 126384 -/+ buffers/cache: 26408 228860Swap: 265000 0 265000 Mem:表示物理内存统计 -/+ buffers/cached:表示物理内存的缓存统计 Swap:表示硬盘上交换分区的使用情况,这里我们不去关心.

关于bcache的一些事情

最近因为工作的原因接触到bcache缓存技术的一些皮毛,做个笔记备忘. bcache是自3.10开始集成到Linux Kernel中去,后面更新了几个版本增加了一些功能. 另一个备用技术选项为facebook开创的flashcache.但是作者在github表示,基本不敢用. This project is not actively maintained. Proceed at your own risk! 除了在Linux 3.10内核中提供支持以外,还有一个bcache-tools工具,用户

Linux中top和free命令(6/15)

top:命令提供了实时的对系统处理器的状态监视.它将显示系统中CPU最"敏感"的任务列表. 该命令可以按CPU使用.内存使用和执行时间对任务进行排序: 而且该命令的很多特性都可以通过交互式命令或者在个人定制文件中进行设定. top - 01:06:48 up  1:22,  1 user,  load average: 0.06, 0.60,  0.48 Tasks:  29 total,   1 running,  28 sleeping,   0 stopped,   0  zom

自定义配置编译linux内核

1 编译linux内核原因一般情况下,我们是不需要重新去编译linux内核的,但如果你发现你需要修改内核的某个部分或者说你需要的某个模块并没有编译进内核,那里你可以通过重新编译内核来满足你的需求,比如当我们需要用bcache时,但默认bcache是没有编译进内核的,我们可以通过修改编译配置文件,将bcache编译进内核,以下的编译操作均是在Centos7.3平台上进行的演示. 2 编译前准备工作2.1 编译用户身份选择官方是强调编译linux内核是强烈不建议以root身份来进行编译的,因为这样有

linux I/O 栈 预习(上)

二.预习 在我们进去device mapper的dm dedup学习之前,我们先要预习一下,什么是device mapper,和为什么device mapper能够做块重删. 1.device mapper照旧,我们先看一下维基百科对它的介绍.The device mapper is a framework provided by the Linux kernel for mapping physical block devices onto higher-level virtual block