Kernel monitor, the return
Andrey Simonenko
simon at comsys.ntu-kpi.kiev.ua
Tue Feb 15 05:21:13 PST 2005
On Mon, Feb 14, 2005 at 10:24:50PM -0800, Ashwin Chandra wrote:
> In trying to create a simple kernel thread that prints out all
> the processes data and stack size, i still get a panic fault
> (vm_fault on no entry) at the printf statement...ive narrowed
> it down to the ru_idrss variable that is causing the problem,
Definitely ru_idrss cannot cause any error, may be you made
such desition, because arguments are pushed to the stack
in the reverse order. p->p_stats pointer causes the error.
> im not sure why
(I think that) If some process is not running, then you cannot
use p->p_stats without additional checks for memory p->p_stats
points to, since p->p_stats points to u_stats in struct user{},
which can be swapped out if a process is not running.
Actually you can read this in the comment before struct user{}
in /sys/sys/user.h.
>. I thought maybe I was not locking properly or
> obseriving correct mutexes, but I have tried everything.
You'll get an error at some time, because of incorrect usage
(really not usage) of locks.
> If anyone
> knows why the fault is occurring at the printf, please let me know. =)
Following code works on my system:
----
sx_slock(&allproc_lock);
FOREACH_PROC_IN_SYSTEM(p) {
mtx_lock_spin(&sched_lock);
PROC_LOCK(p);
printf("proc %ld:", (long)p->p_pid);
if ((p->p_sflag & PS_INMEM) && p->p_stats != NULL)
printf(" ru_isrss %ld, rui_idrss %ld\n", p->p_stats->p_ru.ru_isrss, p->p_stats->p_ru.ru_idrss);
else {
if (!(p->p_sflag & PS_INMEM))
printf(" !PS_INMEM");
if (p->p_stats == NULL)
printf(" p_stats == NULL");
}
printf("\n");
PROC_UNLOCK(p);
mtx_unlock(&sched_lock);
}
sx_sunlock(&allproc_lock);
----
Follow this code:
vm_glue.c:vm_proc_new() allocates memory for u-area with MAP_NOFAULT
vm_glue.c:vm_proc_swapout() calls pmap_qremove() for u-area
vm_glue.c:vm_proc_swapin() fills u-area and calls pmap_qenter() for it
vm_fault.c:vm_failt() panics if a page fault occurred for vm_map_entry
which has MAP_ENTRY_NOFAULT, you got this panic I think.
ps: not related to topic, but I think that ru_idrss and ru_isrss are
not something you need, according to first lines of your letter.
More information about the freebsd-hackers
mailing list