Question

If the answer to the question is NO, why is it not a good idea to do this? Can the kernel not handle and fix page faults that occur in kernel mode? Does the answer change if the code that uses pageable memory only executes as part of the bottom-half of an interrupt?

Thanks!

Was it helpful?

Solution

Can the Linux kernel use pageable (swappable) memory for its own buffers?

No. "Normally, page faults incurred when running in kernel mode will cause a kernel oops. There are exceptions, though; the functions which copy data between user and kernel space are one example." (Source: https://lwn.net/Articles/270339/)

why is it not a good idea to do this?

In user space, you can simply suspend the user process and move on without causing any problems. But in kernel space, your thread may have taken many locks, or disabled interrupts. If you have to stop to take a page fault, then you have a choice:

1) Let the entire system grind to a halt for millions of instructions while that page is loaded from disk. This would lead to terrible performance.

2) Add complexity so that at any point, the locks/interrupts can be "un-wound", allowing other kernel threads to proceed.

Can the kernel not handle and fix page faults that occur in kernel mode?

Yes you can have faults, but only special cases. I.e. you're not allowed to have locks when calling "get_user_page". This lets the kernel 'switch away' from the task as if it were in user mode. If you had turned off interrupts or taken out locks, the rest of the kernel couldn't run.

Does the answer change if the code that uses pageable memory only executes as part of the bottom-half of an interrupt?

No.

The other half of the question is "what do you gain by allowing the kernel to be paged out"? Generally, the kernel memory is only a tiny fraction of overall memory.

OTHER TIPS

the kernel memory cannot be swappable and the only kernel memory which generate page faults is vmalloc memory

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top