zoukankan      html  css  js  c++  java
  • 内核中的内存都不分页

    今天看《linux内核设计与实现》,2.4.3节中有这么一句话:“内核中的内存都不分页”。


    说说我对这句话的理解:

    内存分页机制是为普通进程设计的,每一个普通进程的内存空间都被划分为特定大小的页,如此一来,在某一个特定的时刻,该进程按需可以调进另一个内存页,而把长时间没有使用的页换出。内核与其它普通进程一样,也是一个进程,但却与其它普通进程不同,它可以直接操作硬件,并且它也控制着分页机制以及内存页换入换出的替换算法。因此,对内核占用的内存分页没有意义,倘若,对内核占用的内存进行分页,而又将控制分页机制和替换算法的代码的页换出之后,分页机制和替换算法就会失控。


    在网上google了一下大牛们的理解,有两条说的很靠谱:


    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).


    内核占用的内存都不分页,实际上是意味着分配给内核的内存不能够被换出,书中后面一句话也解释了这种观点,“也就是说,你每用掉一个字节,物理内存就减少一个字节”。

  • 相关阅读:
    超级干货;Python优化之使用pandas读取和训练千万级数据
    「git」mac下git提交github代码
    「Linux+Django」uwsgi服务启动(start)停止(stop)重新装载(reload)
    「Linux+Django」Django+CentOs7+uwsgi+nginx部署网站记录
    「Linux」centos7安装mysql
    「Linux」centos7安装使用rar
    「Linux」centos7安装uWSGI
    「Linux」centos7更新python3.6后yum报错问题
    「Linux」centos7安装python
    「Linux」VMware安装centos7(一)
  • 原文地址:https://www.cnblogs.com/james1207/p/3278424.html
Copyright © 2011-2022 走看看