OSDev.org

The Place to Start for Operating System Developers
It is currently Sun Sep 15, 2019 8:18 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Should Kernel Memory be swapped out?
PostPosted: Fri Aug 30, 2019 11:00 am 
Offline

Joined: Sun Aug 11, 2019 5:36 pm
Posts: 2
Assume: 32 bit machine. Linear address is divided into 3G user, 1G kernel

As far as from what I read online, Linux is designed in a way such the kernel memory cannot be swapped out. If I understand correctly, not only the code and essential data (e.g. page struct) cannot be swapped out, but the buffer allocated in the kernel space cannot be swapped out.

I understand it is necessary to not swap out kernel code and essential data like page struct, but why can't we swap out allocated buffer temporarily and once kernel accessed the area, let the page fault handler swap back the buffer?

Is any issues with swapping out kernel memory like swapping out pages from user process that I overlook?


Top
 Profile  
 
 Post subject: Re: Should Kernel Memory be swapped out?
PostPosted: Sat Aug 31, 2019 1:46 am 
Online
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1634
The only issue is that you have to make sure you don't swap out things that you won't be able to swap back in. (For example, the drivers for the storage holding your swap file.)

In the Linux case, they probably decided the potential benefits weren't worth the amount of work it would take. Computers have a lot of RAM nowadays.


Top
 Profile  
 
 Post subject: Re: Should Kernel Memory be swapped out?
PostPosted: Sat Aug 31, 2019 4:03 am 
Offline
Member
Member

Joined: Thu May 17, 2007 1:27 pm
Posts: 607
Other than code complexity, there is no reason to disallow swapping of kernel pages.

However, the code complexity is easy to underestimate. If you allow swapping out kernel pages, you need to be able to handle page faults whenever you access a page that might be swapped out. This might lead to rather complex issues. The most obvious problem is locking: the page fault handler will need to take a lock on the kernel address space. The FS will be invoked and it will also take some locks. Finally, the disk driver will be called and take locks. If your page fault happens with any of those locks already taken, you get a deadlock. For example, imagine that you have a page that only contains simple statistics of a process, such as the number of I/O operations that the process triggered. Swapping out this page will already be a bug because you will need to take a lock on the statistics page to access it but, on the other hand, the disk driver will try to take this lock to update the page.

_________________
managarm: A microkernel-based OS that is capable of running a Wayland desktop


Top
 Profile  
 
 Post subject: Re: Should Kernel Memory be swapped out?
PostPosted: Sat Aug 31, 2019 3:35 pm 
Offline
Member
Member
User avatar

Joined: Fri Feb 17, 2017 4:01 pm
Posts: 386
Location: Ukraine, Bachmut
Windows is mostly pageable. making the whole kernel nonpageable is lame. your question is valid - it's a good design to make your OS as pageable as possible. this example is a good one, demonstrating, that looking at (only) linux may make poor service for your knowledge, since you may believe some mediocre approach is the only one possible. it's good that you questioned it, the other time it might slip out of eye, or how it's freaking said in english. :D

_________________
future big goal: ANT - NT-like OS for mips, arm and x86.
current smaller goal: efify - UEFI for a couple of boards (mips and arm).


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Octocontrabass and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group