Skip to contentSkip to conversation

question on memory map cleanup stuff

DISCUSSION Chris Friesen 2 participants 5 messages Oct 18, 2004 – Oct 19, 2004

lore
Share & tools
lore
#0 lore raw

I've got a small feature that maps a page of kernel memory to userspace via a syscall, then uses that page for various things.

Currently, I'm marking the page reserved, then exporting it via remap_page_range(). This means that I need to clean up my mapping whenever the memory map is destroyed (process death, exec(), daemonize, etc.).

It appears that I should be able to put my cleanup code in exit_mmap(). Since the cleanup code calls do_munmap() on the address, I would want to call it before taking mm->page_table_lock, correct?

Also, normally I would hold mm->mmap_sem before calling do_munmap(). Would I still need this if I'm calling it from exit_mmap()? Presumably nobody else can get at it anymore...

Thanks,

Chris

#1 lore raw
Quoted 11 lines · Chris Friesen

I've got a small feature that maps a page of kernel memory to userspace via a syscall, then uses that page for various things.
Currently, I'm marking the page reserved, then exporting it via remap_page_range(). This means that I need to clean up my mapping whenever the memory map is destroyed (process death, exec(), daemonize, etc.). It appears that I should be able to put my cleanup code in exit_mmap(). Since the cleanup code calls do_munmap() on the address, I would want to call it before taking mm->page_table_lock, correct?
Also, normally I would hold mm->mmap_sem before calling do_munmap(). Would I still need this if I'm calling it from exit_mmap()? Presumably nobody else can get at it anymore...

vma->vm_ops->close() often suffices for such without disturbing the core.

-- wli

#2 lore raw
Quoted 1 line · William Lee Irwin III

vma->vm_ops->close() often suffices for such without disturbing the core.

Ah. That looks promising.

Thanks.

Chris

#3 lore raw
In reply to William Lee Irwin III
Quoted 6 lines · William Lee Irwin III
Quoted 2 lines · Chris Friesen

I've got a small feature that maps a page of kernel memory to userspace via a syscall, then uses that page for various things.
Currently, I'm marking the page reserved, then exporting it via remap_page_range(). This means that I need to clean up my mapping whenever the memory map is destroyed (process death, exec(), daemonize, etc.).

vma->vm_ops->close() often suffices for such without disturbing the core.

I'm running into a problem.

At the time of close(), I need to figure out which page to unreserve and free. However, when I call

follow_page(vma->vm_mm, vma->vm_start, 0);

it returns zero. How do I go from vma to page?

Chris

#4 lore raw
Quoted 1 line · William Lee Irwin III
Quoted 1 line

vma->vm_ops->close() often suffices for such without disturbing the core.

Quoted 5 lines · Chris Friesen

I'm running into a problem.
At the time of close(), I need to figure out which page to unreserve and free. However, when I call
follow_page(vma->vm_mm, vma->vm_start, 0);
it returns zero. How do I go from vma to page?

You generally need to keep track of this yourself, as during ->close() the pagetables have already been destroyed. linear_page_index() can tell you the offset into the object the vma maps, but ultimately, you have to track the pages yourself. vma->vm_private_data can be used to attach various accounting structures to the vma.

-- wli