1

I've got this error while running a PHP command-line script on a freshly installed server:

PHP Warning: Zend OPcache huge_code_pages: madvise(HUGEPAGE) failed: Invalid argument

The server is running CentOS 7.3, with PHP 7.1.4 from the remi repository.

According to this thread on remi forum, and this thread on plesk.com, the solution is to disable huge_code_pages in php-opcache.ini:

opcache.huge_code_pages=0

However, Remi said that this problem should only occur on CentOS 6, not CentOS 7.

Before I disable huge_code_pages for good, is there a solution to make it work?

BenMorel
  • 4,447
  • 8
  • 36
  • 46
  • Check if the kernel was compiled with `CONFIG_TRANSPARENT_HUGEPAGE`. The config file should be in `/boot/config-$(uname -r)` (at least according to [folks on Serverfault](https://serverfault.com/questions/429315/centos-kernel-config-file-where-can-i-find-it); I don't have a CentOS 7.3 system to check). – derobert May 05 '17 at 16:06
  • There is no config file matching my exact kernel version, for some reason. However, all config files present (different minor versions) have `CONFIG_TRANSPARENT_HUGEPAGE=y`. – BenMorel May 05 '17 at 18:19
  • Are you sure you kernel came from CentOS 7.3 (and isn't, e.g., something you built yourself)? Odd it doesn't include a config file. – derobert May 05 '17 at 18:31
  • Actually I'm using the [OVH](https://www.ovh.com/fr/) kernel, and it [may be the cause of my issues](https://forum.remirepo.net/viewtopic.php?pid=9491). I've just asked [a question on unix.stackexchange](https://unix.stackexchange.com/questions/363277/what-are-the-pros-and-cons-of-using-the-ovh-linux-kernel) to know what the OVH kernel brings that the default kernel doesn't, to maybe revert back to the default kernel! – BenMorel May 05 '17 at 18:41
  • ftp://ftp.ovh.net/made-in-ovh/bzImage/latest-production/ has config files, and they show (in the few I checked) `# CONFIG_TRANSPARENT_HUGEPAGE is not set` ... so that's definitely your problem. I'll add an answer... – derobert May 05 '17 at 18:45

2 Answers2

2

The kernel from OVH you're using, according to an OVH config file, does not set CONFIG_TRANSPARENT_HUGEPAGE=y. Your kernel thus doesn't support transparent huge pages, and thus madvise(HUGEPAGE) fails with an invalid argument error.

If you want to use transparent huge pages, you'll need to use a kernel which supports them—either by switching to the CentOS 7.3 kernel or by building your own based on the OVH one.

I suggest benchmarking to see if transparent huge pages bring any performance benefit under your workload.

As a side note, you need to make sure your kernels get upgraded—updates often contain important security fixes. Not installing them (and rebooting) will often leave your system subject to local (and sometimes even remote) root exploit.

derobert
  • 107,579
  • 20
  • 231
  • 279
  • Thank you for investigating this. I could very well get away with it by disabling `opcache.huge_code_pages`, as I have yet to see if it makes a relevant difference. However, I'm now more concerned indeed about the auto-update feature missing with the OVH kernel! – BenMorel May 05 '17 at 19:01
0

The accepted answer is incorrect mentioning transparent huge pages and the kernel compile option for the same.

PHP OPcache has nothing to do with Transparent Huge Pages, it's about older, explicit huge pages mechanism.

As such, enabling huge pages in OPCache via opcache.huge_code_pages=1 is not sufficient alone, there must be some changes done in kernel settings, e.g. vm.nr_hugepages = 128 in /etc/sysctl.conf (to allot 256 MB of explicit huge pages, as long as your huge page size is 2MB).

Even this may not be sufficient, depending on OS. In CentOS 7, those pages are mounted like the following:

hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)

And that is enough. In other distros, you might have to mount them manually, see here for details.

More details about transparent vs explicit huge pages in the context of OPCache / web servers can be found here.

It's easy to tell which is what using this logic:

  • Transparent huge pages are really as per naming - transparent. That is, you don't have to do any configuration on the side of the apps to have them enabled. It is seamless to all apps.
  • Explicit huge pages need to be configured/enabled both in and outside of a particular app. Meaning there is extra code/configuration in the app itself to support them, as well as having to ensure that the OS will enable those huge pages. This is the exact case of OPCache, and why OPCache has got a special directive for it.

So this is about other directives potentially missing from OVH kernel. From the kernel docs:

the Linux kernel needs to be built with the CONFIG_HUGETLBFS (present under "File systems") and CONFIG_HUGETLB_PAGE (selected automatically when CONFIG_HUGETLBFS is selected) configuration options.

Danila Vershinin
  • 1,471
  • 9
  • 11