Skip to content

Commit

Permalink
Disable THP in check-before-deployment.md (pingcap#4808)
Browse files Browse the repository at this point in the history
* Update check-before-deployment.md

add Disabling Transparent HugePages section

* Update check-before-deployment.md

fix lint

* Update check-before-deployment.md

fix lint

* Update check-before-deployment.md

Co-authored-by: kissmydb <likun@pingcap.com>

* Update check-before-deployment.md

Co-authored-by: kissmydb <likun@pingcap.com>

* Apply suggestions from code review

* Update check-before-deployment.md

* add step 7

Co-authored-by: pepezzzz <35323945+pepezzzz@users.noreply.github.com>

* Apply suggestions from code review

* refine format

Co-authored-by: kissmydb <likun@pingcap.com>
Co-authored-by: TomShawn <41534398+TomShawn@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 19, 2020
1 parent 37298c4 commit 1c1337a
Showing 1 changed file with 139 additions and 0 deletions.
139 changes: 139 additions & 0 deletions check-before-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,145 @@ sudo systemctl start ntpd.service && \
sudo systemctl enable ntpd.service
```

## 检测和关闭透明大页

对于数据库应用,不推荐使用透明大页(即 Transparent Huge Pages,缩写为 THP),因为数据库的内存访问模式往往是稀疏的而非连续的。而且当高阶内存碎片化比较严重时,分配 THP 页面会出现较大的延迟。若开启针对 THP 的直接内存规整功能,也会出现系统 CPU 使用率激增的现象,因此建议关闭透明大页。

采用如下步骤检查是否已经关闭透明大页,并进行关闭:

1. 执行以下命令查看透明大页的开启状态。如果返回 `[always] madvise never` 则表示处于启用状态:

{{< copyable "shell-regular" >}}

```bash
cat /sys/kernel/mm/transparent_hugepage/enabled
```

```
[always] madvise never
```

2. 执行 `grubby` 命令查看默认内核版本:

> **注意:**
>
> 需安装 `grubby` 软件包。

{{< copyable "shell-regular" >}}

```bash
grubby --default-kernel
```

```bash
/boot/vmlinuz-3.10.0-957.el7.x86_64
```

3. 执行 `grubby --update-kernel` 命令修改内核配置:

{{< copyable "shell-regular" >}}

```bash
grubby --args="transparent_hugepage=never" --update-kernel /boot/vmlinuz-3.10.0-957.el7.x86_64
```

> **注意:**
>
> `--update-kernel` 后需要使用实际的默认内核版本。

4. 执行 `grubby --info` 命令查看修改后的默认内核配置:

{{< copyable "shell-regular" >}}

```bash
grubby --info /boot/vmlinuz-3.10.0-957.el7.x86_64
```

> **注意:**
>
> `--info` 后需要使用实际的默认内核版本。

```bash
index=0
kernel=/boot/vmlinuz-3.10.0-957.el7.x86_64
args="ro crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=en_US.UTF-8 transparent_hugepage=never"
root=/dev/mapper/centos-root
initrd=/boot/initramfs-3.10.0-957.el7.x86_64.img
title=CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)
```

5. 执行 `reboot` 命令进行重启或者修改当前的内核配置:

- 如果需要重启验证,执行 `reboot` 命令:

{{< copyable "shell-regular" >}}

```bash
reboot
```

- 如果不希望重启机器,也可以修改当前的内核配置来立即生效:

{{< copyable "shell-regular" >}}

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

6. 查看重启或者修改后已生效的默认内核配置。如果输出 `always madvise [never]` 表示透明大页处于禁用状态。

{{< copyable "shell-regular" >}}

```bash
cat /sys/kernel/mm/transparent_hugepage/enabled
```

```bash
always madvise [never]
```

7. 如果透明大页禁用未生效,需要使用 tuned 或 ktune 动态内核调试工具修改透明大页的配置。操作步骤如下:

1. 启用 tuned 工具:

{{< copyable "shell-regular" >}}

```bash
tuned-adm active
```

```bash
Current active profile: virtual-guest
```

2. 创建一个新的定制 profile:

{{< copyable "shell-regular" >}}

```bash
mkdir /etc/tuned/virtual-guest-no-thp
vi /etc/tuned/virtual-guest-no-thp/tuned.conf
```

```bash
[main]
include=virtual-guest
[vm]
transparent_hugepages=never
```

3. 应用新的定制 profile:

{{< copyable "shell-regular" >}}

```bash
tuned-adm profile virtual-guest-no-thp
```

应用后再重新检查透明大页的状态。

## 手动配置 SSH 互信及 sudo 免密码

对于有需求,通过手动配置中控机至目标节点互信的场景,可参考本段。通常推荐使用 TiUP 部署工具会自动配置 SSH 互信及免密登陆,可忽略本段内容。
Expand Down

0 comments on commit 1c1337a

Please sign in to comment.