From 214fd2f09ede72ce30378a59f62b98c3b4b4319f Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 2 Aug 2018 15:01:42 +1000 Subject: [PATCH] FEATURE: ability to turn off transparent huge pages on arbitrary programs --- image/base/Dockerfile | 6 ++++++ image/base/thpoff.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 image/base/thpoff.c diff --git a/image/base/Dockerfile b/image/base/Dockerfile index 405932e..1a77fab 100644 --- a/image/base/Dockerfile +++ b/image/base/Dockerfile @@ -91,6 +91,12 @@ RUN /tmp/install-gifsicle ADD install-pngquant /tmp/install-pngquant RUN /tmp/install-pngquant +# This tool allows us to disable huge page support for our current process +# since the flag is preserved through forks and execs it can be used on any +# process +ADD thpoff.c /src/thpoff.c +RUN gcc -o /usr/local/sbin/thpoff /src/thpoff.c && rm /src/thpoff.c + # clean up for docker squash RUN rm -fr /usr/share/man &&\ rm -fr /usr/share/doc &&\ diff --git a/image/base/thpoff.c b/image/base/thpoff.c new file mode 100644 index 0000000..3195319 --- /dev/null +++ b/image/base/thpoff.c @@ -0,0 +1,39 @@ +// PUBLIC DOMAIN CODE +// +// A tiny program that disable transparent huge pages on arbitrary processes +// thpoff echo 1 : will run echo 1 with SET_THP_DISABLE true on the process +#include +#include +#include +#include + +int main( int argc, char **argv) { + if (argc < 2) { + fprintf(stderr, "ERROR: expecting at least 1 argument!\n"); + return -1; + } + prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0); + + char* newargv[argc]; + int i; + + newargv[argc-1] = NULL; + for (i=1; i 0) { + fprintf(stderr, "ERROR: %i errno while attempting to run file\n", errno); + return -1; + } + + return 0; +} -- 2.25.1