当前位置:网站首页>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 !
边栏推荐
- Canvas draw text and clear draw
- Four rotor aircraft 1 - structure and control principle
- 当代励志“女”录
- R语言使用quantile函数计算向量数据或者dataframe指定数据列的分位数(百分位数)
- (CVPR-2022)BiCnet
- ACM mm 2022 oral | dig: the new framework of self-monitoring character recognition refreshes the recognition performance of 11 public scene character data sets, with an average improvement of 5%
- PowerCLi 将虚拟机从Host01主机移动到Host02主机
- Basic process of process scheduling
- impala的详细写入流程
- 小熊拍学习之LED灯的点亮
猜你喜欢

PC performance monitoring tool is an indispensable helper for software testers

Basic process of process scheduling

3D point cloud course (VI) -- 3D target detection
![[英雄星球七月集训LeetCode解题日报] 第23日 字典树](/img/e3/74cb4ce8aa08e0ea90e26bb2d197c3.png)
[英雄星球七月集训LeetCode解题日报] 第23日 字典树

Type-C Bluetooth speaker single C-Port rechargeable OTG solution

Educational Codeforces Round 132 (Rated for Div. 2)【比赛记录】

Weights & biases (I)

2、 MFC windows and messages

DHCP:在网络中防止 Rogue DHCP Server

H7-TOOL的I2C接口方式脱机烧录操作方法,已经发布(2022-07-16)
随机推荐
看完这篇,彻底搞懂 gRPC!
PowerCLi 管理VMware vCenter 一键批量部署OVA
Canvas draw text and clear draw
Mysql主从复制
Latex(katex)csdn 希腊字母表示,数学符号,集合符号,特殊标记
SecureCRT乱码问题解决方法[通俗易懂]
Atcoder regular contest 144 [VP record]
FormatDateTime的用法
Construction deployment scheme of GPS Beidou clock server (NTP network clock system)
Sui of the public chain (New Public chain project established by former Facebook /meta employees)
什么是弱网测试?为什么要进行弱网测试?怎么进行弱网测试?「建议收藏」
简历上写的电商,那请问Redis 如何实现库存扣减操作和防止被超卖?
Codeforces Round #809 (Div. 2)【VP记录】
【leetcode天梯】链表 · 022 链表中倒数第k个节点
Educational Codeforces Round 132 (Rated for Div. 2)【比赛记录】
Elk notes 25 - experience APM quickly
DHCP:在网络中防止 Rogue DHCP Server
PowerCLi 管理VMware vCenter 一键批量部署OVF
[Luogu p6656] [LOJ 173] [template] runs (string) (Lyndon string)
【pm2】pm2常用命令