|
2 | 2 | # This file is part of dracut ensure-hugepages module. |
3 | 3 | # SPDX-License-Identifier: MIT |
4 | 4 |
|
5 | | -hugepages=$(getarg hugepages=) || hugepages=0 |
| 5 | +hugepages=$(getarg hugepages=) || hugepages=-1 # -1 for unset |
6 | 6 |
|
7 | 7 | mem_total_mb=$(($(sed -rn 's/MemTotal:\s+(.*) kB/\1/p' /proc/meminfo) / 1024 )) |
8 | 8 | hugepagesize_mb=$(($(sed -rn 's/Hugepagesize:\s+(.*) kB/\1/p' /proc/meminfo) / 1024 )) |
9 | 9 |
|
10 | | -function adopt_watermark_scale_factor() { |
11 | | - # On a 3TiB host, the default watermark_scale_factor=10 was exactly that |
12 | | - # that the kswapd0 was running permanently. Setting it to 5 was solving the |
13 | | - # issue, but is likely a suboptimal value, but a first start. |
14 | | - # The value 500 reproduces exactly that value for that scale, and hopefully |
15 | | - # also holds for larger hosts. |
16 | | - max_watermark_scale_factor=$(($non_hugepages_mb * 500 / $mem_total_mb)) |
17 | | - watermark_scale_factor=$(</proc/sys/vm/watermark_scale_factor) |
18 | | - if [ $max_watermark_scale_factor -lt $watermark_scale_factor ]; then |
19 | | - echo $max_watermark_scale_factor > /proc/sys/vm/watermark_scale_factor |
20 | | - fi |
21 | | -} |
22 | | - |
23 | | -if [ ${hugepages:-0} -gt 0 ]; then |
24 | | - hugepages_mb=$(($hugepages * $hugepagesize_mb)) |
25 | | - non_hugepages_mb=$(($mem_total_mb - $hugepages_mb)) |
26 | | - adopt_watermark_scale_factor |
27 | | - exit 0 |
| 10 | +if [ $hugepages -lt 0 ]; then # presumably unset, derive it from rdnon_hugepages or from default |
| 11 | + non_hugepages_pm=$(getarg rd.non_hugepages_pm=) || non_hugepages_pm=45 |
| 12 | + non_hugepages_mb=$(( ($mem_total_mb * $non_hugepages_pm) / 1000 )) |
| 13 | + hugepages=$(( ($mem_total_mb - $non_hugepages_mb ) / $hugepagesize_mb )) |
28 | 14 | fi |
29 | 15 |
|
30 | 16 |
|
31 | | -non_hugepages_pm=$(getarg rd.non_hugepages_pm=) || non_hugepages_pm=50 |
32 | | -non_hugepages_mb=$(( ($mem_total_mb * $non_hugepages_pm) / 1000 )) |
33 | | -hugepages=$(( ($mem_total_mb - $non_hugepages_mb ) / $hugepagesize_mb )) |
34 | | - |
35 | | -if [ $hugepages -le 0 ]; then |
| 17 | +if [ ${hugepages:-0} -lt 0 ]; then |
36 | 18 | exit 0 |
37 | 19 | fi |
38 | 20 |
|
39 | | -cmdline="$(</proc/cmdline) hugepages=$hugepages" |
40 | | -release=$(uname -r) |
41 | | - |
42 | | -NEWROOT=${NEWROOT:-/sysroot} |
43 | | - |
44 | | -kexec \ |
45 | | - -l $NEWROOT/boot/vmlinuz-${release} \ |
46 | | - --initrd=$NEWROOT/boot/initrd.img-${release} \ |
47 | | - --command-line="$cmdline" |
| 21 | +# On a 3TiB host, the default watermark_scale_factor=10 was exactly that |
| 22 | +# that the kswapd0 was running permanently. Setting it to 5 was solving the |
| 23 | +# issue, but is likely a suboptimal value, but a first start. |
| 24 | +# The value 500 reproduces exactly that value for that scale, and hopefully |
| 25 | +# also holds for larger hosts. |
| 26 | +max_watermark_scale_factor=$(($non_hugepages_mb * 500 / $mem_total_mb)) |
| 27 | +watermark_scale_factor=$(</proc/sys/vm/watermark_scale_factor) |
| 28 | +if [ $max_watermark_scale_factor -lt $watermark_scale_factor ]; then |
| 29 | + echo $max_watermark_scale_factor > /proc/sys/vm/watermark_scale_factor |
| 30 | +fi |
48 | 31 |
|
49 | | -kexec -e --reset-vga |
| 32 | +# Only after having set the above, we an actually reserve the hugepages |
| 33 | +echo $hugepages > /proc/sys/vm/nr_hugepages |
0 commit comments