Пример #1
0
static void do_test(void)
{
	long free;
	long nproc;
	long dummy;

	SAFE_FILE_LINES_SCANF("/proc/meminfo", "MemFree: %ld", &free);
	if (FILE_LINES_SCANF("/proc/stat", "processes %ld", &nproc))
		tst_brk(TBROK, "Could not parse processes");
	tst_res(TPASS, "Free: %ld, nproc: %ld", free, nproc);

	if (FILE_LINES_SCANF("/proc/stat", "non-existent %ld", &dummy))
		tst_res(TPASS, "non-existent not found");
	SAFE_FILE_LINES_SCANF("/proc/stat", "non-existent %ld", &dummy);
}
Пример #2
0
static void memory_pressure_child(void)
{
	size_t i, page_size = getpagesize();
	char *ptr;

	for (;;) {
		ptr = mmap(NULL, 500 * page_size, PROT_READ | PROT_WRITE,
			   MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);

		for (i = 0; i < 500; i++) {
			ptr[i * page_size] = i % 100;
			usleep(sleep_between_faults);
		}

		/* If swap accounting is disabled exit after process swapped out 100MB */
		if (!swap_accounting_enabled) {
			int swapped;

			SAFE_FILE_LINES_SCANF("/proc/self/status", "VmSwap: %d", &swapped);

			if (swapped > 100 * 1024)
				exit(0);
		}

	}

	abort();
}
Пример #3
0
static unsigned long get_cached_size(void)
{
	unsigned long ret;

	SAFE_FILE_LINES_SCANF(MEMINFO_FNAME, "Cached: %lu", &ret);

	return ret;
}
Пример #4
0
static unsigned long get_bytes_read(void)
{
	unsigned long ret;

	SAFE_FILE_LINES_SCANF(PROC_IO_FNAME, "read_bytes: %lu", &ret);

	return ret;
}
Пример #5
0
static void setup(void)
{
	long int swap_total;

	if (access(MEMCG_PATH, F_OK)) {
		tst_brk(TCONF, "'" MEMCG_PATH
			"' not present, CONFIG_MEMCG missing?");
	}

	if (!access(MEMCG_PATH "memory.memsw.limit_in_bytes", F_OK))
		swap_accounting_enabled = 1;
	else
		tst_res(TINFO, "Swap accounting is disabled");

	SAFE_FILE_LINES_SCANF("/proc/meminfo", "SwapTotal: %ld", &swap_total);
	if (swap_total <= 0)
		tst_brk(TCONF, "MADV_FREE does not work without swap");

	page_size = getpagesize();
}