JBD2 is the kernel thread of ext4 file systems. JBD2 often runs into the shadow (BH_Shadow) state when it is being used, which can affect system performance. To solve this problem, an interface is provided to optimize JBD2 in Alibaba Cloud Linux 2 starting from kernel version 4.19.81-17.al7
and Alibaba Cloud Linux 3. This topic describes the interface.
Background information
Ext4 is one of the most common journaling file systems. JBD2 is the kernel thread of ext4 for updating journals and is a global resource for the ext4 file system. When the JBD2 kernel thread attempts to obtain access permissions from the cache, the cache page may be in the BH_Shadow state. In this case, JBD2 waits an extended period of time for the cache page to write back to the disk, which can affect system performance. To solve this problem, Alibaba Cloud Linux provides the force_copy
kernel interface to optimize JBD2. You can enable this interface to forcefully copy the cache page. This way, you can reduce the amount of time that JBD2 waits for the cache page in the BH_Shadow state to write back to the disk. In addition, Alibaba Cloud Linux provides the stats
interface to help analyze quality of service (QoS) issues related to the file system.
Interface description
Interface | Description |
force_copy | The interface file is stored in /proc/fs/jbd2/<device>-8/force_copy, where the Important The interface consumes memory to run. |
stats | The interface file is stored in /proc/fs/jbd2/<device>-8/stats. The interface helps determine whether QoS issues in the file system are caused by JBD2. |
Examples
The following examples demonstrate how to implement the force_copy
and stats
interfaces:
By default, the
force_copy
interface is disabled. You can set the value of the interface to 1 to enable the interface or set the value to 0 to disable the interface.echo 1 > /proc/fs/jbd2/nvme0n1-8/force_copy # Call the interface.
Run the following command to query the
stats
interface:cat /proc/fs/jbd2/nvme0n1-8/stats
A command output similar to the following one is returned:
337 336 65536 0 14837 1701504 16 0 20058 5 33082732 605 942 1000 1000
The following table describes the fields in the preceding sample output.
Field
Description
The first field
The transaction ID.
The second field
The number of transactions requested.
The third field
The maximum number of cached transactions.
The fourth field
The amount of time the translation spent waiting to be processed.
The fifth field
The latency of the transaction request.
The sixth field
The amount of time that the transaction ran.
The seventh field
The amount of time that the transaction was locked.
The eighth field
The amount of time it took to refresh the transaction.
The ninth field
The amount of time it took to log the transaction.
The tenth field
The average amount of time it took to commit the transaction.
The eleventh field
The number of handles contained in the transaction.
The twelfth field
The number of blocks contained in the transaction.
The thirteenth field
The number of blocks recorded for the transaction.
The fourteenth field
The time constant of the kernel configuration. Unit: hertz.
The fifteenth field
The time constant of the kernel configuration. Unit: ms.