当前位置:网站首页>How to understand "page storage management scheme"
How to understand "page storage management scheme"
2022-07-29 03:39:00 【SHolmes1854】
Simply understand the page storage management scheme
Page storage management scheme belongs to a kind of operation of virtual storage . The word "virtual" is a good entry point for us to understand the page storage management scheme . Why is it called virtual storage ? What is virtual ? Is the capacity of the memory .
for instance , Main memory of computer ( Memory module ) Space is limited , Here, it is assumed that the actual physical address is 20 position , That is, the actual physical address space is
B=1MB( Many years ago, it was still possible , Now, at least 4GB 了 ), If the data in memory is Store by block Of , The size of each piece is 4KB, Then the memory module can hold :
Data blocks .
When using ,CPU You can call
Data blocks , But under the virtual storage technology , The virtual address is 24 position , That is, the virtual address space is
B=16MB Under the circumstances ,CPU You will feel that you can call more data blocks , from
Turned into
individual . however In fact, the space capacity of this memory module has not changed , It's always been 1MB. So how does virtual storage technology achieve “ cheated CPU” What about ?
At the actual physical storage level , The program and data are managed by the operating system , First enter the disk , Then the operating system will What is needed for the current operation Transfer into main memory , for CPU Use , The rest will remain on disk .( This sentence comes from Wang daoshu )
To be frank , It's like Xiao Ming opened a bag company , It is claimed that there are ten branches in the province , The total number of employees is 50 people , It claims to have employees at least 500 people , Then Xiao Ming went to deceive investors into investing , Bought a person around investors , Later, investors during the inspection , Go to any branch of Xiaoming to investigate , Xiao Ming will know in advance through this person , Then he took the only 50 All employees are transferred to the branch that the investor will visit , After investigating ten branches , There will be a kind of really at least 500 The illusion of an employee .( Pretend here that this investor is face blind , In real life, such examples are not absent , Just pay attention to those who will be directly contacted and don't be seen repeatedly , Other mass actors are such a group )
/* But virtual memory is the size of space , Not the number of employees */
Page virtual memory , Is to package the data page by page , Instead of packing piece by piece as mentioned before .
For example, according to page virtual memory , The condition in the above example is changed to :
The actual physical address space is
B=1MB, Data in memory is Pack and store by page Of , The size of each page is 4KB, Then the memory module can hold :
Data pages .
The virtual address space is
B=16MB,CPU Will feel The data pages you can call are
individual .
There are many problems in the application of virtual page memory technology , We conquer one by one .
In fact, only 1MB The memory module of space cannot be loaded. The next page size is 4KB Of
A data page . therefore , Only partially loaded , Other data pages are in auxiliary storage ( For example, in the hard disk ) Stay inside , etc. CPU When you need to call a data page , Then put it in , It is also possible that this data page is already inside ,( For example, according to the partial principle of the program, I'm still here ).
problem 1: But how does the computer know CPU Are the data pages to be used now in memory ??
So we naturally think , Set up 1bit Bit to record whether the data page is in memory ./* This bit Scientific name “ Mount bit ”,1 Indicates that it is currently loaded in memory ,0 Indicates that it is not loaded into memory */
problem 2: Let's see the conditions first , Suppose the virtual space of the memory module contains 8 Data pages , The actual space of the memory module can only accommodate 4 Data pages , Because there is still a space to store information ,/* The information currently stored is : Set up 1bit Bit to record whether the data page is in memory .*/ So in the end, I can only save 3 Data pages .




This figure According to the CPU The data page it gets is not the one it wants , This is encountered in virtual page storage problem 2
How to solve it ? Add “CPU Desired data page ” And “ In fact, the location of the page in memory ” Correspondence of :
therefore , The information table becomes like this :( The colors inside are just for more intuitive display of different data pages , One of them is gray ! Look for the )
CPU Desired data page | Color | Is it in memory ( Whether it is loaded ) | In fact, the location of the page in memory | Color |
The first 0 page |
| be not in |
|
|
The first 1 page |
| be not in |
|
|
The first 2 page |
| stay | The first 1 page |
|
The first 3 page |
| be not in |
|
|
The first 4 page |
| stay | The first 2 page |
|
The first 5 page |
| be not in |
|
|
The first 6 page |
| stay | The first 0 page |
|
The first 7 page |
| be not in |
|
|
So this time it's right 
surface 1 Medium “CPU Desired data page ” And “ In fact, the location of the page in memory ” Corresponding to the terms in virtual page storage technology “ Virtual page number ” and “ Real page number ” And tables 1 My scientific name is A page table .
“CPU Desired data page ” == “ Virtual page number ” == “ Logical page number ”
“ In fact, the location of the page in memory ” == “ Real page number ” == “ Page frame number ”
therefore CPU Want data pages , When running to access the memory module , You need to look up the page table first , If it hits ( The page table tells CPU That data page is in memory ) Just follow “ Real page number ” Go to the memory module to find ; If it doesn't hit , Page replacement and page table modification are also required .
In fact, I should have understood the principle here . Don't read the following .
Look at a problem of kingcraft :
A computer memory is byte addressable , fictitious ( Logic ) The address space is 16MB, Main memory ( Physics ) The address space is 1MB, Page size is 4KB;
ask : There are several digits in the virtual address , Which digits represent the virtual page number ? There are several digits in the physical address , Which digits indicate the page frame number ( Physical page number )?
The condition that information is stored in binary and addressed by bytes in a computer , hear :/* If you can't understand byte addressing, please see another article of mine , The one about pigs */
To express 16MB Virtual address space for , need 24 To said ,
=16M.
Because the page size is 4KB, So there is
Data pages , To represent so many data pages , need 12 individual bit position .
But to show 1MB The physical address space of , need 20 To said ,
=1M.
Because the page size is 4KB, So there are actually memory modules
A page .( These page spaces not only store data pages , It is also used to store page tables ), To represent so many pages , need 8 individual bit position
Virtual addresses are shared 24 position , front 12 Bits are used to indicate the virtual page number , Physical addresses are shared 20 position , front 8 Bit indicates the page frame number ( Physical page number )

Fully understand : What is the address on the page ?
Let's start with an example : Set up : One room has 8 A fence 8 Pigs , This fence is made to order , So in order to make the best use of everything , A room must fit 8 Pigs , Then there is a number on each pig ,0 or 1, Now? , I have a
A room , How many pigs are there in total ?
Pigs , But in this world , All rooms are required to be decorated 8 Pigs , therefore , When people communicate, they don't say how many pigs I have , But how many rooms do I have .
Similarly , In the field of computer , People don't say how many I have bit A data , But how many I have Byte( byte ) The data of .
So when you find a data page , To read pages “ A room ” Information on pigs , You also need a message : That is, the address on the page , It's the room number . When the page size is 4KB When , It means there is
Pigs , namely
bit data ; But we press 8 Address a pig ( Address by byte ) therefore , We said there was 4KB data , Then we need to read the page “ A room ” Information on pigs , Page size is 4KB, Description yes 4K A room , To express 4K A room , namely 4K=
, need 12 individual bit position , So the address in the page needs 12bit To said .
The situation of this page is similar to the following figure :

I hope that helps . Please put forward the deficiencies . Reprint please indicate the source !
边栏推荐
- Mathematical modeling -- analytic hierarchy process model
- Sunflower senior product director technology sharing: "how to apply national remote control" in AD domain environment
- Why do programmers so "dislike" the trunk development mode?
- C obtains JSON format data asynchronously from the web address
- 深入C语言(3)—— C的输入输出流
- Instance setup flask service (simple version)
- In depth C language (2) -- definition and use of structure
- 暴力递归到动态规划 01 (机器人移动)
- How fast does it take to implement a super simple programming language?
- Reproduce 20 character short domain name bypass and XSS related knowledge points
猜你喜欢

Why BGP server is used in sunflower remote control? Automatic optimal route and high-speed transmission across operators

Instance setup flask service (simple version)

深入C语言(1)——操作符与表达式

Matlab learning -- structured programs and user-defined functions

Deep into C language (3) -- input and output stream of C

最新二开版漫画小说听书三合一完整源码/整合免签接口/搭建教程/带采集接口

for_each用法示例

向日葵远程控制为何采用BGP服务器?自动最优路线、跨运营商高速传输

NXP i.mx8mp-deepviewrt

Rdkit: introduce smiles code, smart code and Morgan fingerprint (ECFP)
随机推荐
CUDA GDB prompt: /tmp/tmpxft**** cudafe1.stub. c: No such file or directory.
Android view system and custom view Series 1: (kotlin version)
向日葵远程控制为何采用BGP服务器?自动最优路线、跨运营商高速传输
Asynchronous callback future mode of concurrent mode
ROS - create workspace
Set functions in kotlin
How fast does it take to implement a super simple language
深入C语言(4)——switch的定义与使用
Kubernetes-1.24.x feature
Arm architecture and neural network
Regular expression bypasses WAF
The latest second edition of comic novels, listening to books, three in one, complete source code / integrated visa free interface / building tutorials / with acquisition interface
深入C语言(2)——结构的定义与使用
Tonight at 7:30 | is the AI world in the eyes of Lianjie, Jiangmen, Baidu and country garden venture capital continue to be advanced or return to the essence of business
RHCE's at, crontab's basic operations, the Chrony service, symmetric encryption and asymmetric encryption
Bingbing learning notes: operator overloading -- implementation of date class
VISO fast rendering convolution block
后缀自动机(sam)板子 from jly
"The programming is not standardized, and my colleagues are in tears!"
What have I learned from 200 machine learning tools?