Skip to content

Commit d6aacab

Browse files
committed
lazy stack: activate lazy stack in pthreads
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]>
1 parent 9fb4574 commit d6aacab

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

include/osv/mmu-defs.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ enum {
8484
mmap_small = 1ul << 5,
8585
mmap_jvm_balloon = 1ul << 6,
8686
mmap_file = 1ul << 7,
87+
mmap_stack = 1ul << 8,
8788
};
8889

8990
enum {

libc/mman.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,7 @@ unsigned libc_flags_to_mmap(int flags)
4343
mmap_flags |= mmu::mmap_populate;
4444
}
4545
if (flags & MAP_STACK) {
46-
// OSv currently requires that stacks be pinned (see issue #143). So
47-
// if an application wants to mmap() a stack for pthread_attr_setstack
48-
// and did us the courtesy of telling this to ue (via MAP_STACK),
49-
// let's return the courtesy by returning pre-faulted memory.
50-
// FIXME: If issue #143 is fixed, this workaround should be removed.
51-
mmap_flags |= mmu::mmap_populate;
46+
mmap_flags |= mmu::mmap_stack;
5247
}
5348
if (flags & MAP_SHARED) {
5449
mmap_flags |= mmu::mmap_shared;

libc/pthread.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,12 @@ namespace pthread_private {
141141
return {attr.stack_begin, attr.stack_size};
142142
}
143143
size_t size = attr.stack_size;
144-
void *addr = mmu::map_anon(nullptr, size, mmu::mmap_populate, mmu::perm_rw);
144+
#if CONF_lazy_stack
145+
unsigned stack_flags = mmu::mmap_stack;
146+
#else
147+
unsigned stack_flags = mmu::mmap_populate;
148+
#endif
149+
void *addr = mmu::map_anon(nullptr, size, stack_flags, mmu::perm_rw);
145150
mmu::mprotect(addr, attr.guard_size, 0);
146151
sched::thread::stack_info si{addr, size};
147152
si.deleter = free_stack;

0 commit comments

Comments
 (0)