Alibaba Cloud Linux provides two kernel interfaces, force_copy and stats, to optimize JBD2 performance on ext4 file systems. Use force_copy to reduce journaling latency caused by the BH_Shadow state, and stats to diagnose whether JBD2 is the source of file system quality of service (QoS) issues.
How it works
ext4 is a widely used journaling file system. JBD2 is the kernel thread that manages the ext4 journal and serves as a global resource for the file system. When JBD2 accesses a cache page that is in the BH_Shadow state, it must wait for the page to write back to disk, which increases I/O latency and degrades overall performance.
The force_copy interface copies the cache page instead of waiting for the BH_Shadow state to clear, reducing the time JBD2 spends blocked on disk writeback.
Supported versions
|
Distribution |
Minimum kernel version |
|
Alibaba Cloud Linux 2 |
|
|
Alibaba Cloud Linux 3 |
All versions |
Interface reference
force_copy
|
Property |
Value |
|
Path |
/proc/fs/jbd2/<device>-8/force_copy |
|
Default |
Disabled ( |
|
Valid values |
|
|
Function |
Forces a cache page copy to avoid BH_Shadow wait time |
Replace <device> with the block storage device name, such as nvme0n1.
Enabling force_copy increases memory consumption. Check available memory before enabling this on memory-constrained instances.
stats
|
Property |
Value |
|
Path |
/proc/fs/jbd2/<device>-8/stats |
|
Function |
Outputs JBD2 transaction statistics for diagnosing file system QoS issues |
Replace <device> with the block storage device name, such as nvme0n1.
Enable force_copy
Run the following command to enable force_copy. Replace nvme0n1 with your block storage device name.
echo 1 > /proc/fs/jbd2/nvme0n1-8/force_copy
To disable force_copy:
echo 0 > /proc/fs/jbd2/nvme0n1-8/force_copy
Read stats output
Run the following command to query JBD2 transaction statistics:
cat /proc/fs/jbd2/nvme0n1-8/stats
Sample output:
337 336 65536 0 14837 1701504 16 0 20058 5 33082732 605 942 1000 1000
The output contains 15 space-separated fields. The following table describes each field.
|
Field |
Position |
Description |
|
Transaction ID |
1st |
The ID of the current transaction |
|
Transactions requested |
2nd |
The number of transactions requested |
|
Max cached transactions |
3rd |
The maximum number of cached transactions |
|
Wait time |
4th |
The time the transaction spent waiting to be processed |
|
Request latency |
5th |
The latency of the transaction request |
|
Run time |
6th |
The time the transaction ran |
|
Lock time |
7th |
The time the transaction was locked |
|
Flush time |
8th |
The time it took to flush the transaction |
|
Log time |
9th |
The time it took to log the transaction |
|
Average commit time |
10th |
The average time it took to commit the transaction |
|
Handles |
11th |
The number of handles in the transaction |
|
Blocks |
12th |
The number of blocks in the transaction |
|
Logged blocks |
13th |
The number of blocks recorded for the transaction |
|
Time constant (Hz) |
14th |
The kernel time constant ( |
|
Time constant (ms) |
15th |
The kernel time constant. Unit: milliseconds |
Use fields 14 and 15 to convert time-based fields from ticks to the unit of your choice. Compare stats output before and after enabling force_copy to measure the latency improvement on your workload.