mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-08-05 01:46:16 +03:00
San: Implement bump alloc
The new allocator will be used to allocate guarded extents used as slabs for guarded small allocations.
This commit is contained in:
parent
34b00f8969
commit
0f6da1257d
15 changed files with 521 additions and 107 deletions
56
src/pages.c
56
src/pages.c
|
|
@ -365,33 +365,61 @@ pages_decommit(void *addr, size_t size) {
|
|||
|
||||
void
|
||||
pages_mark_guards(void *head, void *tail) {
|
||||
assert(head != NULL && tail != NULL);
|
||||
assert((uintptr_t)head < (uintptr_t)tail);
|
||||
assert(head != NULL || tail != NULL);
|
||||
assert(head == NULL || tail == NULL ||
|
||||
(uintptr_t)head < (uintptr_t)tail);
|
||||
#ifdef JEMALLOC_HAVE_MPROTECT
|
||||
mprotect(head, PAGE, PROT_NONE);
|
||||
mprotect(tail, PAGE, PROT_NONE);
|
||||
if (head != NULL) {
|
||||
mprotect(head, PAGE, PROT_NONE);
|
||||
}
|
||||
if (tail != NULL) {
|
||||
mprotect(tail, PAGE, PROT_NONE);
|
||||
}
|
||||
#else
|
||||
/* Decommit sets to PROT_NONE / MEM_DECOMMIT. */
|
||||
os_pages_commit(head, PAGE, false);
|
||||
os_pages_commit(tail, PAGE, false);
|
||||
if (head != NULL) {
|
||||
os_pages_commit(head, PAGE, false);
|
||||
}
|
||||
if (tail != NULL) {
|
||||
os_pages_commit(tail, PAGE, false);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
pages_unmark_guards(void *head, void *tail) {
|
||||
assert(head != NULL && tail != NULL);
|
||||
assert((uintptr_t)head < (uintptr_t)tail);
|
||||
assert(head != NULL || tail != NULL);
|
||||
assert(head == NULL || tail == NULL ||
|
||||
(uintptr_t)head < (uintptr_t)tail);
|
||||
#ifdef JEMALLOC_HAVE_MPROTECT
|
||||
size_t range = (uintptr_t)tail - (uintptr_t)head + PAGE;
|
||||
if (range <= SC_LARGE_MINCLASS) {
|
||||
bool head_and_tail = (head != NULL) && (tail != NULL);
|
||||
size_t range = head_and_tail ?
|
||||
(uintptr_t)tail - (uintptr_t)head + PAGE :
|
||||
SIZE_T_MAX;
|
||||
/*
|
||||
* The amount of work that the kernel does in mprotect depends on the
|
||||
* range argument. SC_LARGE_MINCLASS is an arbitrary threshold chosen
|
||||
* to prevent kernel from doing too much work that would outweigh the
|
||||
* savings of performing one less system call.
|
||||
*/
|
||||
bool ranged_mprotect = head_and_tail && range <= SC_LARGE_MINCLASS;
|
||||
if (ranged_mprotect) {
|
||||
mprotect(head, range, PROT_READ | PROT_WRITE);
|
||||
} else {
|
||||
mprotect(head, PAGE, PROT_READ | PROT_WRITE);
|
||||
mprotect(tail, PAGE, PROT_READ | PROT_WRITE);
|
||||
if (head != NULL) {
|
||||
mprotect(head, PAGE, PROT_READ | PROT_WRITE);
|
||||
}
|
||||
if (tail != NULL) {
|
||||
mprotect(tail, PAGE, PROT_READ | PROT_WRITE);
|
||||
}
|
||||
}
|
||||
#else
|
||||
os_pages_commit(head, PAGE, true);
|
||||
os_pages_commit(tail, PAGE, true);
|
||||
if (head != NULL) {
|
||||
os_pages_commit(head, PAGE, true);
|
||||
}
|
||||
if (tail != NULL) {
|
||||
os_pages_commit(tail, PAGE, true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue