Vincenzo Mallozzi wrote:
Hi,
from the kernel point of view, how can I understand if
a memory page is locked?
I'll explain better my question by means of an
example.
Even with the example I could not really get what you are asking. But
let me try....
I've two or more threads that, obviously, share some
memory regions (so some memory pages). It can happens
that one of these threads locks a memory page. Is
I assume you mean kernel threads. Or did you mean two threads of execution?
there a way to view that this page is locked by
looking at the struct page fields of this memory page?
If the page is locked in memory for some Disk I/O, you can check the
status by testing using page->flags for PG_locked.
from page-flags.h,
/*...
* During disk I/O, PG_locked is used. This bit is set before I/O and
* reset when I/O completes. page_waitqueue(page) is a wait queue of all
tasks
* waiting for the I/O on this page to complete.
*/
Is there a way to understand if another thread is
trying to access to this locked page? If so, it occurs
page fault in this case? with wath error value?
No. page fault occurs when there is no page in memory corresponding to
the address one thread of execution tries to access. There are a number
of reasons why the page is not in memory and page fault handler handles
these scenarios.
Kernel threads would not cause page fault normally except vmalloc() cases.
If you intend to use one page as a shared resource, you will have to
implement your own locking mechanism for serializing the access I think
HTH,
Om
--
The worst thing one can do is not to try, to be aware of what one wants
and not give in to it, to spend years in silent hurt wondering if
something could have materialized -- and never knowing.
-- David Viscott
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/