Esempio n. 1
0
void connectPrereqsToTargets(const std::string & s, Graph & g) {
    auto it = s.begin();
    std::set<Class>::iterator targetIt;
    while (it != s.end()) {
        if (*it == ':') {
            std::string target(s.begin(), it);
            targetIt = g.classes.find(Class(target));
            assert(targetIt != g.classes.end());
            ++it;
            break;
        }
        ++it;
    }
    while (it != s.end()) {
        ++it;
        auto endit = it;
        while (endit != s.end() && *endit != ' ') { ++endit; }
        std::string prereq(std::string(it, endit));
        std::set<Class>::iterator prereqIt =
            g.classes.find(Class(prereq));
        assert(prereqIt != g.classes.end());
        g.connect(targetIt, prereqIt);
        it = endit;
    }
}
Esempio n. 2
0
void readValidInputLine(const std::string & s, Graph & g) {
    auto it = s.begin();
    while (it != s.end()) {
        if (*it == ':') {
            std::string target(s.begin(), it);
            g.addNode(Class(target));
            ++it;
            break;
        }
        ++it;
    }
    while (it != s.end()) {
        ++it;
        auto endit = it;
        while (endit != s.end() && *endit != ' ') { ++endit; }
        std::string prereq(std::string(it, endit));
        g.addNode(Class(prereq));
        it = endit;
    }
}
Esempio n. 3
0
int main(int argc, char **argv)
{
	struct rlimit lim;
	struct map_list *list, *entry;
	size_t page_size, i;
	void *map = NULL;
	unsigned long mem_free = 0;
	unsigned long hugepage_size = 0;
	unsigned long mem_fragmentable = 0;

	if (prereq() != 0) {
		printf("Either the sysctl compact_unevictable_allowed is not\n"
		       "set to 1 or couldn't read the proc file.\n"
		       "Skipping the test\n");
		return 0;
	}

	lim.rlim_cur = RLIM_INFINITY;
	lim.rlim_max = RLIM_INFINITY;
	if (setrlimit(RLIMIT_MEMLOCK, &lim)) {
		perror("Failed to set rlimit:\n");
		return -1;
	}

	page_size = getpagesize();

	list = NULL;

	if (read_memory_info(&mem_free, &hugepage_size) != 0) {
		printf("ERROR: Cannot read meminfo\n");
		return -1;
	}

	mem_fragmentable = mem_free * 0.8 / 1024;

	while (mem_fragmentable > 0) {
		map = mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE,
			   MAP_ANONYMOUS | MAP_PRIVATE | MAP_LOCKED, -1, 0);
		if (map == MAP_FAILED)
			break;

		entry = malloc(sizeof(struct map_list));
		if (!entry) {
			munmap(map, MAP_SIZE);
			break;
		}
		entry->map = map;
		entry->next = list;
		list = entry;

		/* Write something (in this case the address of the map) to
		 * ensure that KSM can't merge the mapped pages
		 */
		for (i = 0; i < MAP_SIZE; i += page_size)
			*(unsigned long *)(map + i) = (unsigned long)map + i;

		mem_fragmentable--;
	}

	for (entry = list; entry != NULL; entry = entry->next) {
		munmap(entry->map, MAP_SIZE);
		if (!entry->next)
			break;
		entry = entry->next;
	}

	if (check_compaction(mem_free, hugepage_size) == 0)
		return 0;

	return -1;
}