A journey caused by the page fault

Overview

First of all, what is the page, which is for the memory of it, modern operating system memory is divided into many pages (logically), the default page size is 4KB (Linux). Operating system when running a program, not a one-time page will be required for the program are loaded into memory (no need).
So when the operating system to run programs that use the page is not loaded into physical memory when triggered from the CPU of a missing page error, the operating system to catch this error, and then loaded into the corresponding physical memory pages.

Outlined above involves several concepts: pages, physical memory, interrupts.

Page and section

Except that the memory is divided into pages, in fact, may be divided into sections, a section of memory to store all data and instructions required for the program. In this case it does not produce missing data or instructions are. But it raises a new problem: memory fragmentation and memory. As shown below:

Of course there is a solution, that is, memory swapping , the python program occupies 256M written to disk first, and then read back into memory from the hard disk, but is written from then occupied 512M. So that we can continuously 256M space to load a new program X. It seems perfect, no page
appearance, and in fact we all know, memory is compared to the hard disk access speed, but several orders of magnitude slower. Frequent disk read and write performance is certainly not go up, so there are only pages.

Exceptions and interrupts

The program is not only simple to execute instructions, and more also needs to deal with external input and output. On the other hand, the program is running, will encounter a variety of unusual circumstances, such as division by zero, overflow, even we ourselves can make an exception recruitment program

Unusual, in fact, the process is a combination of hardware and software together, abnormal former life: generation and capture, is done at the hardware level. But after half
life, that is handle the exception, in fact, is done by software

The computer will provide every possible anomalies, allocating an exception code. When an exception occurs, the CPU is usually detected by a special signal. These signals, generally one event (Event) called occurred. Get the exception code, CPU triggers exception handling process. Also relates to exception handling context switching.

Abnormal classification

  • Interrupt
    program execution to half, was interrupted, usually asynchronous.
  • Trap
    programmer "deliberately" exception initiative triggered. When the program instructions to this position, which fell into this trap. Then, corresponding exception handler will handle prey this "trap" of them. If the instruction time, the application calls by reading the file system creation process.
  • Failure
    to distinguish it from the trap and that failure is not usually intentionally triggered. 0 If, in addition, add overflow. Fault and interrupt, trap there is an important difference is that, after the failure exception processing is completed, the processing of the current instruction still come back, instead of going to the next instruction.
  • Discontinued
    when no exception handler can handle the current exception, the program exits the current suspension of execution

Physical memory and virtual memory

Guess you like

Origin www.cnblogs.com/yeni/p/11712590.html