Installing nr_hugepages error via SYSFS

I have 8G physical memory, Fedora20, and configured kernel parameters to allocate two huge 1G pages at boot time by passing the following parameters to the kernel:

default_hugepagesz=1G hugepagesz=1G hugepages=2

      

HugeTLBFS is automatically mounted:

% mount | grep ^huge
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
%

      

On reboot everything looks good and I can see that the kernel has allocated the required pages:

% dmesg | grep HugeTLB
HugeTLB registered 1 GB page size, pre-allocated 2 pages
% grep -E ^"(Mem|Huge)" /proc/meminfo
MemTotal:        8137732 kB
MemFree:         5359672 kB
MemAvailable:    5707656 kB
HugePages_Total:       2
HugePages_Free:        2
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:    1048576 kB
%

      

As you can see, the amount of free memory should allow me to increase the number of huge pages, however I cannot do this:

% echo 3 > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages
-bash: echo: write error: Invalid argument

      

or

% echo 3 > /proc/sys/vm/nr_hugepages
-bash: echo: write error: Invalid argument
%

      

The number of pages is also reduced. What am I doing wrong?

+3


source to share


2 answers


I think I have found the reason for this behavior. The kernel documentation for the "largepagesz =" parameter at https://www.kernel.org/doc/Documentation/kernel-parameters.txt says that "1 GB of a page can only be allocated at load time using huge = pages and not subsequently released " I think so I can not reduce the number of pages.

Also, the code in mm / hugetlb.c does not allow this operation:



#if defined(CONFIG_CMA) && defined(CONFIG_X86_64)
...
static inline bool gigantic_page_supported(void) { return true; }
#else
static inline bool gigantic_page_supported(void) { return false; }
...
#endif
...
static int hugetlb_sysctl_handler_common(...)
{
  ...
  if (write && hstate_is_gigantic(h) && !gigantic_page_supported())
          return -EINVAL;
  ...
}

      

So, unless CONFIG_CMA is defined (and the kernel config shipped with Fedora 20 has this option disabled), the kernel will always return EINVAL.

+3


source


It looks like you might need superuser rights for the command. Alternatively, you can try the next step if you want to make changes to your system.

First you need to install hugetlbfs to use traditional huge pages.

mkdir /hugetlbfs
mount -t hugetlbfs none /hugetlbfs

      

Note. IA-64 support - 4KiB, 2MiB and 4MiB pages Note: x86_64 support - 4KiB, 2MiB, 4MiB or 1GiB pages

Next, depending on your requirement, edit the file /etc/sysctl.conf

and specify the number of huge pages in the nr_hugepages files:



vm.nr_hughpages=2

      

Now run the command sysctl -p

for the configuration changes to take effect. Note. If your requirement for the number of huge pages is large and has no contiguous free blocks available, then it is recommended that you restart your system after this has changed.

To check if the number of huge pages has been allocated use cat /proc/meminfo | grep Huge

HugePages_Total:    2
HugePages_Free:     2
HugePages_Rsvd:     0
Hugepagesize:       2048 kB

      

0


source







All Articles