Question about AnonHugePages

Hello to All.

Currently, I have a server with incus containers running a PostgreSQL database for metrics. I enabled the huge pages into the host, and the change was reflected on database container. But when I proceeded to disable the THP on the host, the values of AnonHugePages are different with the container:

On host:

AnonHugePages: 3336192 kB
ShmemHugePages: 0 kB
FileHugePages: 0 kB
HugePages_Total: 8419
HugePages_Free: 8325
HugePages_Rsvd: 2661
HugePages_Surp: 0
Hugepagesize: 2048 kB

On container:

grep -i hugepage /proc/meminfo
AnonHugePages: 0 kB
ShmemHugePages: 0 kB
FileHugePages: 0 kB
HugePages_Total: 8419
HugePages_Free: 8325
HugePages_Rsvd: 2661
HugePages_Surp: 0
Hugepagesize: 2048 kB

The Host server is:

Distributor ID: Debian
Description: Debian GNU/Linux 12 (bookworm)
Release: 12
Codename: bookworm

Is this the expected behavior?

Cheers,

Nicolas

It can be one of two things:

  • This is something that’s correctly tied to cgroups and you’ll need to configure the hugetlb cgroup controller to allow access to those pages (We have some stuff under limits.hugepages)
  • This isn’t tied to the cgroup and it’s just LXCFS not knowing what to do about reporting those fields when it generates the per-container /proc/meminfo

In general, the content of /proc/meminfo is basically best effort as not all keys can be perfectly computed by LXCFS based on cgroup data, so the first step is usually to confirm that something is actually broken at run time to differentiate an issue in reporting from an actual configuration/kernel issue.

Hello, thanks for the quick response!

And, I have the follow problem; if enable the huge pages in container with postgresql (in postgres.conf, huge_pages = on) and enable it in host, according of recommended pages for shared_buffers, the databases cannot start.

For example, shared_buffer in postgresql equal to 16GB, then recommended huge pages~8419 (using formula hp = ((shm_size + (BLKSZ - (shm_size % BLKSZ))) / (huge page size * 1024)) + 1). The value was set vm.nr_hugepages=8419 in sysctl.conf. But when DB was restarted, It show the following error:
”Cannot allocate memory
This error usually means that PostgreSQL’s request for a shared memory segment exceeded available memory, swap space, or huge pages. To reduce the request size (currently 17653825536 bytes), reduce PostgreSQL’s shared memory usage, perhaps by reducing shared_buffers or max_connections.”

But, I think the reserved HP are enough according of DB requirement. As I said, postgresql is running inside a incus container instance, and I don’t have any limit to huge pages. Any Idea? Is there other setting that I messing? Are huge pages transparent from host to containers?
Nicolas Gonzalez