Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable THP permanently (#221) #2419

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,50 @@ You can run `man limits.conf` for more helpful information.

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.

### Transparent huge page
### Transparent Huge Pages

For better delay performance, you must run the following commands to disable the transparent huge pages (THP).
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.

```bash
root# echo never > /sys/kernel/mm/transparent_hugepage/enabled
root# echo never > /sys/kernel/mm/transparent_hugepage/defrag
root# swapoff -a && swapon -a
```
Perform the following steps:

1. Edit the GRUB configuration file `/etc/default/grub`.

```bash
sudo vi /etc/default/grub
```

2. Add `transparent_hugepage=never` to the `GRUB_CMDLINE_LINUX` option, and then save and exit.

```bash
GRUB_CMDLINE_LINUX="... transparent_hugepage=never"
```

3. Update the GRUB configuration.

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.
- For CentOS:

```bash
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
```

- For Ubuntu:

```bash
sudo update-grub
```

5. Reboot the computer.

```bash
sudo reboot
```

If you don't want to reboot, you can run the following commands to temporarily disable THP until the next reboot.

```bash
echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled
echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag
```

## Networking

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,50 @@

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

### Transparent huge page
### 透明大页

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

```bash
root# echo never > /sys/kernel/mm/transparent_hugepage/enabled
root# echo never > /sys/kernel/mm/transparent_hugepage/defrag
root# swapoff -a && swapon -a
```
为了防止系统重启后该配置失效,可以在GRUB配置文件或`/etc/rc.local`中添加相关配置,使系统启动时自动关闭 THP。
操作如下:

1. 编辑 GRUB 配置文件`/etc/default/grub`。

```bash
sudo vi /etc/default/grub
```

2. 在`GRUB_CMDLINE_LINUX`选项中添加`transparent_hugepage=never`,然后保存并退出。

```bash
GRUB_CMDLINE_LINUX="... transparent_hugepage=never"
```

3. 更新 GRUB 配置。

- CentOS

```bash
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
```

- Ubuntu

```bash
sudo update-grub
```

4. 重启操作系统。

```bash
sudo reboot
```

如果不重启可临时关闭透明大页,直到下次重启。

```bash
echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled
echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag
```

## 网络

Expand Down