Skip to content

Commit

Permalink
lazy stack: activate lazy stack in pthreads
Browse files Browse the repository at this point in the history
This patch adds new mmap flag - mmap_stack - that is used when mmaping
a stack when creating new pthread. This new flag is only used when
the build parameter CONF_lazy_stack is enabled.

Signed-off-by: Waldemar Kozaczuk <[email protected]>
  • Loading branch information
wkozaczuk committed Oct 16, 2022
1 parent 9fb4574 commit d6aacab
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions include/osv/mmu-defs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ enum {
mmap_small = 1ul << 5,
mmap_jvm_balloon = 1ul << 6,
mmap_file = 1ul << 7,
mmap_stack = 1ul << 8,
};

enum {
Expand Down
7 changes: 1 addition & 6 deletions libc/mman.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ unsigned libc_flags_to_mmap(int flags)
mmap_flags |= mmu::mmap_populate;
}
if (flags & MAP_STACK) {
// OSv currently requires that stacks be pinned (see issue #143). So
// if an application wants to mmap() a stack for pthread_attr_setstack
// and did us the courtesy of telling this to ue (via MAP_STACK),
// let's return the courtesy by returning pre-faulted memory.
// FIXME: If issue #143 is fixed, this workaround should be removed.
mmap_flags |= mmu::mmap_populate;
mmap_flags |= mmu::mmap_stack;
}
if (flags & MAP_SHARED) {
mmap_flags |= mmu::mmap_shared;
Expand Down
7 changes: 6 additions & 1 deletion libc/pthread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ namespace pthread_private {
return {attr.stack_begin, attr.stack_size};
}
size_t size = attr.stack_size;
void *addr = mmu::map_anon(nullptr, size, mmu::mmap_populate, mmu::perm_rw);
#if CONF_lazy_stack
unsigned stack_flags = mmu::mmap_stack;
#else
unsigned stack_flags = mmu::mmap_populate;
#endif
void *addr = mmu::map_anon(nullptr, size, stack_flags, mmu::perm_rw);
mmu::mprotect(addr, attr.guard_size, 0);
sched::thread::stack_info si{addr, size};
si.deleter = free_stack;
Expand Down

0 comments on commit d6aacab

Please sign in to comment.