Why? Why SetPageReserved is needed when map a kernel space to user space?
Linux - KernelThis forum is for all discussion relating to the Linux kernel.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Why? Why SetPageReserved is needed when map a kernel space to user space?
I am confused by this question for long time, no clear answer about this question when google, the only anser is SetPageReserved is used to prevent the page mapped into user space swapping out!!
But the page is also mapped by a kernel virtual address, how can it be swapped out? In other word, if I don't use SetPageReserved when I remap a kernel virtual address into user space, what's the bad result????
Q: Why? Why SetPageReserved is needed when map a kernel space to user space?
A: Why? Why do you think that's necessarily the case?
PS:
If you're not already familiar with them, Google for the kernel APIs copy_from_user()/copy_to_user(), and the user-space API "mmap()". In general, the kernel isn't allowed to access user-space memory directly.
A: Why? Why do you think that's necessarily the case?
PS:
If you're not already familiar with them, Google for the kernel APIs copy_from_user()/copy_to_user(), and the user-space API "mmap()". In general, the kernel isn't allowed to access user-space memory directly.
I know the user space cant access the kernel memory directly, but my question is when allocate a kernel virtual memory, for instance, __get_free_pages() and map this virtual space to user space by using remap_pfn_range(), but before that, some drivers code in Linux kernel will call SetPageReserved at the VA from __get_from_pages, why SetPageReserved is needed in this case?
User space don't know that these virtual address is from kernel space. They will be swapped out when they think it is necessary.
The question is although the user space doesn't know these address comes from kernel space, but I've mentioned that these virtual address is comes from __get_free_pages, so even the user space mapped to those pages, the kswapd still haven't chance to swap it out. Hence, SetPageReserved is necessary or not for this case??
When user space do mmap, it will map kernel memory to user space normally and call SetPageReserved. For your case, I don't see any different from normal case.
When user space do mmap, it will map kernel memory to user space normally and call SetPageReserved. For your case, I don't see any different from normal case.
The KEY POINT in my question is why SetpageReserved is needed?
As noted, this bit stops a "race condition" that could otherwise exist between this code and the swapper. If two pieces of code (the user, and the kernel) are relying upon a particular physical-page, that page is now a shared resource between the two for the duration, and it is necessary to guarantee that the page will not be "stolen" in the meantime. The bit indicates among other things that this page is not a candidate for stealing.
Though the pages are reserved via a kernel driver, it is meant to be accessed via user space. As a result, the PTE (page table entries) do not know if the pfn belongs to user space or kernel space (even though they are allocated via kernel driver).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.