1
$\begingroup$

Why is paging done only for user code (user space)? I know that the basic intuition behind paging is for managing larger logical address space in smaller physical main memory space. Won't the kernel size also be large? If the kernel code is large enough and the RAM size is small, then how is it managed? Please clarify.

$\endgroup$
1
  • 1
    $\begingroup$ Kernels are not large. $\endgroup$ – Yuval Filmus Aug 28 '20 at 6:19
2
$\begingroup$

Other than the fact that kernels tend to be small, as Yuval points out, you should also consider that they are often not relocatable code (in fact, address binding for kernels is done at compile-time) and so the memory they are allocated could not be moved or swapped-out in any case, not only for paging. Obviously there are also performance-related concerns, and one should consider handling exceptional cases too, like the code responsible for paging being swapped out.

Usually, memory limitations in operating systems are handled in different ways other than paging. For monolithic kernels, this means offering a loadable module system, while for microkernels the problem might not even apply, since their footprint on main memory is usually much lower than monolithic kernels (system services in microkernels are implemented as user-level processes).


Last but not least, enabling paging on kernel memory would defy one of its main definitions, being "[that] part of the operating system that is always resident in memory"1 ;-).

$\endgroup$
1
  • 1
    $\begingroup$ The code responsible for paging being swapped out is a bigger deal than you make it out. It's not just the memory management code. It's also the disk drivers. And the filesystem drivers, because you can swap to a file. And the networking code, because you can swap to a network drive. And there's other code that shouldn't be swapped out, like the handling of the emergency attention key (and therefore the keyboard driver, and drivers for any bus that may host an input peripheral). This doesn't leave all that much kernel code that can be swapped out. $\endgroup$ – Gilles 'SO- stop being evil' Aug 28 '20 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.