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

2

10

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!

Usm answered 12/8, 2013 at 23:0 Comment(5)
Is this question in the context of any particular device-driver?Sd
The Linux kernel is providing virtual memory to application, but does not use it for itself. So, NO!Binary
@TheCodeArtist: No, general question applicable to any driver.Usm
@BasileStarynkevitch: I know, but the question is "why?". The kernel can fetch pages from secondary storage when it hits a fault itself and return to whatever it was doing after fixing up the page fault.Usm
I think because it would make the kernel much more complex to code, with few overall gain. It is simply not worth the effort. (IIRC, in the 1990s some Unix did that: SunOS or AIX...)Binary
P
6

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.

Pulpiteer answered 12/8, 2013 at 23:0 Comment(1)
Kernel oops: Memory violations in the kernel result in an oops, which is a major kernel error.(Linux Kernel Development, 3rd edition)Incursion
I
2

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

Iolanthe answered 8/12, 2013 at 23:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.