Skip to content

Commit c8cdbde

Browse files
committed
lazy stack: new tracepoint for stack pre-faults
This last patch of the series adds new tracepoint - mmu_vm_stack_fault - which when enabled allows one to see how particular app triggers the stack page faults. The tracepoint captures the stack fault address, the thread id and number of the page (0 being the 1st page). Please note this does not capture the 1st page of the stack (page_no 0) as this one pre-faulted by the parent thread that creates a new one. ./scripts/run.py -e /tests/tst-pipe.so --trace=mmu_vm_stack_fault --trace-backtrace -H ./scripts/trace.py extract && ./scripts/trace.py list -bl 0xffff8000016b7040 >init 0 0.002215401 mmu_vm_stack_fault thread=32, addr=0x00002000000ff9d0, page_no=1 mmu::vm_fault(unsigned long, exception_frame*) page_fault ex_pf std_malloc(unsigned long, unsigned long) malloc operator new(unsigned long) do_main_thread(void*) std::_Function_handler<void (), pthread_private::pthread::pthread(void* (*)(void*), void*, sigset_t, pthread_private::thread_attr const*)::{lambda()#1}>::_M_invoke(std::_Any_data const&) __invoke_impl<void, pthread_private::pthread::pthread(void* (*)(void*), void*, sigset_t, const pthread_private::thread_attr*)::<lambda()>&>__invoke_r<void, pthread_private::pthread::pthread(void* (*)(void*), void*, sigset_t, const pthread_private::thread_attr*)::<lambda()>&> _M_invoke sched::thread::main() thread_main_c ... 0xffff8000016b7040 >init 0 0.084799151 mmu_vm_stack_fault thread=32, addr=0x00002000000f8440, page_no=8 mmu::vm_fault(unsigned long, exception_frame*) page_fault ex_pf memory::page_pool::l1::alloc_page() untracked_alloc_page memory::alloc_page() std_malloc(unsigned long, unsigned long) malloc operator new(unsigned long) lookup sys_lstat Signed-off-by: Waldemar Kozaczuk <[email protected]>
1 parent d6aacab commit c8cdbde

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

core/mmu.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,9 @@ bool access_fault(vma& vma, unsigned int error_code)
14131413
TRACEPOINT(trace_mmu_vm_fault, "addr=%p, error_code=%x", uintptr_t, unsigned int);
14141414
TRACEPOINT(trace_mmu_vm_fault_sigsegv, "addr=%p, error_code=%x, %s", uintptr_t, unsigned int, const char*);
14151415
TRACEPOINT(trace_mmu_vm_fault_ret, "addr=%p, error_code=%x", uintptr_t, unsigned int);
1416+
#if CONF_lazy_stack
1417+
TRACEPOINT(trace_mmu_vm_stack_fault, "thread=%d, addr=%p, page_no=%d", unsigned int, uintptr_t, unsigned int);
1418+
#endif
14161419

14171420
static void vm_sigsegv(uintptr_t addr, exception_frame* ef)
14181421
{
@@ -1438,6 +1441,14 @@ void vm_fault(uintptr_t addr, exception_frame* ef)
14381441
trace_mmu_vm_fault_sigsegv(addr, ef->get_error(), "fast");
14391442
return;
14401443
}
1444+
#if CONF_lazy_stack
1445+
auto stack = sched::thread::current()->get_stack_info();
1446+
void *v_addr = reinterpret_cast<void*>(addr);
1447+
if (v_addr >= stack.begin && v_addr < stack.begin + stack.size) {
1448+
trace_mmu_vm_stack_fault(sched::thread::current()->id(), addr,
1449+
((u64)(stack.begin + stack.size - addr)) / 4096);
1450+
}
1451+
#endif
14411452
addr = align_down(addr, mmu::page_size);
14421453
WITH_LOCK(vma_list_mutex.for_read()) {
14431454
auto vma = find_intersecting_vma(addr);

0 commit comments

Comments
 (0)