Tuesday, November 08, 2005

Using dtrace and mdb to examine virtual memory

here is a short example using
dtrace and mdb to examine page faults and process address spaces.
This will be used in a workshop being given to professors teaching operating systems
within China. The workshop will cover Solaris internals using the opensolaris source code
and tools such as dtrace, mdb, and kmdb.

1 comment:

Robin said...

Hi Max,
The article really helps to understand the virtual memory system.Thank you for sharing that.
And I met a problem with your script that as "pagefault" is the routine called to handle all page faults,sometimes I got into other code paths(anon allocation) instead of the one showed in your article.
So based on your script,I wrote a script using speculative tracing which only covers the code path via ufs_getpage,in order to capture the disired code path.Please correct me if I made mistakes.

Zhijun
===================================
#!/usr/sbin/dtrace -s

#pragma D option flowindent

pagefault:entry
/execname == $$1/
{
self->want = 0;
self->spec = speculation();
speculate(self->spec);

printf("fault occurred on address = %p\n", args[0]);
/*
printf("self->spec=%d\n", self->spec);
printf("curthread=%p\n", curthread);
*/
}

pagefault:return
/self->spec/
{
speculate(self->spec);
}

pagefault:return
/self->spec && self->want/
{
commit(self->spec);
self->exit=1;
}

pagefault:return
/self->spec && self->want && self->exit/
{
exit(0);
}

pagefault:return
/self->spec && self->want==0 /
{
discard(self->spec);
self->spec=0;
}

ufs_getpage:entry
/self->spec/
{
self->want=1;
}

entry
/self->spec/
{
speculate(self->spec);
}

return
/self->spec/
{
speculate(self->spec);
}