Re: get_user_pages() and shared memory question

From: Timur Tabi
Date: Tue Jun 21 2005 - 13:23:45 EST

Hugh Dickins wrote:

It depends on what you mean by allocate and deallocate. If the second
process is attaching the same shared memory segment as the first process
had attached, then yes, its buffer will contain those very pages which
the driver erroneously failed to release.

No, I'm talking about when the first process completely destroys the shared memory segment so that it no longer exists. No processes are attached to it, and any attempt to attach to it results in an error, because it doesn't exist.

In this case, when a process creates a new memory segment, I just want to know whether the pages with a non-zero refcount (because of the get_user_pages() call) can ever be used in a new shared memory segment.

I'm assuming the answer is no, because that would defeat the purpose of refcount (right?). I've been looking at the code and reading books on the VM, but I get lost easily. It appears that the function which allocates a page is shmem_alloc_page(), which calls alloc_page() to do the actual work. If that's correct, is it possible for alloc_page() to return a page that has been previously "claimed" by get_user_pages()? I'm looking at __alloc_pages(), and I don't see any calls to page_count(), so I guess there's some other mechanism (either in get_user_pages() or in the way the VM works) that prevents this possibility. However, I'm getting dangerously close to my limit of understanding the Linux VM.

Thanks for replying to my message. I really appreciate the help in understanding the Linux VM.

Timur Tabi
Staff Software Engineer

One thing a Southern boy will never say is,
"I don't think duct tape will fix it."
-- Ed Smylie, NASA engineer for Apollo 13
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at