"report" : 0,
"sampling_rate": 1.0,
"apply_to_children" : 0,
- "mem_limit_avg" : 0.30,
- "mem_limit_peak" : 0.60,
- "comment_to_above" : "% of reference target (1 GB on rpi3)",
+ "mem_limit_avg" : 0.20,
+ "mem_limit_peak" : 0.40,
+ "comment_to_above" : "don't use values close to 1 (risks OOM killer)",
"mem_limit_period" : 3
},
"test-stability-fd" : {
#include <cstdlib>
// C++
+#include <fstream>
+#include <iostream>
#include <thread>
#include <vector>
// POSIX
#include <sys/sysinfo.h>
+static size_t total_ram_kb; // /proc/meminfo returns in kB
+static size_t total_ram_b () { return total_ram_kb * 1024; }
+static size_t total_ram_mb () { return total_ram_kb / 1024; }
+
static void * do_mem (size_t to_alloc)
{
/* Allocate memory and pretend we're using it (so as to make it actually
return nullptr;
}
+static void get_total_ram ()
+{
+ std::ifstream meminfo ("/proc/meminfo");
+
+ std::string entry_name;
+ meminfo >> entry_name >> total_ram_kb;
+
+ if (entry_name != "MemTotal:")
+ throw std::runtime_error ("Unexpected format of /proc/meminfo");
+
+ std::cout << "Total RAM: " << total_ram_mb () << " MB" << std::endl;
+}
+
unsigned long long operator "" _MB (unsigned long long n)
{ return 1024 * 1024 * n; }
static void * mem_heavy_peak (void * arg)
-{ return do_mem (750_MB); }
+{ return do_mem (0.5f * total_ram_b ()); }
static void * mem_heavy_avg (void * arg)
-{ return do_mem (400_MB); }
+{ return do_mem (0.3f * total_ram_b ()); }
static void * mem_light (void * arg)
{ return do_mem (25_MB); }
int main (int argc, char ** argv)
{
+ get_total_ram ();
+
const std::vector <std::pair <bool (*) (), std::string>> test_cases
{ { []() {
/* Do a reasonable amount of memory (re)allocation.
/* Allocate and keep lots of memory.
* Expect a signal. */
return ! run_mem_test (mem_heavy_peak, TEST_TIME_PEAK, & handler_peak);
- } , "heavy allocation (750 MB + overhead), expecting peak signal"
+ } , "heavy allocation (50% of total (" + std::to_string(size_t (0.5 * total_ram_mb ())) + " MB) + overhead), expecting peak signal"
} , { []() {
/* Allocate an amount of memory not high enough
* to trigger peak, but keep it long enough to
* trigger average. */
return ! run_mem_test (mem_heavy_avg, TEST_TIME_AVG, & handler_avg);
- } , "medium allocation (400 MB + overhead), expecting avg signal"
+ } , "medium allocation (30% of total (" + std::to_string(size_t (0.3 * total_ram_mb ())) + " MB) + overhead), expecting avg signal"
}
};