smaps = seek_to_smaps_entry(addr); if (!smaps)
ksft_exit_fail_msg("Unable to parse /proc/self/smaps\n");
while (getline(&line, &size, smaps) > 0) { if (!strstr(line, "MMUPageSize")) {
free(line);
line = NULL;
size = 0; continue;
}
/* found the MMUPageSize of this section */ if (sscanf(line, "MMUPageSize: %8lu kB", &mmupage_size) < 1)
ksft_exit_fail_msg("Unable to parse smaps entry for Size:%s\n",
line);
}
free(line); if (smaps)
fclose(smaps); return mmupage_size << 10;
}
/* *Testmlock/mlock2()onprovidedmemorychunk. *Itexpectsthemlock/mlock2()tobesuccessful(withinrlimit) * *Withallocatedmemorychunk[p,p+alloc_size),this *testwillchoosestart/lenrandomlytoperformmlock/mlock2 *[start,start+len]memoryrange.Therangeiswithinrange *oftheallocatedchunk. * *Thememoryregionsizealloc_sizeiswithintherlimit. *Sowealwaysexpectasuccessofmlock/mlock2. * *VmLckisassumedtobe0beforethistest. * *returnvalue:0-success *else:failure
*/ staticvoid test_mlock_within_limit(char *p, int alloc_size)
{ int i; int ret = 0; int locked_vm_size = 0; struct rlimit cur; int page_size = 0;
getrlimit(RLIMIT_MEMLOCK, &cur); if (cur.rlim_cur < alloc_size)
ksft_exit_fail_msg("alloc_size[%d] < %u rlimit,lead to mlock failure\n",
alloc_size, (unsignedint)cur.rlim_cur);
srand(time(NULL)); for (i = 0; i < TEST_LOOP; i++) { /* *-choosemlock/mlock2randomly *-chooselock_sizerandomlybutlock_size<alloc_size *-choosestart_offsetrandomlybutp+start_offset+lock_size *<p+alloc_size
*/ int is_mlock = !!(rand() % 2); int lock_size = rand() % alloc_size; int start_offset = rand() % (alloc_size - lock_size);
if (is_mlock)
ret = mlock(p + start_offset, lock_size); else
ret = mlock2_(p + start_offset, lock_size,
MLOCK_ONFAULT);
if (ret)
ksft_exit_fail_msg("%s() failure (%s) at |%p(%d)| mlock:|%p(%d)|\n",
is_mlock ? "mlock" : "mlock2",
strerror(errno), p, alloc_size,
p + start_offset, lock_size);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.