On Friday 16 December 2005 02:27, Nick Piggin wrote:
vm_insert_page is indeed the right interface for mapping these pages
into userspace.
Ok, that's what I intended to do.
You do not have to worry about pages being swapped out, and you shouldn't
need to set any unusual vma or page flags. kswapd only walks the lru lists,
and it won't even look at any other pages.
I'd still like to understand how things work (I'm one of those programmers who don't like to code without understanding).
I think I understand how disk buffers or non-shared pages mapped by a regular file can be reclaimed, but I have trouble with anonymous pages and shared pages.
First of all, I haven't been to find a definition of an anonymous page. I understand it as a page of memory not backed by a file (pages allocated by vmalloc for instance). If this is wrong, what I'm about to say if probably very wrong as well.
Are anonymous pages ever added to the LRU active list ? I suppose they are not, which is why they are not reclaimed.
How does the kernel handle shared pages, (if for instance two processes map a regular file with MAP_SHARED) ? They can't be reclaimed before all processes which map them have had their PTEs modified. Is this where reverse mapping comes into play ?
Finally, how are devices which map anonymous kernel memory to user space handled ? When a page is inserted in a process VMA using vm_insert_page, it becomes shared between the kernel and user space. Does the kernel see the page as a regular device backed page, and put it in the LRU active list ? You
said I shouldn't need to set any unusual VMA or page flags. What's the exact purpose of VM_RESERVED and VM_IO then ? And when should they be set ?
Hope I'm not bothering you too much with all those questions. I don't feel at ease when developping kernel code if I don't have at least a basic understanding of what I'm doing.