views:

95

answers:

3

Does OS kernel use Virtual memory or Can some part of the OS kernel reside in Hard Disk?

A: 

Which OS Kernel?

Some OS Kernels use Virtual Memory, some don't. Many modern Operating Systems don't even have Virtual Memory anymore. (VM is only required for C, C++ or similar pointer-unsafe languages, but the majority of languages and platforms in use today are pointer-safe (e.g. JavaScript, Python, Ruby, PHP, Perl, Java, CLI minus unsafe), so there's really no need for VM anymore.)

Jörg W Mittag
Whether a particular language has or provides pointers and whether the OS has/uses virtual memory are two completely different concepts.
Emil
+1  A: 

"Using virtual memory" is kind of a vague statement. Broadly interpreted, the answer is yes. Virtual memory is a fundamental part of operating systems for protecting one process from another and giving processes the illusion that they have the computer's entire memory to themselves. The Wikipedia article on virtual memory is a good reference for how this works. (Although to be fair, Linux can be configured without virtual memory, and there are other custom or real-time systems that don't use it.)

Now, if you're asking the more detailed question of whether an operating system will page out memory that holds kernel data structures, I can only answer that the Linux kernel doesn't. Memory is large enough these days the extra memory gained by paging out kernel data structures doesn't justify the added complexity or the cost of a page fault.

Karmastan
A: 

NT kernels and device drivers use virtual memory for data structures and objects that can be safely paged out to storage. For example, a driver can request virtual memory as a usermode program does.

However, the kernel has data and code that: 1) must be kept always in memory for efficiency reasons 2) must be kept in memory because a page fault cannot be serviced. A typical example is entering ISRs (interrupt service routine) (such as the page fault handling code itself). Code and data of this type is kept on physical memory always, and it's called nonpaged pool on NT kernels.

The latter does not means that nonpaged memory addresses are referenced directly. They are always translated to physical addresses (and viceversa) by the kernel memory manager.

I think (i listen for corrections) the only physical addresses used without virtual mapping is the first 1MB when the system boots up (in WinNT, the NTLDR / NTDETECT.COM phase until protected mode is activated).

Hernán