Skip to content

Commit

Permalink
jail: Try disabling Transparent Hugepage on Linux
Browse files Browse the repository at this point in the history
Disabling Transparent Hugepage has often been the solution to solve
hard-to-diagnose instability issues and despite improvements in this
area compared to the RHEL6 era, our recommandation is still to avoid
THP to this day.

In addition to refreshing the documentation on this topic, the Linux
jail will tentatively disable THP or warn when it cannot.
  • Loading branch information
cartoush committed Sep 12, 2024
1 parent 0b938f2 commit d4e100b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 17 deletions.
31 changes: 25 additions & 6 deletions bin/varnishd/mgt/mgt_jail_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,38 @@ vjl_make_workdir(const char *dname, const char *what, struct vsb *vsb)

vjl_master(JAIL_MASTER_FILE);
if (statfs(dname, &info) != 0) {
if (vsb)
VSB_printf(vsb, "Could not stat working directory '%s': %s (%d)\n", dname, VAS_errtxt(errno), errno);
else
MGT_Complain(C_ERR, "Could not stat working directory '%s': %s (%d)", dname, VAS_errtxt(errno), errno);
if (vsb) {
VSB_printf(vsb,
"Could not stat working directory '%s': %s (%d)\n",
dname, VAS_errtxt(errno), errno);
} else {
MGT_Complain(C_ERR,
"Could not stat working directory '%s': %s (%d)",
dname, VAS_errtxt(errno), errno);
}
return (1);
}
if (info.f_type != TMPFS_MAGIC) {
if (vsb != NULL)
VSB_printf(vsb, "Working directory not mounted on tmpfs partition\n");
VSB_printf(vsb,
"Working directory not mounted on tmpfs partition\n");
else
MGT_Complain(C_INFO, "Working directory not mounted on tmpfs partition");
MGT_Complain(C_INFO,
"Working directory not mounted on tmpfs partition");
}
vjl_master(JAIL_MASTER_LOW);

if (prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0) != 0) {
if (vsb != NULL) {
VSB_printf(vsb,
"Could not disable Transparent Hugepage: %s (%d)\n",
VAS_errtxt(errno), errno);
} else {
MGT_Complain(C_INFO,
"Could not disable Transparent Hugepage: %s (%d)",
VAS_errtxt(errno), errno);
}
}
return (0);
}

Expand Down
30 changes: 19 additions & 11 deletions doc/sphinx/installation/platformnotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,29 @@ On some platforms it is necessary to adjust the operating system before running
Varnish on it. The systems and steps known to us are described in this section.


Transparent hugepages on Redhat Enterprise Linux 6
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Transparent Hugepage on Linux
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

On RHEL6 Transparent Hugepage kernel support is enabled by default.
This is known to cause sporadic crashes of Varnish.
On certain Linux distributions Transparent Hugepage kernel support is enabled
by default. This is known to cause instability of Varnish.

It is recommended to disable transparent hugepages on affected
systems. This can be done with
``echo never > /sys/kernel/mm/redhat_transparent_hugepage/enabled``
(runtime) or by adding "transparent_hugepage=never" to the kernel boot
line in the "/etc/grub.conf" file (persistent).
It is recommended to disable Transparent Hugepage on affected systems.
If Varnish is the only significant service running on this system, this can be
done during runtime with::

On Debian/Ubuntu systems running 3.2 kernels the default value is "madvise" and
does not need to be changed.
echo never > /sys/kernel/mm/transparent_hugepage/enabled

Alternatively, this can be persisted in your bootloader configuration by adding
``transparent_hugepage=never`` to the kernel command line.

On other systems the default value is ``madvise`` and does not need to be
changed. Either way, the Linux :ref:`ref-varnishd-opt_j` will try to disable
Transparent Hugepage in the ``varnishd`` process.

The general recommendation is to mount the working directory in a ``tmpfs``
partition, usually ``/var/lib/varnish``. By default tmpfs should be mounted with
Transparent Hugepage disabled. Consider mounting the working directory with the
``huge=never`` mount option if that is not the case with your OS vendor.

OpenVZ
~~~~~~
Expand Down
1 change: 1 addition & 0 deletions doc/sphinx/reference/varnishd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ specific options. Available jails are:

- It warns when *workdir* is not on a ``tmpfs``.
- It tries to keep the process dumpable after dropping privileges.
- It tries to disable Transparent Hugepage in ``varnishd``

-j <unix[,user=`user`][,ccgroup=`group`][,workuser=`user`]>

Expand Down

0 comments on commit d4e100b

Please sign in to comment.