Example #1
0
File: mem.c Project: Nan619/ltp-ddt
void write_cpusets(long nd)
{
	char buf[BUFSIZ];
	char cpus[BUFSIZ] = "";

	snprintf(buf, BUFSIZ, "%ld", nd);
	write_cpuset_files(CPATH_NEW, "mems", buf);

	_gather_cpus(cpus, nd);
	write_cpuset_files(CPATH_NEW, "cpus", cpus);

	snprintf(buf, BUFSIZ, "%d", getpid());
	write_file(CPATH_NEW "/tasks", buf);
}
Example #2
0
int main(int argc, char *argv[])
{
	int lc;

	tst_parse_opts(argc, argv, NULL, NULL);

#if __WORDSIZE == 32
	tst_brkm(TCONF, NULL, "test is not designed for 32-bit system.");
#endif

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		tst_count = 0;

		tst_resm(TINFO, "OOM on CPUSET...");
		testoom(0, 0, ENOMEM, 1);

		if (is_numa(cleanup)) {
			/*
			 * Under NUMA system, the migration of cpuset's memory
			 * is in charge of cpuset.memory_migrate, we can write
			 * 1 to cpuset.memory_migrate to enable the migration.
			 */
			write_cpuset_files(CPATH_NEW,
					   "memory_migrate", "1");
			tst_resm(TINFO, "OOM on CPUSET with mem migrate:");
			testoom(0, 0, ENOMEM, 1);
		}
	}
	cleanup();
	tst_exit();
}
Example #3
0
int main(int argc, char *argv[])
{
    char *msg;
    int lc;
    int swap_acc_on = 1;

    msg = parse_opts(argc, argv, NULL, NULL);
    if (msg != NULL)
        tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

#if __WORDSIZE == 32
    tst_brkm(TCONF, NULL, "test is not designed for 32-bit system.");
#endif

    setup();

    for (lc = 0; TEST_LOOPING(lc); lc++) {
        tst_count = 0;

        tst_resm(TINFO, "OOM on CPUSET & MEMCG...");
        testoom(0, 0);

        /*
         * Under NUMA system, the migration of cpuset's memory
         * is in charge of cpuset.memory_migrate, we can write
         * 1 to cpuset.memory_migrate to enable the migration.
         */
        if (is_numa(cleanup)) {
            write_cpuset_files(CPATH_NEW, "memory_migrate", "1");
            tst_resm(TINFO, "OOM on CPUSET & MEMCG with "
                     "cpuset.memory_migrate=1");
            testoom(0, 0);
        }

        if (access(MEMCG_SW_LIMIT, F_OK) == -1) {
            if (errno == ENOENT) {
                tst_resm(TCONF,
                         "memcg swap accounting is disabled");
                swap_acc_on = 0;
            } else
                tst_brkm(TBROK|TERRNO, cleanup, "access");
        }

        if (swap_acc_on) {
            tst_resm(TINFO, "OOM on CPUSET & MEMCG with "
                     "special memswap limitation:");
            SAFE_FILE_PRINTF(cleanup, MEMCG_SW_LIMIT, "%ld", TESTMEM);
            testoom(0, 0);

            tst_resm(TINFO, "OOM on CPUSET & MEMCG with "
                     "disabled memswap limitation:");
            SAFE_FILE_PRINTF(cleanup, MEMCG_SW_LIMIT, "-1");
            testoom(0, 0);
        }
    }

    cleanup();
    tst_exit();
}
Example #4
0
static void testcpuset(void)
{
	int lc;
	int child, i, status;
	unsigned long nmask[MAXNODES / BITS_PER_LONG] = { 0 };
	char mems[BUFSIZ], buf[BUFSIZ];

	read_cpuset_files(CPATH, "cpus", buf);
	write_cpuset_files(CPATH_NEW, "cpus", buf);
	read_cpuset_files(CPATH, "mems", mems);
	write_cpuset_files(CPATH_NEW, "mems", mems);
	SAFE_FILE_PRINTF(cleanup, CPATH_NEW "/tasks", "%d", getpid());

	switch (child = fork()) {
	case -1:
		tst_brkm(TBROK | TERRNO, cleanup, "fork");
	case 0:
		for (i = 0; i < nnodes; i++) {
			if (nodes[i] >= MAXNODES)
				continue;
			set_node(nmask, nodes[i]);
		}
		if (set_mempolicy(MPOL_BIND, nmask, MAXNODES) == -1)
			tst_brkm(TBROK | TERRNO, cleanup, "set_mempolicy");
		exit(mem_hog_cpuset(ncpus > 1 ? ncpus : 1));
	}
	for (lc = 0; TEST_LOOPING(lc); lc++) {
		tst_count = 0;
		snprintf(buf, BUFSIZ, "%d", nodes[0]);
		write_cpuset_files(CPATH_NEW, "mems", buf);
		snprintf(buf, BUFSIZ, "%d", nodes[1]);
		write_cpuset_files(CPATH_NEW, "mems", buf);
	}

	if (waitpid(child, &status, WUNTRACED | WCONTINUED) == -1)
		tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
	if (WEXITSTATUS(status) != 0)
		tst_resm(TFAIL, "child exit status is %d", WEXITSTATUS(status));
}
Example #5
0
void write_cpusets(long nd)
{
	char buf[BUFSIZ];
	char cpus[BUFSIZ] = "";

	snprintf(buf, BUFSIZ, "%ld", nd);
	write_cpuset_files(CPATH_NEW, "mems", buf);

	gather_node_cpus(cpus, nd);
	/*
	 * If the 'nd' node doesn't contain any CPUs,
	 * the first ID of CPU '0' will be used as
	 * the value of cpuset.cpus.
	 */
	if (strlen(cpus) != 0) {
		write_cpuset_files(CPATH_NEW, "cpus", cpus);
	} else {
		tst_resm(TINFO, "No CPUs in the node%ld; "
				"using only CPU0", nd);
		write_cpuset_files(CPATH_NEW, "cpus", "0");
	}

	SAFE_FILE_PRINTF(NULL, CPATH_NEW "/tasks", "%d", getpid());
}
Example #6
0
File: oom04.c Project: sathnaga/ltp
static void verify_oom(void)
{
#if __WORDSIZE == 32
	tst_brk(TCONF, "test is not designed for 32-bit system.");
#endif

	tst_res(TINFO, "OOM on CPUSET...");
	testoom(0, 0, ENOMEM, 1);

	if (is_numa(NULL, NH_MEMS, 2)) {
		/*
		 * Under NUMA system, the migration of cpuset's memory
		 * is in charge of cpuset.memory_migrate, we can write
		 * 1 to cpuset.memory_migrate to enable the migration.
		 */
		write_cpuset_files(CPATH_NEW, "memory_migrate", "1");
		tst_res(TINFO, "OOM on CPUSET with mem migrate:");
		testoom(0, 0, ENOMEM, 1);
	}
}