[ACT][PATCH 1/3] UBUNTU: SAUCE: ubuntu_ltp: import pending LTP patches for several failures
Krzysztof Kozlowski
krzysztof.kozlowski at canonical.com
Mon Jun 28 07:52:15 UTC 2021
Few patches to upstream LTP project are pending for longer time (2-3
weeks). Either the discussion is on-going (and not necessarily going
anywhere like in case of controllers/memcg patches) or they are ignored.
These patches fix real test issues, so apply them here. The patchset
contains fixes for ubuntu_ltp and ubuntu_ltp_syscalls, because it is
easier to keep one set.
This imports Krzysztof Kozlowski's work in LTP:
- tpci: accept ENOMEM resource failure with virtio-pci
- controllers/memcg: increase memory limit in subgroup charge
- controllers/memcg: accept non-zero max_usage_in_bytes after reset
- controllers/memcg: accept range of usage_in_bytes
- controllers/memcg: accept range of max_usage_in_bytes
- lib: memutils: don't pollute entire system memory to avoid OoM
- device-drivers/cpufreq_boost: skip test on virtual machines
- syscalls/msgstress: tune limit of processes for small machines
- syscalls/msgstress03: fix fork failure on small memory systems
- syscalls/msgstress04: fix fork failure on small memory systems
- include/tst_pid.h: fix language typo (subtraction)
- controllers/cpuacct: skip cpuacct_100_100 on small memory systems
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
---
...cct-skip-cpuacct_100_100-on-small-me.patch | 112 ++++++++++
..._pid.h-fix-language-typo-subtraction.patch | 26 +++
...ss04-fix-fork-failure-on-small-memor.patch | 158 ++++++++++++++
...ss03-fix-fork-failure-on-small-memor.patch | 67 ++++++
...ss-tune-limit-of-processes-for-small.patch | 41 ++++
...pufreq_boost-skip-test-on-virtual-ma.patch | 43 ++++
...-t-pollute-entire-system-memory-to-a.patch | 59 ++++++
...g-accept-range-of-max_usage_in_bytes.patch | 80 +++++++
...memcg-accept-range-of-usage_in_bytes.patch | 198 ++++++++++++++++++
...g-accept-non-zero-max_usage_in_bytes.patch | 45 ++++
...g-increase-memory-limit-in-subgroup-.patch | 72 +++++++
...MEM-resource-failure-with-virtio-pci.patch | 81 +++++++
ubuntu_ltp/ubuntu_ltp.py | 32 +++
13 files changed, 1014 insertions(+)
create mode 100644 ubuntu_ltp/patches/0001-controllers-cpuacct-skip-cpuacct_100_100-on-small-me.patch
create mode 100644 ubuntu_ltp/patches/0002-include-tst_pid.h-fix-language-typo-subtraction.patch
create mode 100644 ubuntu_ltp/patches/0003-syscalls-msgstress04-fix-fork-failure-on-small-memor.patch
create mode 100644 ubuntu_ltp/patches/0004-syscalls-msgstress03-fix-fork-failure-on-small-memor.patch
create mode 100644 ubuntu_ltp/patches/0005-syscalls-msgstress-tune-limit-of-processes-for-small.patch
create mode 100644 ubuntu_ltp/patches/0006-device-drivers-cpufreq_boost-skip-test-on-virtual-ma.patch
create mode 100644 ubuntu_ltp/patches/0007-lib-memutils-don-t-pollute-entire-system-memory-to-a.patch
create mode 100644 ubuntu_ltp/patches/0008-controllers-memcg-accept-range-of-max_usage_in_bytes.patch
create mode 100644 ubuntu_ltp/patches/0009-controllers-memcg-accept-range-of-usage_in_bytes.patch
create mode 100644 ubuntu_ltp/patches/0010-controllers-memcg-accept-non-zero-max_usage_in_bytes.patch
create mode 100644 ubuntu_ltp/patches/0011-controllers-memcg-increase-memory-limit-in-subgroup-.patch
create mode 100644 ubuntu_ltp/patches/0012-tpci-accept-ENOMEM-resource-failure-with-virtio-pci.patch
diff --git a/ubuntu_ltp/patches/0001-controllers-cpuacct-skip-cpuacct_100_100-on-small-me.patch b/ubuntu_ltp/patches/0001-controllers-cpuacct-skip-cpuacct_100_100-on-small-me.patch
new file mode 100644
index 000000000000..d40a56068fb4
--- /dev/null
+++ b/ubuntu_ltp/patches/0001-controllers-cpuacct-skip-cpuacct_100_100-on-small-me.patch
@@ -0,0 +1,112 @@
+From b8c70988a96cf508afdd0a9d0f623fc8d24c6020 Mon Sep 17 00:00:00 2001
+From: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+Date: Thu, 10 Jun 2021 11:57:06 +0200
+Subject: [PATCH 01/12] controllers/cpuacct: skip cpuacct_100_100 on small
+ memory systems
+
+Running cpuacct_100_100 on a system with less than ~4 GB of RAM fails:
+
+ cpuacct 1 TINFO: timeout per run is 0h 5m 0s
+ cpuacct 1 TINFO: cpuacct: /sys/fs/cgroup/cpu,cpuacct
+ cpuacct 1 TINFO: Creating 100 subgroups each with 100 processes
+ testcases/bin/cpuacct.sh: 0: Cannot fork
+
+In dmesg:
+
+ LTP: starting cpuacct_100_100 (cpuacct.sh 100 100)
+ cgroup: fork rejected by pids controller in /user.slice/user-1000.slice/session-1.scope
+
+The reason is cgroups pid limit set by systemd user.slice. For example
+on 2 GB RAM machine it is set as:
+ /sys/fs/cgroup/pids/user.slice/user-0.slice/pids.max:5207
+
+Add a check for both free memory and maximum number of pids (when using
+systemd) to skip the test. Systems not using systemd might still fail.
+
+Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+
+---
+
+Changes since v1:
+1. Add checking for pids.
+2. Accurately check the memory constraints.
+---
+ .../kernel/controllers/cpuacct/cpuacct.sh | 56 +++++++++++++++++++
+ 1 file changed, 56 insertions(+)
+
+diff --git a/testcases/kernel/controllers/cpuacct/cpuacct.sh b/testcases/kernel/controllers/cpuacct/cpuacct.sh
+index 323aa7513bf4..66a48dde679b 100755
+--- a/testcases/kernel/controllers/cpuacct/cpuacct.sh
++++ b/testcases/kernel/controllers/cpuacct/cpuacct.sh
+@@ -38,12 +38,68 @@ OPTIONS
+ EOF
+ }
+
++check_free_memory()
++{
++ local memneeded
++ local memfree=`awk '/MemAvailable/ {print $2}' /proc/meminfo`
++
++ if [ $? -ne 0 ]; then
++ local memcached
++
++ memfree=`awk '/MemFree/ {print $2}' /proc/meminfo`
++ test $? || return 0
++
++ memcached=`awk '/MemCached/ {print $2}' /proc/meminfo`
++ test $? || return 0
++
++ memfree=$((memfree + memcached))
++ fi
++
++ # On x86_64, each 100 of processes were using ~16 MB of memory,
++ # so try to estimate the needed free memory based on this.
++ memneeded=$((max * nbprocess * 16384 / 100))
++
++ if [ $memfree -lt $memneeded ]; then
++ tst_brk TCONF "not enough of free memory on this system (approximate need $memneeded kB, free $memfree kB)"
++ fi
++ tst_res TINFO "memory requirements fulfilled (approximate need $memneeded kB, free $memfree kB)"
++
++ return 0
++}
++
++check_limits()
++{
++ local realuid="$SUDO_UID"
++ local tasksneeded=$((max * nbprocess + 100))
++
++ if [ "$realuid" = "" ]; then
++ realuid=`id -u`
++ test $? || return 0
++ fi
++
++ local tasksmax=`systemctl show user-${real_uid}.slice | awk -F '=' '/TasksMax/ {print $2}'`
++ test $? || return 0
++
++ if [ $tasksmax -le $tasksneeded ]; then
++ tst_brk TCONF "limit of tasks is too low (approximate need $tasksneeded, limit $tasksmax)"
++ fi
++ tst_res TINFO "task limit fulfilled (approximate need $tasksneeded, limit $tasksmax)"
++
++ return 0
++}
++
+ setup()
+ {
+ if ! grep -q -w cpuacct /proc/cgroups; then
+ tst_brk TCONF "cpuacct not supported on this system"
+ fi
+
++ check_limits
++ # Don't bother with memory limit checks on smaller tests
++ if [ $max -ge 100 ] && [ $nbprocess -ge 100 ]; then
++ check_free_memory
++ fi
++
+ mount_point=`grep -w cpuacct /proc/mounts | cut -f 2 | cut -d " " -f2`
+ tst_res TINFO "cpuacct: $mount_point"
+ if [ "$mount_point" = "" ]; then
+--
+2.27.0
+
diff --git a/ubuntu_ltp/patches/0002-include-tst_pid.h-fix-language-typo-subtraction.patch b/ubuntu_ltp/patches/0002-include-tst_pid.h-fix-language-typo-subtraction.patch
new file mode 100644
index 000000000000..5a86bd4c8552
--- /dev/null
+++ b/ubuntu_ltp/patches/0002-include-tst_pid.h-fix-language-typo-subtraction.patch
@@ -0,0 +1,26 @@
+From 90f38de47e949fe9380281b4caae7b4391aa7ab9 Mon Sep 17 00:00:00 2001
+From: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+Date: Wed, 23 Jun 2021 13:23:15 +0200
+Subject: [PATCH 02/12] include/tst_pid.h: fix language typo (subtraction)
+
+Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+---
+ include/tst_pid.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/include/tst_pid.h b/include/tst_pid.h
+index 9ba1abb27b7c..6c42f73a57e7 100644
+--- a/include/tst_pid.h
++++ b/include/tst_pid.h
+@@ -13,7 +13,7 @@
+ pid_t tst_get_unused_pid_(void (*cleanup_fn)(void));
+
+ /*
+- * Returns number of free pids by substarction of the number of pids
++ * Returns number of free pids by subtraction of the number of pids
+ * currently used ('ps -eT') from max_pids
+ */
+ int tst_get_free_pids_(void (*cleanup_fn)(void));
+--
+2.27.0
+
diff --git a/ubuntu_ltp/patches/0003-syscalls-msgstress04-fix-fork-failure-on-small-memor.patch b/ubuntu_ltp/patches/0003-syscalls-msgstress04-fix-fork-failure-on-small-memor.patch
new file mode 100644
index 000000000000..2b5a1d130cc8
--- /dev/null
+++ b/ubuntu_ltp/patches/0003-syscalls-msgstress04-fix-fork-failure-on-small-memor.patch
@@ -0,0 +1,158 @@
+From 1c73eb35d3ee91403441a4c296c0d15c0e064355 Mon Sep 17 00:00:00 2001
+From: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+Date: Tue, 22 Jun 2021 12:44:42 +0200
+Subject: [PATCH 03/12] syscalls/msgstress04: fix fork failure on small memory
+ systems
+
+Running syscalls/msgstress04 on a system with less than ~4 GB of RAM fails:
+
+ Fork failure in the first child of child group 4396
+ Fork failure in the second child of child group 4413
+ msgstress04 1 TFAIL : msgstress04.c:222: Child exit status = 1
+
+The reason is cgroups pid limit set by systemd user.slice. The limit is
+set for login session, also for root user. For example on 2 GB RAM
+machine it is set as:
+ /sys/fs/cgroup/pids/user.slice/user-0.slice/pids.max:5207
+
+Read the maximum number of pids and adjust the test limit.
+
+Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+---
+ include/tst_pid.h | 4 ++-
+ lib/tst_pid.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++-
+ 2 files changed, 81 insertions(+), 2 deletions(-)
+
+diff --git a/include/tst_pid.h b/include/tst_pid.h
+index 6c42f73a57e7..8d999a655f1a 100644
+--- a/include/tst_pid.h
++++ b/include/tst_pid.h
+@@ -14,7 +14,9 @@ pid_t tst_get_unused_pid_(void (*cleanup_fn)(void));
+
+ /*
+ * Returns number of free pids by subtraction of the number of pids
+- * currently used ('ps -eT') from max_pids
++ * currently used ('ps -eT') from maximum number of processes.
++ * The limit of processes come from kernel pid_max and cgroup session limits
++ * (e.g. configured by systemd user.slice).
+ */
+ int tst_get_free_pids_(void (*cleanup_fn)(void));
+
+diff --git a/lib/tst_pid.c b/lib/tst_pid.c
+index 9568cc9e91d2..c1ea3fe90e83 100644
+--- a/lib/tst_pid.c
++++ b/lib/tst_pid.c
+@@ -18,14 +18,20 @@
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
++#include <errno.h>
+ #include <fcntl.h>
+ #include <limits.h>
++#include <stdio.h>
++#include <stdlib.h>
+ #include <sys/types.h>
++#include <unistd.h>
+ #include "test.h"
+ #include "tst_pid.h"
+ #include "old_safe_file_ops.h"
+
+ #define PID_MAX_PATH "/proc/sys/kernel/pid_max"
++#define CGROUPS_V1_SLICE_FMT "/sys/fs/cgroup/pids/user.slice/user-%d.slice/pids.max"
++#define CGROUPS_V2_SLICE_FMT "/sys/fs/cgroup/user.slice/user-%d.slice/pids.max"
+
+ pid_t tst_get_unused_pid_(void (*cleanup_fn) (void))
+ {
+@@ -36,10 +42,77 @@ pid_t tst_get_unused_pid_(void (*cleanup_fn) (void))
+ return pid;
+ }
+
++/*
++ * Get the effective session UID - either one invoking current test via sudo
++ * or the real UID.
++ */
++static int get_session_uid(void)
++{
++ const char *sudo_uid;
++
++ sudo_uid = getenv("SUDO_UID");
++ if (sudo_uid) {
++ int real_uid;
++
++ TEST(sscanf(sudo_uid, "%u", &real_uid));
++ if (TEST_RETURN != 1) {
++#ifdef DEBUG
++ tst_resm(TINFO, "No SUDO_UID from env");
++#endif
++ } else {
++ return real_uid;
++ }
++ }
++
++ return getuid();
++}
++
++static int read_session_pids_limit(const char *path_fmt, int uid,
++ void (*cleanup_fn) (void))
++{
++ int max_pids, ret;
++ char path[PATH_MAX];
++
++ ret = snprintf(path, sizeof(path), path_fmt, uid);
++ if (ret < 0 || (size_t)ret >= sizeof(path))
++ return -1;
++
++ if (access(path, R_OK) != 0) {
++ tst_resm(TINFO, "Cannot read session user limits from '%s'", path);
++ return -1;
++ }
++
++ SAFE_FILE_SCANF(cleanup_fn, path, "%d", &max_pids);
++ tst_resm(TINFO, "Found limit of processes %d (from %s)", max_pids, path);
++
++ return max_pids;
++}
++
++static int get_session_pids_limit(void (*cleanup_fn) (void))
++{
++ int max_pids, uid;
++
++ uid = get_session_uid();
++ if (TEST_RETURN != 1) {
++ tst_resm(TINFO, "Cannot get UID");
++ return -1;
++ }
++
++ max_pids = read_session_pids_limit(CGROUPS_V2_SLICE_FMT, uid, cleanup_fn);
++ if (max_pids < 0)
++ max_pids = read_session_pids_limit(CGROUPS_V1_SLICE_FMT, uid,
++ cleanup_fn);
++
++ if (max_pids < 0)
++ return -1;
++
++ return max_pids;
++}
++
+ int tst_get_free_pids_(void (*cleanup_fn) (void))
+ {
+ FILE *f;
+- int rc, used_pids, max_pids;
++ int rc, used_pids, max_pids, max_session_pids;
+
+ f = popen("ps -eT | wc -l", "r");
+ if (!f) {
+@@ -57,6 +130,10 @@ int tst_get_free_pids_(void (*cleanup_fn) (void))
+
+ SAFE_FILE_SCANF(cleanup_fn, PID_MAX_PATH, "%d", &max_pids);
+
++ max_session_pids = get_session_pids_limit(cleanup_fn);
++ if ((max_session_pids > 0) && (max_session_pids < max_pids))
++ max_pids = max_session_pids;
++
+ /* max_pids contains the maximum PID + 1,
+ * used_pids contains used PIDs + 1,
+ * so this additional '1' is eliminated by the substraction */
+--
+2.27.0
+
diff --git a/ubuntu_ltp/patches/0004-syscalls-msgstress03-fix-fork-failure-on-small-memor.patch b/ubuntu_ltp/patches/0004-syscalls-msgstress03-fix-fork-failure-on-small-memor.patch
new file mode 100644
index 000000000000..ae9002a8e024
--- /dev/null
+++ b/ubuntu_ltp/patches/0004-syscalls-msgstress03-fix-fork-failure-on-small-memor.patch
@@ -0,0 +1,67 @@
+From 98315709311c8a88e363492c3be61c6e8861321b Mon Sep 17 00:00:00 2001
+From: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+Date: Tue, 22 Jun 2021 12:15:00 +0200
+Subject: [PATCH 04/12] syscalls/msgstress03: fix fork failure on small memory
+ systems
+
+Running syscalls/msgstress03 on a system with less than ~4 GB of RAM fails:
+
+ msgstress03 1 TFAIL : msgstress03.c:155: Fork failed (may be OK if under stress)
+
+In dmesg:
+
+ LTP: starting msgstress03
+ cgroup: fork rejected by pids controller in /user.slice/user-1000.slice/session-1.scope
+
+The reason is cgroups pid limit set by systemd user.slice. The limit is
+set for login session, also for root user. For example on 2 GB RAM
+machine it is set as:
+ /sys/fs/cgroup/pids/user.slice/user-0.slice/pids.max:5207
+
+Read the maximum number of pids and adjust the test limit. For 2 GB RAM
+machine with systemd this will result in:
+
+ msgstress03 0 TINFO : Found limit of processes 5056 (from /sys/fs/cgroup/pids/user.slice/user-1000.slice/pids.max)
+ msgstress03 0 TINFO : Requested number of processes higher than user session limit (10000 > 4556), setting to 4556
+
+Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+---
+ .../kernel/syscalls/ipc/msgstress/msgstress03.c | 15 ++++++++++++++-
+ 1 file changed, 14 insertions(+), 1 deletion(-)
+
+diff --git a/testcases/kernel/syscalls/ipc/msgstress/msgstress03.c b/testcases/kernel/syscalls/ipc/msgstress/msgstress03.c
+index 294b401b1b38..18e50e35ee07 100644
+--- a/testcases/kernel/syscalls/ipc/msgstress/msgstress03.c
++++ b/testcases/kernel/syscalls/ipc/msgstress/msgstress03.c
+@@ -78,7 +78,7 @@ static void usage(void)
+
+ int main(int argc, char **argv)
+ {
+- int i, j, ok, pid;
++ int i, j, ok, pid, free_pids;
+ int count, status;
+ struct sigaction act;
+
+@@ -109,6 +109,19 @@ int main(int argc, char **argv)
+ }
+ }
+
++ free_pids = tst_get_free_pids(cleanup);
++ if (free_pids < 0) {
++ tst_brkm(TBROK, cleanup, "Can't obtain free_pid count");
++ } else if (!free_pids) {
++ tst_brkm(TBROK, cleanup, "No free pids");
++ }
++ if (nprocs >= free_pids) {
++ tst_resm(TINFO,
++ "Requested number of processes higher than limit (%d > %d), "
++ "setting to %d", nprocs, free_pids, free_pids);
++ nprocs = free_pids;
++ }
++
+ srand(getpid());
+ tid = -1;
+
+--
+2.27.0
+
diff --git a/ubuntu_ltp/patches/0005-syscalls-msgstress-tune-limit-of-processes-for-small.patch b/ubuntu_ltp/patches/0005-syscalls-msgstress-tune-limit-of-processes-for-small.patch
new file mode 100644
index 000000000000..61c4841db300
--- /dev/null
+++ b/ubuntu_ltp/patches/0005-syscalls-msgstress-tune-limit-of-processes-for-small.patch
@@ -0,0 +1,41 @@
+From 019c34b4473f8142c3e3807e8d32d7a678140909 Mon Sep 17 00:00:00 2001
+From: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+Date: Wed, 23 Jun 2021 14:52:53 +0200
+Subject: [PATCH 05/12] syscalls/msgstress: tune limit of processes for small
+ machines
+
+Forking the exactly amount of processes as the limit (either from
+max_pids or from cgroups) is risky - OS might be doing some work and
+interfere with the test. Instead leave some reserve (hard-coded to
+500) for the OS so the test won't fail on fork failure.
+
+Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+---
+ lib/tst_pid.c | 4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+diff --git a/lib/tst_pid.c b/lib/tst_pid.c
+index c1ea3fe90e83..1b2e85959430 100644
+--- a/lib/tst_pid.c
++++ b/lib/tst_pid.c
+@@ -32,6 +32,8 @@
+ #define PID_MAX_PATH "/proc/sys/kernel/pid_max"
+ #define CGROUPS_V1_SLICE_FMT "/sys/fs/cgroup/pids/user.slice/user-%d.slice/pids.max"
+ #define CGROUPS_V2_SLICE_FMT "/sys/fs/cgroup/user.slice/user-%d.slice/pids.max"
++/* Leave some available processes for the OS */
++#define PIDS_RESERVE 500
+
+ pid_t tst_get_unused_pid_(void (*cleanup_fn) (void))
+ {
+@@ -106,7 +108,7 @@ static int get_session_pids_limit(void (*cleanup_fn) (void))
+ if (max_pids < 0)
+ return -1;
+
+- return max_pids;
++ return max_pids > PIDS_RESERVE ? max_pids - PIDS_RESERVE : 0;
+ }
+
+ int tst_get_free_pids_(void (*cleanup_fn) (void))
+--
+2.27.0
+
diff --git a/ubuntu_ltp/patches/0006-device-drivers-cpufreq_boost-skip-test-on-virtual-ma.patch b/ubuntu_ltp/patches/0006-device-drivers-cpufreq_boost-skip-test-on-virtual-ma.patch
new file mode 100644
index 000000000000..848433179610
--- /dev/null
+++ b/ubuntu_ltp/patches/0006-device-drivers-cpufreq_boost-skip-test-on-virtual-ma.patch
@@ -0,0 +1,43 @@
+From cb5b20937220e7f310ccbcb436ba0246cabadbfb Mon Sep 17 00:00:00 2001
+From: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+Date: Wed, 23 Jun 2021 09:56:31 +0200
+Subject: [PATCH 06/12] device-drivers/cpufreq_boost: skip test on virtual
+ machines
+
+Testing CPU frequency boost on virtual machines is not reliable. Even
+if cpufreq driver reports boost frequencies, the underlying hypervisor
+might decide otherwise.
+
+For example on AWS x1e.xlarge instance (claimed to be running on Intel
+Xeon E7 8880) under Xen hypervisor the test always fails:
+
+ cpufreq_boost 0 TINFO : found 'intel_pstate' driver, sysfs knob '/sys/devices/system/cpu/intel_pstate/no_turbo'
+ cpufreq_boost 0 TINFO : maximum speed is 3100000 KHz
+ cpufreq_boost 0 TINFO : load CPU0 with boost enabled
+ cpufreq_boost 0 TINFO : elapsed time is 1155 ms
+ cpufreq_boost 0 TINFO : load CPU0 with boost disabled
+ cpufreq_boost 0 TINFO : elapsed time is 1155 ms
+ cpufreq_boost 1 TFAIL : cpufreq_boost.c:186: compare time spent with and without boost (-2%)
+
+Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+---
+ testcases/kernel/device-drivers/cpufreq/cpufreq_boost.c | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/testcases/kernel/device-drivers/cpufreq/cpufreq_boost.c b/testcases/kernel/device-drivers/cpufreq/cpufreq_boost.c
+index b9739db37cb7..67917b3fea25 100644
+--- a/testcases/kernel/device-drivers/cpufreq/cpufreq_boost.c
++++ b/testcases/kernel/device-drivers/cpufreq/cpufreq_boost.c
+@@ -90,6 +90,9 @@ static void setup(void)
+ unsigned int i;
+ tst_require_root();
+
++ if (tst_is_virt(VIRT_ANY))
++ tst_brkm(TCONF, NULL, "running in a virtual machine, overclock not reliably measureable");
++
+ for (i = 0; i < ARRAY_SIZE(cdrv); ++i) {
+ fd = open(cdrv[i].file, O_RDWR);
+ if (fd == -1)
+--
+2.27.0
+
diff --git a/ubuntu_ltp/patches/0007-lib-memutils-don-t-pollute-entire-system-memory-to-a.patch b/ubuntu_ltp/patches/0007-lib-memutils-don-t-pollute-entire-system-memory-to-a.patch
new file mode 100644
index 000000000000..dbdd937b958c
--- /dev/null
+++ b/ubuntu_ltp/patches/0007-lib-memutils-don-t-pollute-entire-system-memory-to-a.patch
@@ -0,0 +1,59 @@
+From d016d45857c7be2ebfaf74a6b6eb04e3794df536 Mon Sep 17 00:00:00 2001
+From: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+Date: Thu, 24 Jun 2021 15:15:46 +0200
+Subject: [PATCH 07/12] lib: memutils: don't pollute entire system memory to
+ avoid OoM
+
+On big memory systems, e.g. 196 GB RAM machine, the ioctl_sg01 test was
+failing because of OoM killer during memory pollution:
+
+ tst_test.c:1311: TINFO: Timeout per run is 0h 05m 00s
+ ioctl_sg01.c:81: TINFO: Found SCSI device /dev/sg2
+ tst_test.c:1357: TINFO: If you are running on slow machine, try exporting LTP_TIMEOUT_MUL > 1
+ tst_test.c:1359: TBROK: Test killed! (timeout?)
+
+In dmesg:
+
+ [76477.661067] LTP: starting cve-2018-1000204 (ioctl_sg01)
+ [76578.062209] ioctl_sg01 invoked oom-killer: gfp_mask=0x100dca(GFP_HIGHUSER_MOVABLE|__GFP_ZERO), order=0, oom_score_adj=0
+ ...
+ [76578.062335] Mem-Info:
+ [76578.062340] active_anon:63 inactive_anon:49016768 isolated_anon:0
+ active_file:253 inactive_file:117 isolated_file:0
+ unevictable:4871 dirty:4 writeback:0
+ slab_reclaimable:18451 slab_unreclaimable:56355
+ mapped:2478 shmem:310 pagetables:96625 bounce:0
+ free:121136 free_pcp:0 free_cma:0
+ ...
+ [76578.062527] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0-1,global_oom,task_memcg=/user.slice/user-1000.slice/session-40.scope,task=ioctl_sg01,pid=446171,uid=0
+ [76578.062539] Out of memory: Killed process 446171 (ioctl_sg01) total-vm:195955840kB, anon-rss:195941256kB, file-rss:1416kB, shmem-rss:0kB, UID:0 pgtables:383496kB oom_score_adj:0
+ [76581.046078] oom_reaper: reaped process 446171 (ioctl_sg01), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB
+
+It seems leaving hard-coded 128 MB free memory works for small or medium
+systems, but for such bigger machine it creates significant memory
+pressure triggering the out of memory reaper.
+
+The memory pressure usually is defined by ratio between free and total
+memory, so adjust the safety/spare memory similarly to keep always 0.5%
+of memory free.
+
+Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+---
+ lib/tst_memutils.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c
+index dd09db4902b0..abf382d41b20 100644
+--- a/lib/tst_memutils.c
++++ b/lib/tst_memutils.c
+@@ -21,6 +21,7 @@ void tst_pollute_memory(size_t maxsize, int fillchar)
+
+ SAFE_SYSINFO(&info);
+ safety = MAX(4096 * SAFE_SYSCONF(_SC_PAGESIZE), 128 * 1024 * 1024);
++ safety = MAX(safety, (info.freeram / 200));
+ safety /= info.mem_unit;
+
+ if (info.freeswap > safety)
+--
+2.27.0
+
diff --git a/ubuntu_ltp/patches/0008-controllers-memcg-accept-range-of-max_usage_in_bytes.patch b/ubuntu_ltp/patches/0008-controllers-memcg-accept-range-of-max_usage_in_bytes.patch
new file mode 100644
index 000000000000..a6377d89b10b
--- /dev/null
+++ b/ubuntu_ltp/patches/0008-controllers-memcg-accept-range-of-max_usage_in_bytes.patch
@@ -0,0 +1,80 @@
+From d08877889abb964bbc6162465217b2b828853ad3 Mon Sep 17 00:00:00 2001
+From: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+Date: Tue, 8 Jun 2021 10:29:10 +0200
+Subject: [PATCH 08/12] controllers/memcg: accept range of max_usage_in_bytes
+
+Several Linux kernel versions report higher max_usage_in_bytes than
+expected size of 1024 pages. For example v5.4, v5.8, v5.10
+and 5.13.0-rc5:
+
+ memcg_max_usage_in_bytes_test 1 TINFO: Test memory.max_usage_in_bytes
+ memcg_max_usage_in_bytes_test 1 TINFO: Running memcg_process --mmap-anon -s 4194304
+ memcg_max_usage_in_bytes_test 1 TINFO: Warming up pid: 1393215
+ memcg_max_usage_in_bytes_test 1 TINFO: Process is still here after warm up: 1393215
+ memcg_max_usage_in_bytes_test 1 TFAIL: memory.max_usage_in_bytes is 4325376, 4194304 expected
+
+It seems that recent Linux kernel reports more memory used than
+expected.
+
+Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+---
+ .../kernel/controllers/memcg/functional/memcg_lib.sh | 11 +++++++++--
+ .../memcg/functional/memcg_max_usage_in_bytes_test.sh | 6 +++++-
+ 2 files changed, 14 insertions(+), 3 deletions(-)
+
+diff --git a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
+index d9bb6d94324d..083ef376e120 100755
+--- a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
++++ b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
+@@ -140,7 +140,8 @@ shmmax_cleanup()
+
+ # Check size in memcg
+ # $1 - Item name
+-# $2 - Expected size
++# $2 - Expected size lower bound
++# $3 - Expected size upper bound (optional)
+ check_mem_stat()
+ {
+ local item_size
+@@ -151,7 +152,13 @@ check_mem_stat()
+ item_size=$(grep -w $1 memory.stat | cut -d " " -f 2)
+ fi
+
+- if [ "$2" = "$item_size" ]; then
++ if [ "$3" ]; then
++ if [ $item_size -ge $2 ] && [ $item_size -le $3 ]; then
++ tst_res TPASS "$1 is ${2}-${3} as expected"
++ else
++ tst_res TFAIL "$1 is $item_size, ${2}-${3} expected"
++ fi
++ elif [ "$2" = "$item_size" ]; then
+ tst_res TPASS "$1 is $2 as expected"
+ else
+ tst_res TFAIL "$1 is $item_size, $2 expected"
+diff --git a/testcases/kernel/controllers/memcg/functional/memcg_max_usage_in_bytes_test.sh b/testcases/kernel/controllers/memcg/functional/memcg_max_usage_in_bytes_test.sh
+index 14daa4651798..a940606cbd34 100755
+--- a/testcases/kernel/controllers/memcg/functional/memcg_max_usage_in_bytes_test.sh
++++ b/testcases/kernel/controllers/memcg/functional/memcg_max_usage_in_bytes_test.sh
+@@ -12,6 +12,10 @@ TST_CNT=4
+ . memcg_lib.sh
+
+ MEM_TO_ALLOC=$((PAGESIZE * 1024))
++# Recent Linux kernels (at least v5.4) started reporting memory usage of 32
++# pages higher than requested allocation. Cause is not known, so let's just be
++# flexible.
++MEM_EXPECTED_UPPER=$((MEM_TO_ALLOC + PAGESIZE * 32))
+ MEM_LIMIT=$((MEM_TO_ALLOC * 2))
+
+ # Run test cases which checks memory.[memsw.]max_usage_in_bytes after make
+@@ -32,7 +36,7 @@ test_max_usage_in_bytes()
+ signal_memcg_process $MEM_TO_ALLOC
+ signal_memcg_process $MEM_TO_ALLOC
+
+- check_mem_stat $item $MEM_TO_ALLOC
++ check_mem_stat $item $MEM_TO_ALLOC $MEM_EXPECTED_UPPER
+
+ if [ $check_after_reset -eq 1 ]; then
+ echo 0 > $item
+--
+2.27.0
+
diff --git a/ubuntu_ltp/patches/0009-controllers-memcg-accept-range-of-usage_in_bytes.patch b/ubuntu_ltp/patches/0009-controllers-memcg-accept-range-of-usage_in_bytes.patch
new file mode 100644
index 000000000000..bff5e178b686
--- /dev/null
+++ b/ubuntu_ltp/patches/0009-controllers-memcg-accept-range-of-usage_in_bytes.patch
@@ -0,0 +1,198 @@
+From bf5ddfad116796d26f85faf36890770cbba06569 Mon Sep 17 00:00:00 2001
+From: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+Date: Tue, 8 Jun 2021 13:16:12 +0200
+Subject: [PATCH 09/12] controllers/memcg: accept range of usage_in_bytes
+
+Several Linux kernel versions report higher usage_in_bytes than
+expected size of 1024 pages. For example v5.4, v5.8, v5.10
+and 5.13.0-rc5:
+
+ memcg_usage_in_bytes_test 1 TINFO: Test memory.usage_in_bytes
+ memcg_usage_in_bytes_test 1 TINFO: Running memcg_process --mmap-anon -s 4194304
+ memcg_usage_in_bytes_test 1 TINFO: Warming up pid: 1160
+ memcg_usage_in_bytes_test 1 TINFO: Process is still here after warm up: 1160
+ memcg_usage_in_bytes_test 1 TFAIL: memory.usage_in_bytes is 4325376, 4194304 expected
+
+It seems that recent Linux kernel reports more memory used than
+expected.
+
+Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+---
+ .../controllers/memcg/functional/memcg_lib.sh | 11 +++++++---
+ .../memcg/functional/memcg_stat_rss.sh | 20 +++++++++----------
+ .../memcg/functional/memcg_stat_test.sh | 8 ++++----
+ .../functional/memcg_usage_in_bytes_test.sh | 10 ++++++++--
+ 4 files changed, 30 insertions(+), 19 deletions(-)
+
+diff --git a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
+index 083ef376e120..d44bb027076c 100755
+--- a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
++++ b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
+@@ -239,8 +239,9 @@ test_mem_stat()
+ local size=$2
+ local total_size=$3
+ local stat_name=$4
+- local exp_stat_size=$5
+- local check_after_free=$6
++ local exp_stat_size_low=$5
++ local exp_stat_size_up=$6
++ local check_after_free=$7
+
+ start_memcg_process $memtypes -s $size
+
+@@ -251,7 +252,11 @@ test_mem_stat()
+ echo $MEMCG_PROCESS_PID > tasks
+ signal_memcg_process $size
+
+- check_mem_stat $stat_name $exp_stat_size
++ if [ "$exp_stat_size_low" = "$exp_stat_size_up" ]; then
++ check_mem_stat $stat_name $exp_stat_size_low
++ else
++ check_mem_stat $stat_name $exp_stat_size_low $exp_stat_size_up
++ fi
+
+ signal_memcg_process $size
+ if $check_after_free; then
+diff --git a/testcases/kernel/controllers/memcg/functional/memcg_stat_rss.sh b/testcases/kernel/controllers/memcg/functional/memcg_stat_rss.sh
+index 1a6128a6dba8..d9b4ec287b5f 100755
+--- a/testcases/kernel/controllers/memcg/functional/memcg_stat_rss.sh
++++ b/testcases/kernel/controllers/memcg/functional/memcg_stat_rss.sh
+@@ -18,54 +18,54 @@ TST_CNT=10
+ # Test the management and counting of memory
+ test1()
+ {
+- test_mem_stat "--mmap-anon" $PAGESIZES $PAGESIZES "rss" $PAGESIZES false
++ test_mem_stat "--mmap-anon" $PAGESIZES $PAGESIZES "rss" $PAGESIZES $PAGESIZES false
+ }
+
+ test2()
+ {
+- test_mem_stat "--mmap-file" $PAGESIZE $PAGESIZE "rss" 0 false
++ test_mem_stat "--mmap-file" $PAGESIZE $PAGESIZE "rss" 0 0 false
+ }
+
+ test3()
+ {
+- test_mem_stat "--shm -k 3" $PAGESIZE $PAGESIZE "rss" 0 false
++ test_mem_stat "--shm -k 3" $PAGESIZE $PAGESIZE "rss" 0 0 false
+ }
+
+ test4()
+ {
+ test_mem_stat "--mmap-anon --mmap-file --shm" \
+- $PAGESIZES $((PAGESIZES * 3)) "rss" $PAGESIZES false
++ $PAGESIZES $((PAGESIZES * 3)) "rss" $PAGESIZES $PAGESIZES false
+ }
+
+ test5()
+ {
+- test_mem_stat "--mmap-lock1" $PAGESIZES $PAGESIZES "rss" $PAGESIZES false
++ test_mem_stat "--mmap-lock1" $PAGESIZES $PAGESIZES "rss" $PAGESIZES $PAGESIZES false
+ }
+
+ test6()
+ {
+- test_mem_stat "--mmap-anon" $PAGESIZES $PAGESIZES "rss" $PAGESIZES true
++ test_mem_stat "--mmap-anon" $PAGESIZES $PAGESIZES "rss" $PAGESIZES $PAGESIZES true
+ }
+
+ test7()
+ {
+- test_mem_stat "--mmap-file" $PAGESIZE $PAGESIZE "rss" 0 true
++ test_mem_stat "--mmap-file" $PAGESIZE $PAGESIZE "rss" 0 0 true
+ }
+
+ test8()
+ {
+- test_mem_stat "--shm -k 8" $PAGESIZE $PAGESIZE "rss" 0 true
++ test_mem_stat "--shm -k 8" $PAGESIZE $PAGESIZE "rss" 0 0 true
+ }
+
+ test9()
+ {
+ test_mem_stat "--mmap-anon --mmap-file --shm" \
+- $PAGESIZES $((PAGESIZES * 3)) "rss" $PAGESIZES true
++ $PAGESIZES $((PAGESIZES * 3)) "rss" $PAGESIZES $PAGESIZES true
+ }
+
+ test10()
+ {
+- test_mem_stat "--mmap-lock1" $PAGESIZES $PAGESIZES "rss" $PAGESIZES true
++ test_mem_stat "--mmap-lock1" $PAGESIZES $PAGESIZES "rss" $PAGESIZES $PAGESIZES true
+ }
+
+ tst_run
+diff --git a/testcases/kernel/controllers/memcg/functional/memcg_stat_test.sh b/testcases/kernel/controllers/memcg/functional/memcg_stat_test.sh
+index 925c4ecf87bc..e5eb7e5d0001 100755
+--- a/testcases/kernel/controllers/memcg/functional/memcg_stat_test.sh
++++ b/testcases/kernel/controllers/memcg/functional/memcg_stat_test.sh
+@@ -14,28 +14,28 @@ TST_CNT=8
+ test1()
+ {
+ tst_res TINFO "Test cache"
+- test_mem_stat "--shm -k 3" $PAGESIZES $PAGESIZES "cache" $PAGESIZES false
++ test_mem_stat "--shm -k 3" $PAGESIZES $PAGESIZES "cache" $PAGESIZES $PAGESIZES false
+ }
+
+ test2()
+ {
+ tst_res TINFO "Test mapped_file"
+ test_mem_stat "--mmap-file" $PAGESIZES $PAGESIZES \
+- "mapped_file" $PAGESIZES false
++ "mapped_file" $PAGESIZES $PAGESIZES false
+ }
+
+ test3()
+ {
+ tst_res TINFO "Test unevictable with MAP_LOCKED"
+ test_mem_stat "--mmap-lock1" $PAGESIZES $PAGESIZES \
+- "unevictable" $PAGESIZES false
++ "unevictable" $PAGESIZES $PAGESIZES false
+ }
+
+ test4()
+ {
+ tst_res TINFO "Test unevictable with mlock"
+ test_mem_stat "--mmap-lock2" $PAGESIZES $PAGESIZES \
+- "unevictable" $PAGESIZES false
++ "unevictable" $PAGESIZES $PAGESIZES false
+ }
+
+ test5()
+diff --git a/testcases/kernel/controllers/memcg/functional/memcg_usage_in_bytes_test.sh b/testcases/kernel/controllers/memcg/functional/memcg_usage_in_bytes_test.sh
+index e77d6bf2ef23..b5761a4e4716 100755
+--- a/testcases/kernel/controllers/memcg/functional/memcg_usage_in_bytes_test.sh
++++ b/testcases/kernel/controllers/memcg/functional/memcg_usage_in_bytes_test.sh
+@@ -12,13 +12,18 @@ TST_CNT=2
+ . memcg_lib.sh
+
+ MEM_TO_ALLOC=$((PAGESIZE * 1024))
++# Recent Linux kernels (at least v5.4) started reporting memory usage of 32
++# pages higher than requested allocation. Cause is not known, so let's just be
++# flexible.
++MEM_EXPECTED_UPPER=$((MEM_TO_ALLOC + PAGESIZE * 32))
+ MEM_LIMIT=$((MEM_TO_ALLOC * 2))
+
+ test1()
+ {
+ tst_res TINFO "Test memory.usage_in_bytes"
+ test_mem_stat "--mmap-anon" $MEM_TO_ALLOC $MEM_TO_ALLOC \
+- "memory.usage_in_bytes" $MEM_TO_ALLOC false
++ "memory.usage_in_bytes" $MEM_TO_ALLOC \
++ $MEM_EXPECTED_UPPER false
+ }
+
+ test2()
+@@ -29,7 +34,8 @@ test2()
+ echo $MEM_LIMIT > memory.limit_in_bytes
+ echo $MEM_LIMIT > memory.memsw.limit_in_bytes
+ test_mem_stat "--mmap-anon" $MEM_TO_ALLOC $MEM_TO_ALLOC \
+- "memory.memsw.usage_in_bytes" $MEM_TO_ALLOC false
++ "memory.memsw.usage_in_bytes" $MEM_TO_ALLOC \
++ $MEM_EXPECTED_UPPER false
+ }
+
+ tst_run
+--
+2.27.0
+
diff --git a/ubuntu_ltp/patches/0010-controllers-memcg-accept-non-zero-max_usage_in_bytes.patch b/ubuntu_ltp/patches/0010-controllers-memcg-accept-non-zero-max_usage_in_bytes.patch
new file mode 100644
index 000000000000..44499fd5f94d
--- /dev/null
+++ b/ubuntu_ltp/patches/0010-controllers-memcg-accept-non-zero-max_usage_in_bytes.patch
@@ -0,0 +1,45 @@
+From 8c8deb9fd2e41ab9122c28ab90bf2aa8b15f0113 Mon Sep 17 00:00:00 2001
+From: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+Date: Tue, 8 Jun 2021 14:16:40 +0200
+Subject: [PATCH 10/12] controllers/memcg: accept non-zero max_usage_in_bytes
+ after reset
+
+Several Linux kernel versions report a non-zero max_usage_in_bytes after
+resetting the counter. For example v5.4, v5.8, v5.10, v5.11, v5.12 and
+5.13.0-rc5:
+
+ memcg_max_usage_in_bytes_test 4 TINFO: Test reset memory.memsw.max_usage_in_bytes
+ memcg_max_usage_in_bytes_test 4 TINFO: Running memcg_process --mmap-anon -s 4194304
+ memcg_max_usage_in_bytes_test 4 TINFO: Warming up pid: 1416
+ memcg_max_usage_in_bytes_test 4 TINFO: Process is still here after warm up: 1416
+ memcg_max_usage_in_bytes_test 4 TFAIL: memory.memsw.max_usage_in_bytes is 4325376, 4194304 expected
+ memcg_max_usage_in_bytes_test 4 TFAIL: memory.memsw.max_usage_in_bytes is 122880, 0 expected
+
+It seems that recent Linux kernel still notices some memory allocation
+by the memcg tool. Accept therefore a range from 0 to 32 pages.
+
+Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+---
+ .../memcg/functional/memcg_max_usage_in_bytes_test.sh | 6 +++++-
+ 1 file changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/testcases/kernel/controllers/memcg/functional/memcg_max_usage_in_bytes_test.sh b/testcases/kernel/controllers/memcg/functional/memcg_max_usage_in_bytes_test.sh
+index a940606cbd34..8f0fc33996f3 100755
+--- a/testcases/kernel/controllers/memcg/functional/memcg_max_usage_in_bytes_test.sh
++++ b/testcases/kernel/controllers/memcg/functional/memcg_max_usage_in_bytes_test.sh
+@@ -40,7 +40,11 @@ test_max_usage_in_bytes()
+
+ if [ $check_after_reset -eq 1 ]; then
+ echo 0 > $item
+- check_mem_stat $item 0
++ # Recent Linux kernels (at least v5.4) started reporting
++ # a non-zero max_usage_in_bytes after resetting the counter.
++ # The typical values are 0, 4096, 8096 and up to 122880.
++ # Cause is not known, so let's just be flexible.
++ check_mem_stat $item 0 $((PAGESIZE * 32))
+ fi
+
+ stop_memcg_process
+--
+2.27.0
+
diff --git a/ubuntu_ltp/patches/0011-controllers-memcg-increase-memory-limit-in-subgroup-.patch b/ubuntu_ltp/patches/0011-controllers-memcg-increase-memory-limit-in-subgroup-.patch
new file mode 100644
index 000000000000..c05f9df970fc
--- /dev/null
+++ b/ubuntu_ltp/patches/0011-controllers-memcg-increase-memory-limit-in-subgroup-.patch
@@ -0,0 +1,72 @@
+From a33bd1fcad345a16c19178a189c950091cade593 Mon Sep 17 00:00:00 2001
+From: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+Date: Wed, 16 Jun 2021 17:34:36 +0200
+Subject: [PATCH 11/12] controllers/memcg: increase memory limit in subgroup
+ charge
+
+The memcg_subgroup_charge was failing on kernel v5.8 in around 10% cases
+with:
+
+ memcg_subgroup_charge 1 TINFO: Running memcg_process --mmap-anon -s 135168
+ memcg_subgroup_charge 1 TINFO: Warming up pid: 19289
+ memcg_subgroup_charge 1 TINFO: Process is still here after warm up: 19289
+ memcg_subgroup_charge 1 TFAIL: rss is 0, 135168 expected
+ memcg_subgroup_charge 1 TPASS: rss is 0 as expected
+
+In dmesg one could see that OOM killer killed the process even though
+group memory limit was matching the usage:
+
+ memcg_process invoked oom-killer: gfp_mask=0xcc0(GFP_KERNEL), order=0, oom_score_adj=0
+ CPU: 4 PID: 19289 Comm: memcg_process Not tainted 5.8.0-1031-oracle #32~20.04.2-Ubuntu
+ Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.4.1 12/03/2020
+ ...
+ memory: usage 132kB, limit 132kB, failcnt 9
+ memory+swap: usage 132kB, limit 9007199254740988kB, failcnt 0
+ kmem: usage 4kB, limit 9007199254740988kB, failcnt 0
+ ...
+ Tasks state (memory values in pages):
+ [ pid ] uid tgid total_vm rss pgtables_bytes swapents oom_score_adj name
+ [ 19289] 0 19289 669 389 40960 0 0 memcg_process
+ oom-kill:constraint=CONSTRAINT_MEMCG,nodemask=(null),cpuset=/,mems_allowed=0,oom_memcg=/ltp_19257,task_memcg=/ltp_19257,task=memcg_process,pid=19289,uid=0
+ Memory cgroup out of memory: Killed process 19289 (memcg_process) total-vm:2676kB, anon-rss:84kB, file-rss:1468kB, shmem-rss:4kB, UID:0 pgtables:40kB oom_score_adj:0
+ oom_reaper: reaped process 19289 (memcg_process), now anon-rss:0kB, file-rss:0kB, shmem-rss:4kB
+
+It seems using 100% of memory assigned to given group might trigger OOM,
+so add a space of at least one page.
+
+Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+---
+ .../memcg/functional/memcg_subgroup_charge.sh | 16 ++++++++++++++--
+ 1 file changed, 14 insertions(+), 2 deletions(-)
+
+diff --git a/testcases/kernel/controllers/memcg/functional/memcg_subgroup_charge.sh b/testcases/kernel/controllers/memcg/functional/memcg_subgroup_charge.sh
+index 9b23177a4dc5..88ddbabf7fa9 100755
+--- a/testcases/kernel/controllers/memcg/functional/memcg_subgroup_charge.sh
++++ b/testcases/kernel/controllers/memcg/functional/memcg_subgroup_charge.sh
+@@ -19,9 +19,21 @@ TST_CNT=3
+ # $2 - memory.limit_in_bytes in sub group
+ test_subgroup()
+ {
++ local limit_parent=$1
++ local limit_subgroup=$2
++
++ # OOM might start killing if memory usage is 100%, so give it
++ # always one page size more:
++ if [ $limit_parent -ne 0 ]; then
++ limit_parent=$((limit_parent + PAGESIZE))
++ fi
++ if [ $limit_subgroup -ne 0 ]; then
++ limit_subgroup=$((limit_subgroup + PAGESIZE))
++ fi
++
+ mkdir subgroup
+- echo $1 > memory.limit_in_bytes
+- echo $2 > subgroup/memory.limit_in_bytes
++ echo $limit_parent > memory.limit_in_bytes
++ echo $limit_subgroup > subgroup/memory.limit_in_bytes
+
+ start_memcg_process --mmap-anon -s $PAGESIZES
+
+--
+2.27.0
+
diff --git a/ubuntu_ltp/patches/0012-tpci-accept-ENOMEM-resource-failure-with-virtio-pci.patch b/ubuntu_ltp/patches/0012-tpci-accept-ENOMEM-resource-failure-with-virtio-pci.patch
new file mode 100644
index 000000000000..8122906c52d6
--- /dev/null
+++ b/ubuntu_ltp/patches/0012-tpci-accept-ENOMEM-resource-failure-with-virtio-pci.patch
@@ -0,0 +1,81 @@
+From 8b4b1ceb4f869c4ecb59113ea35534db56351f23 Mon Sep 17 00:00:00 2001
+From: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+Date: Fri, 18 Jun 2021 15:00:39 +0200
+Subject: [PATCH 12/12] tpci: accept ENOMEM resource failure with virtio-pci
+
+Assigning the memory prefetch resource to virtio-pci might fail on VM
+guests. For example on Oracle cloud instance (describing itself as
+"Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.4.1
+12/03/2020"):
+
+ test_pci 76 TFAIL : tpci.c:73: PCI bus 00 slot 20 : Test-case '12'
+
+In dmesg:
+
+ ltp_tpci: test-case 12
+ ltp_tpci: assign resources
+ ltp_tpci: assign resource #0
+ ltp_tpci: name = 0000:00:04.0, flags = 262401, start 0xc000, end 0xc03f
+ ltp_tpci: assign resource #1
+ ltp_tpci: name = 0000:00:04.0, flags = 262656, start 0xc1010000, end 0xc1010fff
+ ltp_tpci: assign resource #2
+ ltp_tpci: name = 0000:00:04.0, flags = 0, start 0x0, end 0x0
+ ltp_tpci: assign resource #3
+ ltp_tpci: name = 0000:00:04.0, flags = 0, start 0x0, end 0x0
+ ltp_tpci: assign resource #4
+ ltp_tpci: name = 0000:00:04.0, flags = 538190348, start 0x800004000, end 0x800007fff
+ virtio-pci 0000:00:04.0: BAR 4: no space for [mem size 0x00004000 64bit pref]
+ virtio-pci 0000:00:04.0: BAR 4: failed to assign [mem size 0x00004000 64bit pref]
+ ltp_tpci: assign resource to '4', ret '-12'
+ ltp_tpci: assign resource #5
+ ltp_tpci: name = (null), flags = 0, start 0x0, end 0x0
+ ltp_tpci: assign resource #6
+ ltp_tpci: name = 0000:00:04.0, flags = 0, start 0x0, end 0x0
+
+Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
+
+---
+
+Found the failure on multiple different kernels in different cloud
+providers (Oracle, AWS, Azure):
+https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1878389
+---
+ .../device-drivers/pci/tpci_kernel/ltp_tpci.c | 15 ++++++++++++---
+ 1 file changed, 12 insertions(+), 3 deletions(-)
+
+diff --git a/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c b/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c
+index 5b48aa0c7ece..ca757c1e8a52 100644
+--- a/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c
++++ b/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c
+@@ -108,8 +108,9 @@ static int probe_pci_dev(unsigned int bus, unsigned int slot)
+ if (!dev || !dev->driver)
+ return -ENODEV;
+
+- prk_info("found pci_dev '%s', bus %u, devfn %u",
+- pci_name(dev), bus, slot);
++ prk_info("found pci_dev '%s', driver '%s', bus %u, devfn %u",
++ pci_name(dev), (dev->driver) ? dev->driver->name : "",
++ bus, slot);
+
+ ltp_pci.dev = dev;
+ ltp_pci.bus = dev->bus;
+@@ -444,7 +445,15 @@ static int test_assign_resources(void)
+ r->flags & IORESOURCE_PREFETCH) {
+ ret = pci_assign_resource(dev, i);
+ prk_info("assign resource to '%d', ret '%d'", i, ret);
+- rc |= (ret < 0 && ret != -EBUSY) ? TFAIL : TPASS;
++ if (dev->driver && !strncmp(dev->driver->name, "virtio-pci",
++ strlen("virtio-pci"))) {
++ if (ret < 0 && ret != -EBUSY && ret != -ENOMEM)
++ rc |= TFAIL;
++ else
++ rc |= TPASS;
++ } else {
++ rc |= (ret < 0 && ret != -EBUSY) ? TFAIL : TPASS;
++ }
+ }
+ }
+
+--
+2.27.0
+
diff --git a/ubuntu_ltp/ubuntu_ltp.py b/ubuntu_ltp/ubuntu_ltp.py
index 91ac9649223b..3b89d21d2c92 100644
--- a/ubuntu_ltp/ubuntu_ltp.py
+++ b/ubuntu_ltp/ubuntu_ltp.py
@@ -11,6 +11,33 @@ from autotest.client.shared import error
class ubuntu_ltp(test.test):
version = 1
+ patches = [
+ # Each element is also a list of patch title (user printable) and relative path to patch from bindir
+ ['controllers/cpuacct: skip cpuacct_100_100 on small memory systems',
+ 'patches/0001-controllers-cpuacct-skip-cpuacct_100_100-on-small-me.patch'],
+ ['include/tst_pid.h: fix language typo (subtraction)',
+ 'patches/0002-include-tst_pid.h-fix-language-typo-subtraction.patch'],
+ ['syscalls/msgstress04: fix fork failure on small memory systems',
+ 'patches/0003-syscalls-msgstress04-fix-fork-failure-on-small-memor.patch'],
+ ['syscalls/msgstress03: fix fork failure on small memory systems',
+ 'patches/0004-syscalls-msgstress03-fix-fork-failure-on-small-memor.patch'],
+ ['syscalls/msgstress: tune limit of processes for small machines',
+ 'patches/0005-syscalls-msgstress-tune-limit-of-processes-for-small.patch'],
+ ['patches/device-drivers/cpufreq_boost: skip test on virtual machines',
+ 'patches/0006-device-drivers-cpufreq_boost-skip-test-on-virtual-ma.patch'],
+ ['lib: memutils: don\'t pollute entire system memory to avoid OoM',
+ 'patches/0007-lib-memutils-don-t-pollute-entire-system-memory-to-a.patch'],
+ ['controllers/memcg: accept range of max_usage_in_bytes/memcg: accept range of max_usage_in_bytes',
+ 'patches/0008-controllers-memcg-accept-range-of-max_usage_in_bytes.patch'],
+ ['controllers/memcg: accept range of usage_in_bytes',
+ 'patches/0009-controllers-memcg-accept-range-of-usage_in_bytes.patch'],
+ ['controllers/memcg: accept non-zero max_usage_in_bytes after reset',
+ 'patches/0010-controllers-memcg-accept-non-zero-max_usage_in_bytes.patch'],
+ ['controllers/memcg: increase memory limit in subgroup charge',
+ 'patches/0011-controllers-memcg-increase-memory-limit-in-subgroup-.patch'],
+ ['tpci: accept ENOMEM resource failure with virtio-pci',
+ 'patches/0012-tpci-accept-ENOMEM-resource-failure-with-virtio-pci.patch'],
+ ]
def install_required_pkgs(self):
try:
@@ -36,6 +63,7 @@ class ubuntu_ltp(test.test):
'libselinux1-dev',
'libssl-dev',
'libtirpc-dev',
+ 'patchutils',
'pkg-config',
'quota',
'virt-what',
@@ -73,6 +101,10 @@ class ubuntu_ltp(test.test):
sha1 = utils.system_output('git rev-parse --short HEAD', retain_output=False, verbose=False)
print("Test suite HEAD SHA1: {}".format(sha1))
+ for patch in self.patches:
+ print("Patching with: %s" % patch[0])
+ utils.system('patch -p1 < %s/%s' % (self.bindir, patch[1]))
+
# Disable NTFS as we disable RW support
cmd = 'sed -i /ntfs/d lib/tst_supported_fs_types.c'
utils.system_output(cmd)
--
2.27.0
More information about the kernel-team
mailing list