当前位置:网站首页>Home NAS server (3) | SSD cache acceleration mechanical hard disk
Home NAS server (3) | SSD cache acceleration mechanical hard disk
2022-07-23 19:48:00 【Woodland ningning】
household NAS The server (3)| SSD Cache acceleration mechanical hard disk
Original address :CSDN post
Summary of the previous article : household NAS The server (2)| HyperV Of Winserver 2022 and Ubuntu 22.04 Dual system
List of articles
1. Preface
Yahoo , Readers, we meet again o( ̄▽ ̄)ブ. Remember that in the last chapter, we have already installed Windows Server, And the Ubuntu Server Success lies in Hyper-V Install in . After successful installation , The author gave the mechanical hard disk directly to Ubuntu virtual machine .
But everybody knows that , The random read and write performance of mechanical hard disk is very low , So in order to improve HDD The ability to read and write at random , In this chapter , I will take you , By setting bcache Tools , Will be with SSD SSD as cache , To improve the random reading and writing ability of mechanical hard disk .
Besides , I will also briefly pass my previous articles , To reduce the power consumption of mechanical hard disk . My blog is here :SeaChest Utilities Tools , Make your hard disk low power consumption and long life .
2. SSD Cache acceleration
SSD Caching can effectively alleviate the problem of low random read and write performance of mechanical hard disk , Therefore, it will be the first thing to set up before the server is put into use .
Before starting the demonstration , The author first explains my Ubuntu Equipment structure . If you find that your equipment structure is different , You need to adjust the order yourself Or in the Hyper-V Modify the device location in . The author's equipment structure is as follows :
| Device name | describe |
|---|---|
/dev/sda | System disk . The entity is external Winserver Of virtual disks . |
/dev/sdb | Solid state disk , Will be used as SSD cache . |
/dev/sdc | first 16T Mechanical drive . |
/dev/sdd | the second 16T Mechanical drive . |
2.1 Hard disk partition
Although the hard disk is not forced to partition , The author still likes to divide each storage device into a zone , Use here fdisk Tool creation GPT Table and partition :
# Enter the mechanical hard disk fdisk Interface
> sudo fdisk /dev/sdc
# establish gpt Partition table
> g
# Create a new partition , All default settings , That is, create only one partition , Occupy all equipment space
> n
If readers have their own zoning needs , You can adjust the partition structure by yourself . here SSD Do not participate in partition .
After partition , The author's current zoning equipment is /dev/sdc1 And /dev/sdd1.
2.2 bcache
2.2.1 bcache install
bcache It's a Linux Tools under , It allows the use of solid state drives as read and write caches (writeback Pattern ) Or read cache (writethrough perhaps writearound Pattern ) Come for another block equipment ( Usually mechanical hard disk or hard disk array ) Speed up .
Besides ,bcache The team also developed a software based on bcache Of bcachefs, This file system is providing SSD Cache acceleration , It also provides COW(Copy On Write Copy while writing )、 Data encryption 、 Data backup, disk array and other functions . But here we have set xfs file system , You don't need to use , The following sections refer to Bcache - ArchWiki.
stay Ubuntu If you want to enable , Need to download first bcache Tools . Fortunately, ,apt The source already contains bcache, Just use the following command to download and install :
sudo apt install bcache-tools
Be careful : hinder bcache Initialization operation , All data on the hard disk will be cleared , therefore bcache It should be the step before file system initialization .
then , Start Initialize solid state disk and mechanical disk :
# Create a back-end device ( Generally speaking, this is your mechanical hard disk ).
# The back-end device can be the whole device 、 A partition or anything else block equipment .
make-bcache -B /dev/sdc1
make-bcache -B /dev/sdd1
# Create a cache device ( This is usually your SSD ).
# The cache device can be an entire device 、 A partition or anything else block equipment
make-bcache -C /dev/sdb
If the above command is successfully executed , So now /dev There will be two more devices in the directory :/dev/bcache0 and /dev/bcache1, Corresponding to /dev/sdc and /dev/sdd. At present, the corresponding relationship between the cache and the back-end device is :
| SSD Cache related devices | The original device ( Partition ) | describe |
|---|---|---|
| nothing | /dev/sdb | SSD Cache disk |
/dev/bcache0 | /dev/sdc1 | Mechanical drive 1 |
/dev/bcache1 | /dev/sdd1 | Mechanical drive 1 |
after , We use solid state drives as cache devices , Add to mechanical hard disk ( Back end devices ) In the cache list of . First View the current SSD cache device UUID:
ls /sys/fs/bcache/
Through this line of command, you can see that there is a UUID, That's the cache device UUID 了 . without , Then use the following command Register caching device :
echo /dev/sdb > /sys/fs/bcache/register
The above two commands can see the cache device UUID, Put this UUID remember , And add it to the cache list of back-end devices , that will do Enable SSD Cache acceleration :
echo UUID__from_previous_command > /sys/block/bcache0/bcache/attach
echo UUID__from_previous_command > /sys/block/bcache1/bcache/attach
2.2.2 bcache operation
Show bcached Device information :
bcache-super-show /dev/sdXY
Stop the backend device :
echo 1 > /sys/block/sdX/sdX[Y]/bcache/stop
Take the cache device offline :
echo 1 > /sys/block/sdX/sdX[Y]/bcache/detach
2.2.3 bcache Pattern
bcache There are altogether 4 Kind of , Namely :
none: No caching at all .writeback: The best cache mode , All read and write requests are in SSD When the request is completed, it is regarded as the request is completed . Be careful , Although this mode can greatly improve the performance , But because of SSD The data on the will be synchronized asynchronously with the back-end device , Therefore, if power failure occurs during synchronization , May lead to SSD Data loss on . For all that ,bcache After the next restart , The asynchronous synchronization process that was not completed last time will continue to complete , Minimize the risk of data loss .writethrough: Default cache mode , The performance is lower than the above one . In this mode , All read operations will pass through the cache layer . The difference is , All write requests will be made to SSD And back-end devices , And only after the backend device writes , Consider the request completed . The advantage of this is , The performance of the cache is improved for read operations in a period of time after writing .writearound: Low performance mode , But it can prolong SSD Life span of . In this mode , Only cache read operations .
Back end device runtime , You can view the caching mode adopted by the backend device :
cat /sys/block/bcache0/bcache/cache_mode
cat /sys/block/bcache1/bcache/cache_mode
The author considers SSD The problem of the life span of , And I'm not very interested in the cache of write operations , Therefore, choose to modify the cache mode to writearound Pattern :
echo writearound > /sys/block/bcache0/bcache/cache_mode
echo writearound > /sys/block/bcache1/bcache/cache_mode
Of course , If readers have their own needs , You can choose your own cache mode .
2.3 xfs file system
The author chose xfs file system , Mainly valued its actions RHEL The stability of the default file system of the distribution , At the same time, the performance is not backward ext4 How many? . Then there's a chance , The author will issue a separate issue on Linux Under the comparison of major file systems , We will discuss it in detail at that time .
On the back-end device with a good cache mechanism , We will start to format the file system . This file system is optional , It doesn't have to be xfs file system , Only the author chose xfs.
First , install xfs Related tools of :
sudo apt install xfsprogs
after , Set up a file system for our backend device partition , Pay attention to... Directly after that bcache* To operate the equipment :
sudo mkfs.xfs /dev/bcache0
sudo mkfs.xfs /dev/bcache1
thus ,xfs The file system already contains SSD Successfully created on the cached hard disk , You can mount .
2.4 fstab Power on auto mount
After the file system is established , It's best to set it to mount automatically .
here , I plan to mount the two disks on /mnt/sdc and /mnt/snapraid_backup. First, create a mount point :
sudo mkdir -p /mnt/sdc /mnt/snapraid_backup
And then by looking at bcache* The equipment UUID And write it down :
sudo lsblk -f
Use the editor to open /etc/fstab, Add the following code :
UUID=<bcache0 Of UUID> /mnt/sdc xfs defaults 0 0
UUID=<bcache1 Of UUID> /mnt/snapraid_backup xfs defaults 0 0
Save and restart the system , If it works , With SSD The cached mechanical hard disk is established .
3. summary
This issue , The author finally put SSD The cache acceleration mechanism is set up , It's also a good adjustment bcache The function of . stay bcache blessings , Random access speed over a period of time From the original 2MB/s To the present 30Mb/s, Compared with the original mechanical hard disk , Already there. A huge improvement .
Besides , In this issue, the file system will also be created , For the next issue mergerfs and snapraid The appearance of . Only when mergerfs + snapraid Set up , It is really a safe harbor for data .
Comrades, if you think my content is useful , Please leave me a compliment and comment , It's best to pay attention , I will be very happy !
Recently, I saw many blog posts with great moisture , The content is plain and homogeneous , I still don't want to become such a marketing number after all , May the spirit of open source survive !
边栏推荐
- Type-C Bluetooth speaker single C-Port rechargeable OTG solution
- 进程调度的基本过程
- How can mysqldump export content without comments?
- Why are there Chinese materials and web pages for foreign chips?
- (干货)结合Scikit-learn介绍几种常用的特征选择方法
- 【leetcode天梯】链表 · 206 反转链表
- 三维点云课程(六)——三维目标检测
- 在Hyper-V中手动将.avhd合并到.vhd
- 行业分析| 物流对讲
- 测试如何应对新的开发模式?
猜你喜欢

Understand chisel language. 21. Chisel sequential circuit (I) -- detailed explanation of chisel register

Analyse de l'industrie | interphone logistique

Hongke dry goods | teaches you how to parse floating-point data in MODBUS

将本地镜像发布到阿里云仓库

3D point cloud course (VII) -- feature point description

基于自学习的机器人决策系统(达闼科技赵开勇)

Codeforces Round #805-#808【部分题解】

Codeforces Round #809 (Div. 2)【VP记录】

H7-TOOL串口脱机烧录操作说明,支持TTL串口,RS232和RS485(2022-06-30)

PowerCLi 管理VMware vCenter 一键批量部署OVA
随机推荐
Talk about the parental delegation mechanism in detail (often asked in interviews) [easy to understand]
当代励志“女”录
Solutions to SecureCRT garbled code problem [easy to understand]
Still using xshell? You are out. I recommend a more modern terminal connection tool
(CVPR-2022)BiCnet
H7-TOOL的I2C接口方式脱机烧录操作方法,已经发布(2022-07-16)
公链之Sui(前脸书/Meta员工成立的新公链项目)
【开发经验】开发项目踩坑集合【持续更新】
离线数据、实时数据是什么
Idea select code generation method
R language uses dwilcox function to generate Wilcoxon rank sum statistical distribution density function data, and uses plot function to visualize Wilcoxon rank sum statistical distribution density fu
SecureCRT乱码问题解决方法[通俗易懂]
Basic process of process scheduling
攻防世界web题-fakebook
PC performance monitoring tool is an indispensable helper for software testers
R语言data.table包进行数据分组聚合统计变换(Aggregating transforms)、计算dataframe数据的分组最小值(min)
Why do you get confused when you ask JVM?
Mysql主从复制
Weights & biases (I)
R语言使用tidyr包的gather函数将从宽表转化为长表(宽表转化为长表)、第一个参数指定原多个数据列名称生成的新数据列名称、第二个参数指定原表内容值、第三个和第四个参数指定不变的列名称列表