当前位置:网站首页>The question is: can you successfully apply for 8g memory on a machine with 4GB physical memory?
The question is: can you successfully apply for 8g memory on a machine with 4GB physical memory?
2022-07-22 05:56:00 【InfoQ】

Text
- If there is , Just allocate physical memory directly , And establish the mapping relationship between virtual memory and physical memory .
- If there is no free physical memory , Then the kernel will begin to reclaim memory , If the memory recycling work is finished , The free physical memory is still unable to meet the physical memory application , Then the kernel will trigger the last big move OOM (Out of Memory) Mechanism .

- 32 The kernel space of bit system takes up 1G, At the top , The rest 3G It's user space ;
- 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 .

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
int main() {
int ret;
char* addr[4];
printf(" Use cat /proc/%d/maps View memory allocation \n",getpid());
size_t s = 1024 * 1024 * 1024;
int i = 0;
for(i = 0; i < 4; ++i) {
printf("alloc size = %d\n", s);
addr[i] = (char*) malloc(s);
printf(" Main thread call malloc after , apply 1gb Memory size , This memory start address :0X%x\n", addr[i]);
}
getchar();
return 0;
}

# ps aux | grep alloc_4g
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 7797 0.0 0.0 4198540 352 pts/1 S+ 16:58 0:00 ./alloc_4g
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
int main() {
int ret;
char* addr[4];
printf(" Use cat /proc/%d/maps View memory allocation \n",getpid());
size_t s = 1024 * 1024 * 1024;
int i = 0;
for(i = 0; i < 4; ++i) {
printf("alloc size = %d\n", s);
addr[i] = (char*) malloc(s);
printf(" Main thread call malloc after , apply 1gb Memory size , This memory start address :0X%x\n", addr[i]);
// Accessing virtual memory
memset(addr[i], 0, s);
}
getchar();
return 0;
}

- stay 32 Bit operating system , Because the process can only apply for 3 GB Size of virtual memory , So apply directly 8G Memory , The application will fail .
- stay 64 position Bit operating system , Because the process can only apply for 128 TB Size of virtual memory , Even if the physical memory is only 4GB, apply 8G Memory is no problem , Because the requested memory is virtual memory , When this virtual memory is accessed , Because there is not enough physical space , It will happen OOM.
边栏推荐
- 今天面了个腾讯拿 38K 出来的,让我见识到了基础的天花板
- Understand the domestic open source Magnolia license series agreement in simple terms
- 华为机试-题目核心考点
- 浅析二层工业交换机的特点
- Tencent took out 38K two days ago, which showed me the basic ceiling. Today share is for you~
- The pit trodden by real people tells you to avoid the 10 mistakes that novices in automated testing often make
- Openai officially announced that dall-e will open its beta to 1million users
- Idea error port 8080 is already in use
- kali wifi破解(多种方式)
- FPGA设计中遇到的奇葩问题之“芯片也要看出身”(三)
猜你喜欢
Idea error port 8080 is already in use
Mlx90640 infrared thermal imaging sensor temperature measurement module development notes (III)
攻防世界---mfw
国家互联网信息办公室对滴滴全球股份有限公司依法作出网络安全审查相关行政处罚的决定
Explain soap Simple Object Access Protocol in detail
npm install 报 -4058错误
Figure neural network: gat learning, understanding and pit entry
Metronic 管理仪表板,高级引导仪表板主题
文件操作管理
模电——电阻是什么?
随机推荐
Detailed explanation of onvif protocol and protocol testing tools
Computer postgraduate entrance examination database question bank
D3.js + Canvas 绘制组织结构图
Class字节码文件
“中国网事·感动2022”二季度网络感动人物评选结果揭晓
小程序技术解决桌面应用敏捷迭代的一种思路
Openai officially announced that dall-e will open its beta to 1million users
使用4D Nerf显示遮挡(CVPR2022)
2022年数据库审计产品排行榜-必看!
Matlab least square fitting
92.(leaflet篇)leaflet态势标绘-进攻方向采集
初步认识Redis
文件操作管理
solo 博客 文章的链接编辑提示非法链接
[comprehensive pen test] difficulty 3.5/5, multi solution popular binary tree pen test
An idea of solving agile iteration of desktop application with applet Technology
QT 之事件的相关使用用例
Tensorflow入门教程(三十八)——V2-Net
Expression package applet, sideline daily entry 400+
申万宏源证券股票低佣金开户靠谱吗,可靠安全吗