關於內核中的內存都不分頁

這條真的很難理解,對於我這種初學者來說……

下面是我查到的很有名的兩句話,解釋並介紹了關於內核內存問題,真的很贊!!

1、Operating systems have memory areas that are pinned (never swapped to secondary storage). For example, interrupt mechanisms rely on an array of pointers to their handlers, such as I/O completion and page fault. If the pages containing these pointers or the code that they invoke were pageable, interrupt-handling would become far more complex and time-consuming, particularly in the case of page fault interrupts. Hence, some part of the page table structures is not pageable.

Some pages may be pinned for short periods of time, others may be pinned for long periods of time, and still others may need to be permanently pinned. For example:

The paging supervisor code and drivers for secondary storage devices on which pages reside must be permanently pinned, as otherwise paging wouldn't even work because the necessary code wouldn't be available.
Timing-dependent components may be pinned to avoid variable paging delays.
Data buffers that are accessed directly by peripheral devices that use direct memory access or I/O channels must reside in pinned pages while the I/O operation is in progress because such devices and the buses to which they are attached expect to find data buffers located at physical memory addresses; regardless of whether the bus has a memory management unit for I/O, transfers cannot be stopped if a page fault occurs and then restarted when the page fault has been processed.


2、You might have heard about 3G/1G split. This 1GB is the virtual address of the kernel. And whenever kernel try to access any address in this range(for ARM architecture it is  0xC0000000 - 0xFFFFFFFF),there should not be any page fault. That means MMU should be able to convert your virtual address to physical. This 1GB contains your IO address, RAM address.

Paging is a mechanism OS uses to pull the data(in pagesizes) to and from between system RAM and secondary memory.Kernel memory is not pageable. This means memory allocated for the kernel will not be pagged out. If you try to access any memory in kernel with out creating page tables(this can be done by ioremap) you will end up in OOPS. The main reason of kernel not being swapable or pageable is as follows.

Think this way. What will happen if we have paged out that portion of the logic which decides what to do when a page fault occurs? Who will
take care of the page fault then?

But if a user program hit a page fault(ie accessed address is not in main memory), kernel will load the page from secondary memory if it is
a valid address. And if the address accesses is illegal, kernel kill the user application(Segmentation fault).


內核佔用的內存都不分頁,實際上是意味着分配給內核的內存不能夠被換出,書中後面一句話也解釋了這種觀點,“也就是說,你每用掉一個字節,物理內存就減少一個字節”。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章