page faults
I need some help finding the cause for page faults in my RT application. My app has a startup phase, where I can tolerate page faults, and a hard realtime phase, where page faults cannot be tolerated. Trouble is, I continue to get page faults in the hard realtime phase.
The app encounters a page fault while writing to a heap buffer. I've even added steps to clear the entire buffer in the startup phase, after mlockall(), to ensure each page is locked in place. Here's a timeline of the fault:
static constructor runs and allocates buffer from heap application main() runs
begin application startup phasemlockall(MCL_CURRENT | MCL_FUTURE) runs and returns 0 entire buffer cleared
paranoid code even verifies buffer addr 0x81f4000 contents are 0 begin application hard realtime phase
time elapses ...
page fault copying stack addr 0xb645a2d1 to heap buffer addr 0x81f4000
The page fault is confirmed by the kernel debug message:
Xenomai: Switching mythread to secondary mode after exception #14 from user-space at 0x80fb8c5 (pid 3558)
as well as the delivery of SIGXCPU to my application (at my request).
How do I prevent this page fault?
Is this issue covered by the recent NOCOW activity?
thanks,
Jeff
my config:
CPU: VIA Nehemiah (i386)
ipipe version: 1.5-00
Xenomai: 2.2.4
Linux kernel: 2.6.17.14
Quoted 20 lines · Jeff Weber
I need some help finding the cause for page faults in my RT application. My app has a startup phase, where I can tolerate page faults, and a hard realtime phase, where page faults cannot be tolerated. Trouble is, I continue to get page faults in the hard realtime phase.
The app encounters a page fault while writing to a heap buffer. I've even added steps to clear the entire buffer in the startup phase, after
mlockall(), to ensure each page is locked in place. Here's a timeline of the fault:static constructor runs and allocates buffer from heap application
main()runs
begin application startup phasemlockall(MCL_CURRENT | MCL_FUTURE)runs and returns 0 entire buffer cleared
paranoid code even verifies buffer addr0x81f4000contents are 0 begin application hard realtime phase
time elapses ...
page fault copying stack addr0xb645a2d1to heap buffer addr0x81f4000
Quoted 4 lines
The page fault is confirmed by the kernel debug message:
Xenomai: Switching mythread to secondary mode after exception #14 from user-space at0x80fb8c5(pid 3558)
Could you disassemble the code around location 0x80fb8c5?
Quoted 6 lines
as well as the delivery of SIGXCPU to my application (at my request).
How do I prevent this page fault?
Is this issue covered by the recent NOCOW activity?
Possibly. You need I-pipe 1.7-03 and Xenomai >= v2.3.1 to get the ondemand mapping scheme disabled by the nucleus when your thread starts.
Quoted 13 lines
thanks,
Jeffmy config:
CPU: VIA Nehemiah (i386)
ipipe version: 1.5-00
Xenomai: 2.2.4
Linux kernel: 2.6.17.14_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help
Signature · 1 line
Philippe.
Quoted 1 line · Philippe Gerum
Could you disassemble the code around location
0x80fb8c5?
The latest version of my code has moved the the addresses a bit:
Xenomai: Switching mythread to secondary mode after exception #14 from user-space at 0x80fb8cd (pid 3590)
(gdb) disas
Dump of assembler code for function _ZN4AMSC8CRtDequeIcE9push_backERKc:
0x080fb8b4 <_ZN4AMSC8CRtDequeIcE9push_backERKc+0>: push %ebp 0x080fb8b5 <_ZN4AMSC8CRtDequeIcE9push_backERKc+1>: mov %esp,%ebp 0x080fb8b7 <_ZN4AMSC8CRtDequeIcE9push_backERKc+3>: sub $0x8,%esp 0x080fb8ba <_ZN4AMSC8CRtDequeIcE9push_backERKc+6>: mov 0x8(%ebp),%edx 0x080fb8bd <_ZN4AMSC8CRtDequeIcE9push_backERKc+9>: mov 0x8(%ebp),%eax 0x080fb8c0 <_ZN4AMSC8CRtDequeIcE9push_backERKc+12>: mov 0x8(%eax),%eax 0x080fb8c3 <_ZN4AMSC8CRtDequeIcE9push_backERKc+15>: mov (%edx),%edx 0x080fb8c5 <_ZN4AMSC8CRtDequeIcE9push_backERKc+17>: add %eax,%edx 0x080fb8c7 <_ZN4AMSC8CRtDequeIcE9push_backERKc+19>: mov 0xc(%ebp),%eax 0x080fb8ca <_ZN4AMSC8CRtDequeIcE9push_backERKc+22>: movzbl (%eax),%eax 0x080fb8cd <_ZN4AMSC8CRtDequeIcE9push_backERKc+25>: mov %al,(%edx) 0x080fb8cf <_ZN4AMSC8CRtDequeIcE9push_backERKc+27>: mov 0x8(%ebp),%eax 0x080fb8d2 <_ZN4AMSC8CRtDequeIcE9push_backERKc+30>: add $0x8,%eax 0x080fb8d5 <_ZN4AMSC8CRtDequeIcE9push_backERKc+33>: mov %eax,0x4(%esp) 0x080fb8d9 <_ZN4AMSC8CRtDequeIcE9push_backERKc+37>: mov 0x8(%ebp),%eax 0x080fb8dc <_ZN4AMSC8CRtDequeIcE9push_backERKc+40>: mov %eax,(%esp) 0x080fb8df <_ZN4AMSC8CRtDequeIcE9push_backERKc+43>: call 0x80fcb18 <_ZN4AMSC8CRtDequeIcE3incERi>
Quoted 9 lines
Quoted 6 lines
as well as the delivery of SIGXCPU to my application (at my request).
How do I prevent this page fault?
Is this issue covered by the recent NOCOW activity?
Possibly. You need I-pipe 1.7-03 and Xenomai >= v2.3.1 to get the ondemand mapping scheme disabled by the nucleus when your thread starts.
I am not familiar with the purpose and implementation of the NOCOW patch. How would the patch affect my page fault issue?
thanks,
Jeff
Quoted 29 lines · Jeff Weber
Quoted 1 line · Philippe Gerum
Could you disassemble the code around location
0x80fb8c5?The latest version of my code has moved the the addresses a bit:
Xenomai: Switching mythread to secondary mode after exception #14 from user-space at0x80fb8cd(pid 3590)(gdb) disas
Dump of assembler code for function_ZN4AMSC8CRtDequeIcE9push_backERKc:0x080fb8b4 <_ZN4AMSC8CRtDequeIcE9push_backERKc+0>: push %ebp 0x080fb8b5 <_ZN4AMSC8CRtDequeIcE9push_backERKc+1>: mov %esp,%ebp 0x080fb8b7 <_ZN4AMSC8CRtDequeIcE9push_backERKc+3>: sub $0x8,%esp 0x080fb8ba <_ZN4AMSC8CRtDequeIcE9push_backERKc+6>: mov 0x8(%ebp),%edx 0x080fb8bd <_ZN4AMSC8CRtDequeIcE9push_backERKc+9>: mov 0x8(%ebp),%eax 0x080fb8c0 <_ZN4AMSC8CRtDequeIcE9push_backERKc+12>: mov 0x8(%eax),%eax 0x080fb8c3 <_ZN4AMSC8CRtDequeIcE9push_backERKc+15>: mov (%edx),%edx 0x080fb8c5 <_ZN4AMSC8CRtDequeIcE9push_backERKc+17>: add %eax,%edx 0x080fb8c7 <_ZN4AMSC8CRtDequeIcE9push_backERKc+19>: mov 0xc(%ebp),%eax 0x080fb8ca <_ZN4AMSC8CRtDequeIcE9push_backERKc+22>: movzbl (%eax),%eax 0x080fb8cd <_ZN4AMSC8CRtDequeIcE9push_backERKc+25>: mov %al,(%edx) 0x080fb8cf <_ZN4AMSC8CRtDequeIcE9push_backERKc+27>: mov 0x8(%ebp),%eax 0x080fb8d2 <_ZN4AMSC8CRtDequeIcE9push_backERKc+30>: add $0x8,%eax 0x080fb8d5 <_ZN4AMSC8CRtDequeIcE9push_backERKc+33>: mov %eax,0x4(%esp) 0x080fb8d9 <_ZN4AMSC8CRtDequeIcE9push_backERKc+37>: mov 0x8(%ebp),%eax 0x080fb8dc <_ZN4AMSC8CRtDequeIcE9push_backERKc+40>: mov %eax,(%esp) 0x080fb8df <_ZN4AMSC8CRtDequeIcE9push_backERKc+43>: call 0x80fcb18 <_ZN4AMSC8CRtDequeIcE3incERi>Quoted 3 lines
Quoted 3 lines
as well as the delivery of SIGXCPU to my application (at my request).
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
How do I prevent this page fault?
Is this issue covered by the recent NOCOW activity?
Possibly. You need I-pipe 1.7-03 and Xenomai >= v2.3.1 to get the ondemand mapping scheme disabled by the nucleus when your thread starts.
I am not familiar with the purpose and implementation of the NOCOW patch. How would the patch affect my page fault issue?
If the fault you observe is due to an access to some memory after a call to fork or one of its derivative (such as system, popen, etc...), the patch would have copied the whole real-time process address space at fork time instead of setting up COW mappings.
Signature · 1 line
Gilles Chanteperdrix.
Quoted 4 lines · Gilles Chanteperdrix
If the fault you observe is due to an access to some memory after a call to fork or one of its derivative (such as system, popen, etc...), the patch would have copied the whole real-time process address space at fork time instead of setting up COW mappings.
No process forks are involved. Though mlockall() was called from Linux main(), and the page fault was encountered by a separate Xenomai task. Here's the task history:
static constructor allocates buffer from heap
enter main()
call mlockall(), verify return status == 0
buffer is forcibly cleared using memset(buffer, 0, sizeof(buffer)) main calls rt_task_shadow() to create Xenomai startup task startup task spawns Xenomai communications task via rt_task_start() communications task encounters page fault
Let me know if you are able to spot the source of the page faults.
thanks,
Jeff
Quoted 8 lines · Jeff Weber
Quoted 4 lines · Gilles Chanteperdrix
If the fault you observe is due to an access to some memory after a call to fork or one of its derivative (such as system, popen, etc...), the patch would have copied the whole real-time process address space at fork time instead of setting up COW mappings.
No process forks are involved. Though
mlockall()was called from Linuxmain(), and the page fault was encountered by a separate Xenomai task. Here's the task history:
The fork may well be hidden in some library. The best way to know if there is really no fork is to register a callback with pthread_atfork.
Signature · 1 line
Gilles Chanteperdrix.
Quoted 7 lines · Gilles Chanteperdrix
Quoted 6 lines · Jeff Weber
Quoted 4 lines · Gilles Chanteperdrix
If the fault you observe is due to an access to some memory after a call to fork or one of its derivative (such as system, popen, etc...), the patch would have copied the whole real-time process address space at fork time instead of setting up COW mappings.
Quoted 6 lines
Quoted 3 lines
No process forks are involved. Though
mlockall()was called from Linuxmain(), and the page fault was encountered by a separate Xenomai task. Here's the task history:The fork may well be hidden in some library. The best way to know if there is really no fork is to register a callback with
pthread_atfork.
pthread_atfork confirms that there is no fork.
Jeff
Signature · 2 lines
Jeff Weber American Superconductor Corp.
Quoted 8 lines · Jeff Weber
Quoted 7 lines · Gilles Chanteperdrix
Quoted 6 lines · Jeff Weber
Quoted 4 lines · Gilles Chanteperdrix
If the fault you observe is due to an access to some memory after a call to fork or one of its derivative (such as system, popen, etc...), the patch would have copied the whole real-time process address space at fork time instead of setting up COW mappings.
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
No process forks are involved. Though
mlockall()was called from Linuxmain(), and the page fault was encountered by a separate Xenomai task. Here's the task history:The fork may well be hidden in some library. The best way to know if there is really no fork is to register a callback with
pthread_atfork.
pthread_atforkconfirms that there is no fork.
Ok. I am afraid you will have to help us a bit. Could you try Xenomai 2.3.1 in case the nocow patch magically solves your issue ?
If it does not, could you try sizing down your program to a small example that we could run to reproduce the issue ?
If reducing your program is not possible, the only option left is to start debugging this issue. A good starting point would be to put some printks in arch/i386/mm/fault.c to see what kind of page fault is causing the mode switch.
Signature · 1 line
Gilles Chanteperdrix.
Quoted 2 lines · Gilles Chanteperdrix
Ok. I am afraid you will have to help us a bit. Could you try Xenomai 2.3.1 in case the nocow patch magically solves your issue ?
Will do. That may take a little while due to other considerations on this end. I'll get back to you.
Quoted 3 lines
If it does not, could you try sizing down your program to a small example that we could run to reproduce the issue ?
I've already been working on this, with no luck so far.
Quoted 5 lines
If reducing your program is not possible, the only option left is to start debugging this issue. A good starting point would be to put some printks in
arch/i386/mm/fault.cto see what kind of page fault is causing the mode switch.
Let's hope it doesn't come to this. :-)
Jeff
Quoted 13 lines · Gilles Chanteperdrix
Quoted 12 lines · Jeff Weber
Quoted 11 lines · Gilles Chanteperdrix
Quoted 9 lines · Jeff Weber
Quoted 4 lines · Gilles Chanteperdrix
If the fault you observe is due to an access to some memory after a call to fork or one of its derivative (such as system, popen, etc...), the patch would have copied the whole real-time process address space at fork time instead of setting up COW mappings.
No process forks are involved. Though
mlockall()was called from Linuxmain(), and the page fault was encountered by a separate Xenomai task. Here's the task history:
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
The fork may well be hidden in some library. The best way to know if there is really no fork is to register a callback with
pthread_atfork.
pthread_atforkconfirms that there is no fork.Ok. I am afraid you will have to help us a bit. Could you try Xenomai 2.3.1 in case the nocow patch magically solves your issue ?
Indeed, stepping up to:
linux-2.6.20.3
xenomai-2.3.1
ipipe-1.7-03
magically solved my page faults.
thanks!
Jeff
Quoted 21 lines · Jeff Weber
Quoted 13 lines · Gilles Chanteperdrix
Quoted 12 lines · Jeff Weber
Quoted 11 lines · Gilles Chanteperdrix
Quoted 9 lines · Jeff Weber
Quoted 4 lines · Gilles Chanteperdrix
If the fault you observe is due to an access to some memory after a call to fork or one of its derivative (such as system, popen, etc...), the patch would have copied the whole real-time process address space at fork time instead of setting up COW mappings.
No process forks are involved. Though
mlockall()was called from Linuxmain(), and the page fault was encountered by a separate Xenomai task. Here's the task history:Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
The fork may well be hidden in some library. The best way to know if there is really no fork is to register a callback with
pthread_atfork.
pthread_atforkconfirms that there is no fork.Ok. I am afraid you will have to help us a bit. Could you try Xenomai 2.3.1 in case the nocow patch magically solves your issue ?
Quoted 7 lines
Indeed, stepping up to:
linux-2.6.20.3
xenomai-2.3.1
ipipe-1.7-03magically solved my page faults.
Ok, so some memory which was referred to must have been lying in a COWed shared VM page, since what 1.7-03 does is that it eagerly breaks COW for all the virtual memory space available to real-time threads.
In case you really, really, really don't want to upgrade to 2.3.x for product maintenance issues (albeit I would really, really, really recommend it, because there are really, really, really nice improvements there over 2.2.x), I've crafted a quick patch to disable ondemand VM mappings with older Xenomai revs using recent I-pipe patches. IOW, this patch against v2.2.x should allow you to run the latter over I-pipe 1.7-03, and make use of its COW-breaking feature (uncompiled, untested).
asm-generic/hal.h +7 -0
@@ -304,6 +304,13 @@#define PF_EVNOTIFY 0#endif /* !PF_EVNOTIFY */ +#ifdef VM_PINNED +#define rthal_disable_ondemand_mappings (tsk) ipipe_disable_ondemand_mappings(tsk) +#else /* !VM_PINNED */ +/* In case the I-pipe does not allow disabling ondemand mappings. */ +#define rthal_disable_ondemand_mappings (tsk) (0) +#endif /* !VM_PINNED */ +#ifdef CONFIG_KGDB #define rthal_set_foreign_stack (ipd) ipipe_set_foreign_stack(ipd)#define rthal_clear_foreign_stack (ipd) ipipe_clear_foreign_stack(ipd)
nucleus/shadow.c +8 -5
@@ -828,6 +828,14 @@ thread->name, current->pid, xnthread_base_priority(thread)); +#ifdef CONFIG_MMU +if (!(current->mm->def_flags &VM_LOCKED )) +send_sig (SIGXCPU , current,1 ); +else +if ((err =rthal_disable_ondemand_mappings (current))) +return err; +#endif /* CONFIG_MMU */ +/* Switch on propagation of normal kernel events for the bound task. This is basically a per-task event filter which restricts event notifications (e.g. syscalls) to tasks
@@ -836,11 +844,6 @@plain (i.e. non-Xenomai) Linux tasks. */ current->flags |=PF_EVNOTIFY ; -#ifdef CONFIG_MMU -if (!(current->mm->def_flags &VM_LOCKED )) -send_sig (SIGXCPU , current,1 ); -#endif /* CONFIG_MMU */ - current->cap_effective |=CAP_TO_MASK (CAP_IPC_LOCK ) |CAP_TO_MASK (CAP_SYS_RAWIO ) |CAP_TO_MASK (CAP_SYS_NICE );
Signature · 1 line
Philippe.