Skip to content

Commit 5abf195

Browse files
disable THP permanently (#221) (#2419)
commentfix fix Update docs-2.0-en/5.configurations-and-logs/1.configurations/6.kernel-config.md Co-authored-by: Chris Chen <chris.chen@vesoft.com>
1 parent 7f931c4 commit 5abf195

File tree

2 files changed

+83
-16
lines changed

2 files changed

+83
-16
lines changed

docs-2.0-en/5.configurations-and-logs/1.configurations/6.kernel-config.md

+41-8
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,50 @@ You can run `man limits.conf` for more helpful information.
4747

4848
These values control the dirty data cache for the system. For write-intensive scenarios, you can make adjustments based on your needs (throughput priority or delay priority). We recommend that you use the system default value.
4949

50-
### Transparent huge page
50+
### Transparent Huge Pages
5151

52-
For better delay performance, you must run the following commands to disable the transparent huge pages (THP).
52+
Transparent Huge Pages (THP) is a memory management feature of the Linux kernel, which enhances the system's ability to use large pages. In most database systems, Transparent Huge Pages can degrade performance, so it is recommended to disable it.
5353

54-
```bash
55-
root# echo never > /sys/kernel/mm/transparent_hugepage/enabled
56-
root# echo never > /sys/kernel/mm/transparent_hugepage/defrag
57-
root# swapoff -a && swapon -a
58-
```
54+
Perform the following steps:
55+
56+
1. Edit the GRUB configuration file `/etc/default/grub`.
57+
58+
```bash
59+
sudo vi /etc/default/grub
60+
```
61+
62+
2. Add `transparent_hugepage=never` to the `GRUB_CMDLINE_LINUX` option, and then save and exit.
63+
64+
```bash
65+
GRUB_CMDLINE_LINUX="... transparent_hugepage=never"
66+
```
67+
68+
3. Update the GRUB configuration.
5969

60-
To prevent THP from being enabled again after the system restarts, you can modify the GRUB configuration file or `/etc/rc.local` to disable THP automatically upon system startup.
70+
- For CentOS:
71+
72+
```bash
73+
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
74+
```
75+
76+
- For Ubuntu:
77+
78+
```bash
79+
sudo update-grub
80+
```
81+
82+
5. Reboot the computer.
83+
84+
```bash
85+
sudo reboot
86+
```
87+
88+
If you don't want to reboot, you can run the following commands to temporarily disable THP until the next reboot.
89+
90+
```bash
91+
echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled
92+
echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag
93+
```
6194
6295
## Networking
6396

docs-2.0-zh/5.configurations-and-logs/1.configurations/6.kernel-config.md

+42-8
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,50 @@
4747

4848
`vm.dirty_*`是一系列控制系统脏数据缓存的参数。对于写密集型场景,用户可以根据需要进行调整(吞吐量优先或延迟优先),建议使用系统默认值。
4949

50-
### Transparent huge page
50+
### 透明大页
5151

52-
为了降低延迟,用户必须关闭 THP(transparent huge page)。命令如下:
52+
透明大页(Transparent Huge Pages, THP)是一种 Linux 内核的内存管理特性,可以提高系统使用大页的能力。在多数数据库系统中,透明大页会降低性能,建议关闭。
5353

54-
```bash
55-
root# echo never > /sys/kernel/mm/transparent_hugepage/enabled
56-
root# echo never > /sys/kernel/mm/transparent_hugepage/defrag
57-
root# swapoff -a && swapon -a
58-
```
59-
为了防止系统重启后该配置失效,可以在GRUB配置文件或`/etc/rc.local`中添加相关配置,使系统启动时自动关闭 THP。
54+
操作如下:
55+
56+
1. 编辑 GRUB 配置文件`/etc/default/grub`
57+
58+
```bash
59+
sudo vi /etc/default/grub
60+
```
61+
62+
2.`GRUB_CMDLINE_LINUX`选项中添加`transparent_hugepage=never`,然后保存并退出。
63+
64+
```bash
65+
GRUB_CMDLINE_LINUX="... transparent_hugepage=never"
66+
```
67+
68+
3. 更新 GRUB 配置。
69+
70+
- CentOS
71+
72+
```bash
73+
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
74+
```
75+
76+
- Ubuntu
77+
78+
```bash
79+
sudo update-grub
80+
```
81+
82+
4. 重启操作系统。
83+
84+
```bash
85+
sudo reboot
86+
```
87+
88+
如果不重启可临时关闭透明大页,直到下次重启。
89+
90+
```bash
91+
echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled
92+
echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag
93+
```
6094

6195
## 网络
6296

0 commit comments

Comments
 (0)