Comments (4)
代码中已定义的数组包括两种:
- 函数体内的,在栈中分配,由RLIMIT_STACK来限制
- 全局的,属于已初始或未初始的变量,由RLIMIT_DATA限制
另外RLIMIT_DATA同样也影响堆。
RLIMIT_AS是限制进程的虚拟内存大小,即内存地址空间的大小,是不能反应一个程序使用物理内存的大小的。
from lo-runner.
http://linux.die.net/man/2/getrlimit
可以看看里面各种限制具体的含义
from lo-runner.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <sys/resource.h>
int main()
{
int *a = NULL;
// 150M
int v = 150000000;
struct rlimit memory_limit;
// 90M
memory_limit.rlim_cur = memory_limit.rlim_max = 90000000;
setrlimit(RLIMIT_AS, &memory_limit);
//setrlimit(RLIMIT_DATA, &memory_limit);
a = (int *)malloc(v);
if(a == NULL){
printf("error\n");
}
else {
memset(a, 0, v);
printf("success\n");
}
return 0;
}
但是我使用上面的代码测试,RLIMIT_DATA
仍然能成功的分配内存,而 RLIMIT_AS
会导致内存分配失败。
文档上说的This limit affects calls to brk(2) and sbrk(2)
,我测试 malloc
大内存的时候使用到了 mmap
。
from lo-runner.
又翻了下文档,glibc的malloc有两种分配内存的方式,小内存是在堆上面分配(可以被RLIMIT_DATA影响),但是超过阈值的内存分配是通过mmap来分配的,mmap分配的不在堆上,而他产生的地址空间是受RLIMIT_AS影响的。
所以这里应该是RLIMIT_DATA和RLIMIT_AS都要做限制,但是由于地址空间里面有些不是进程直接分配的内存,因此设置限制的时候乘以2了。
不过这个bug不影响测评的结果(最后会再次校验内存的使用情况)。
Thanks!
from lo-runner.
Related Issues (14)
- 想知道有木有trace功能的白名单 HOT 2
- 怎么设置files参数? HOT 1
- MAC 上无法编译成功,好像是因为 sys/user.h文件和linux不一样 HOT 3
- 沙盒中(python)调用其他库 HOT 3
- 利用centos7.3 计算出来的运行时间和内存使用,出入挺大的 HOT 3
- emmm...小白有个安装问题
- 安装时出错了呀 HOT 1
- Install Problem On Linux HOT 1
- 在判java题时报错
- Presentation Error when using 'rU' open mode HOT 2
- PE after latest commit HOT 5
- 64位Ubuntu下内存读不准 HOT 4
- 本项目开源协议是什么? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lo-runner.