#include "../kselftest.h"
 #include "cgroup_util.h"
 
+static bool has_localevents;
 static bool has_recursiveprot;
 
 /*
 {
        int ret = KSFT_FAIL;
        char *parent, *child;
+       long parent_oom_events;
 
        parent = cg_name(root, "memcg_test_0");
        child = cg_name(root, "memcg_test_0/memcg_test_1");
        if (!cg_run(memcg, alloc_anon, (void *)MB(100)))
                goto cleanup;
 
-       if (cg_read_key_long(memcg, "memory.events", "oom_kill ") != 3)
-               goto cleanup;
+       parent_oom_events = cg_read_key_long(
+                       parent, "memory.events", "oom_kill ");
+       /*
+        * If memory_localevents is not enabled (the default), the parent should
+        * count OOM events in its children groups. Otherwise, it should not
+        * have observed any events.
+        */
+       if ((has_localevents && parent_oom_events == 0) ||
+            parent_oom_events > 0)
+               ret = KSFT_PASS;
 
        if (kill(safe_pid, SIGKILL))
                goto cleanup;
 
-       ret = KSFT_PASS;
-
 cleanup:
        if (memcg)
                cg_destroy(memcg);
        return ret;
 }
 
-
 #define T(x) { x, #x }
 struct memcg_test {
        int (*fn)(const char *root);
                ksft_exit_skip("Failed to query cgroup mount option\n");
        has_recursiveprot = proc_status;
 
+       proc_status = proc_mount_contains("memory_localevents");
+       if (proc_status < 0)
+               ksft_exit_skip("Failed to query cgroup mount option\n");
+       has_localevents = proc_status;
+
        for (i = 0; i < ARRAY_SIZE(tests); i++) {
                switch (tests[i].fn(root)) {
                case KSFT_PASS: