当前位置:网站首页>Memory introduction
Memory introduction
2022-06-24 13:23:00 【Chen Bucheng I】
One . Memory
Physical memory is also called main memory , Most computers use dynamic random access memory (DRAM). Only the kernel has direct access to physical memory .
Linux The kernel provides each process with an independent virtual address space , And the address space is continuous . such , Processes can easily access memory , More specifically, access to virtual memory .
It can be seen from here that ,32 The kernel space of bit system takes up 1G, At the top , The rest 3G It's user space . and 64 The kernel space and user space of a bit system are both 128T, Occupy the highest and lowest memory space respectively , The rest of the middle is undefined .
When the process is in user mode , Can only access user space memory ; Only after entering kernel state , To access kernel space memory . Although the address space of each process contains the kernel space , But these kernel spaces , In fact, they are all related to the same physical memory . such , After the process switches to kernel mode , You can easily access kernel space memory .
Each process has the entire virtual space available , But physical memory is allocated only when it is actually applied . Allocated physical memory , It's managed by memory mapping . That adds up to the virtual memory of all processes , Much larger than the actual physical memory .
Memory mapping , It's actually mapping the virtual memory address to the physical memory address . To complete the memory mapping , The kernel maintains a page table for each process , Record the mapping relationship between virtual address and physical address , As shown in the figure below :
Page tables are actually stored in CPU Memory management unit for MMU in , such , Under normal circumstances , The processor can go directly through the hardware , Find the memory to access .
When the virtual address accessed by the process cannot be found in the page table , The system will generate a page missing exception , Go into kernel space and allocate physical memory 、 Update process page table , Finally, return to user space , Resume the operation of the process .
Two . Memory footprint
The basic idea of virtual memory is : Program 、 The total size of the data and stack may exceed the size of the available physical memory . The operating system keeps those parts of the program currently in use in main memory , Save the rest on disk . for example , For one 16MB The program , By carefully choosing where to go at each moment 4MB The contents remain in memory , And exchange program fragments between memory and disk when necessary , In this way, the program can be in a 4MB Running on the machine .
The smallest unit of memory is bytes 1M=1024byte( byte ) 1 byte =8bit( The bit ) So the maximum storage value of a byte is 255, Namely 8 individual 1
How many bytes does it take , And interpreter version , System version related . Numbers 4 byte Variable =100 1 Bytes can be stored directly 100 Variable =100( character string ) One character takes one byte Man occupied 2 Byte representation
The variables here , It will occupy memory , But not much , One int Variables of type account for 4 Bytes , A byte is 8 individual bit, Every bit It can only be stored in the 0 or 1
therefore int Type of 4 A total of... Bytes 4*8=32 bit
The biggest expression is 1111111111…..(32 individual 1)
Convert to 10 process ,, Namely int Of a type used in actual calculations 2 Of 32 The next power
If the process is complicated , There are many variables defined , It takes up a lot of memory space
From the memory model , The simplest heap and stack
Some variables are on the stack , Some variables are in the heap . After calculation ( Program end ), Variable destruction , Memory space recycling , So you can see that your memory is down again .
边栏推荐
- Experience of IOS interview strategy - App testing and launching
- LVGL库入门教程 - 颜色和图像
- 实现领域驱动设计 - 使用ABP框架 - 更新操作实体
- Process basic properties
- 几种常见的DoS攻击
- Troubleshooting and optimization of files that cannot be globally searched by ordinary users in easydss video platform customization project
- RAID5 array recovery case tutorial of a company in Shanghai
- Implement Domain Driven Design - use ABP framework - create entities
- 手把手教你用AirtestIDE无线连接手机!
- How does Argo family bucket make Devops easier?
猜你喜欢
I have fundamentally solved the problem of wechat occupying mobile memory
Comparator 排序函数式接口
【概率论期末抱佛脚】概念+公式(不含参数估计)
1、贪吃蛇游戏设计
"Interesting" is the competitiveness of the new era
3. Caller 服务调用 - dapr
Brief introduction to cluster analysis
‘高并发&高性能&高可用服务程序’编写及运维指南
快速了解常用的消息摘要算法,再也不用担心面试官的刨根问底
线程同步的基石AbstractQueuedSynchronizer详解
随机推荐
A hero's note stirred up a thousand waves across 10 countries, and the first-line big factories sent people here- Gwei 2022 Singapore
青藤入选工信部网安中心“2021年数字技术融合创新应用典型解决方案”
Attack Science: DDoS (Part 2)
Who is the fish and who is the bait? Summary of honeypot recognition methods from the perspective of red team
Implement Domain Driven Design - use ABP framework - update operational entities
hands-on-data-analysis 第三单元 模型搭建和评估
The difference between apt and apt get
How can junior middle school developers effectively reduce their own workload?
【数据挖掘】期末复习(样卷题目+少量知识点)
Gateway processing flow of zuul source code analysis
About the hacked database
Cohere、OpenAI、AI21联合发布部署模型的最佳实践准则
Use abp Zero builds a third-party login module (I): Principles
"Interesting" is the competitiveness of the new era
How stupid of me to hire a bunch of programmers who can only "Google"!
Opengauss kernel: simple query execution
How long will it take to open a mobile account? Is online account opening safe?
Perhaps the greatest romance of programmers is to commemorate their dead mother with a software
手机开户后多久才能通过?在线开户安全么?
系统测试主要步骤