Rate This Document
Findability
Accuracy
Completeness
Readability

How to Change the Memory Page Size from 64 KB to 4 KB on CentOS

This section describes how to change the memory page size on CentOS.

  1. Check the current memory page size.
    getconf PAGESIZE

    If 65536 is displayed in the command output, the page size is 64 KB.

  2. Download the kernel source code.
    wget https://git.centos.org/sources/kernel/c8/a857effa0971fa1b6790bf8df25f69dda20acdd3

    If the kernel source code already exists in the environment, skip this step and 3. If the message "ERROR: cannot verify git.centos.org's certificate" is displayed during the download, add the --no-check-certificate option to the end of the command.

  3. Decompress the package to obtain the kernel source code directory linux-4.18.0-193.28.1.el8_2, and move the directory to the /usr/src directory.
    tar -xf a857effa0971fa1b6790bf8df25f69dda20acdd3
    ll
    mv linux-4.18.0-193.28.1.el8_2 /usr/src

  4. Install the kernel compilation dependencies.
    yum install -y vim rpm-build net-tools bc xmlto asciidoc openssl-devel hmaccalc python-devel newt-devel perl elfutils-devel zlib-devel binutils-devel audit-libs-devel java-devel numactl-devel pciutils-devel ncurses-devel perl-ExtUtils-Embed git
  5. Go to the kernel source code directory and copy the kernel compilation file of the current system to ensure that other kernel configuration items are the same as those of the current system.
    cd /usr/src/linux-4.18.0-193.28.1.el8_2
    cp /boot/config-`uname -r` ./.config
  6. Change the kernel page size to 4 KB.
    1. Open menuconfig.
      make menuconfig
    2. Choose Kernel Features.

    3. Press Enter to access the next-level menu, and choose Page size (64KB).

    4. Press Enter to access the next-level menu, and press the space button to choose 4KB.

    5. Choose Exit twice to save and exit.

  7. Check the memory page configuration in the .config file to verify that the modification takes effect.
    grep -i pages .config

    As shown in the following command output, the 4K configuration item is enabled, and the 64K configuration item is commented out.

  8. Modify the kernel version.

    Ensure that the new kernel version is later than the current system kernel version. You can run the uname -a command to check the kernel version.

    1. Open the Makefile file.
      vim Makefile
    2. Modify the EXTRAVERSION parameter.

    3. Press Esc, type :wq!, and press Enter to save the setting and exit.
  9. Compile the kernel binary package. During the compilation, the system loads the modified .config file and prompts you to confirm some configuration items. Set the page size to 4 KB and adjust the subsequent options based on service requirements.
    1. Run the following command to compile the kernel. Choose 1 as prompted to set the page size to 4 KB.
      make binrpm-pkg -j`nproc`

    2. Set the virtual address space size as required. For example, choose 1 to set the virtual address space size to 39-bit.

    3. Set the ELF file configuration information as required.

    4. Set the network driver information as required.

      After the command is executed, you can view the path to the generated RPM package in the command output.

    5. View the generated kernel RPM package in the /root/rpmbuild/RPMS/aarch64/ directory.
      ll /root/rpmbuild/RPMS/aarch64/

  10. Install the kernel RPM package.
    rpm -ivh /root/rpmbuild/RPMS/aarch64/kernel-4.18.0_3-7.aarch64.rpm

  11. Check whether the kernel is successfully installed.
    rpm -qa | grep kernel

    If the installed kernel version is displayed in the command output, the kernel is successfully installed.

  12. Reboot the system and access the newly compiled and installed kernel.
    reboot

    Select the installed kernel when the following information is displayed:

    If you cannot access the remote console through the BMC, run the following commands to select the kernel:

    1. View all kernels in the current system.
      awk -F\' '$1=="menuentry " {print i++ " : "$2}' /boot/efi/EFI/*/grub.cfg
    2. Run the grub2-set-default command to select the newly installed kernel as the default kernel.
      grub2-set-default 0
    3. Reboot the server.
      reboot
  13. Check the kernel version.
    uname -a

    If the kernel version in the command output is the same as the installed version, the kernel version is correct.

  14. Check the current memory page size.
    getconf PAGESIZE

    If 4096 is displayed in the command output, the memory page size has been changed to 4 KB.