Giter VIP home page Giter VIP logo

Comments (4)

dojiong avatar dojiong commented on September 27, 2024

代码中已定义的数组包括两种:

  1. 函数体内的,在栈中分配,由RLIMIT_STACK来限制
  2. 全局的,属于已初始或未初始的变量,由RLIMIT_DATA限制

另外RLIMIT_DATA同样也影响堆。

RLIMIT_AS是限制进程的虚拟内存大小,即内存地址空间的大小,是不能反应一个程序使用物理内存的大小的。

from lo-runner.

dojiong avatar dojiong commented on September 27, 2024

http://linux.die.net/man/2/getrlimit
可以看看里面各种限制具体的含义

from lo-runner.

virusdefender avatar virusdefender commented on September 27, 2024
#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.

dojiong avatar dojiong commented on September 27, 2024

又翻了下文档,glibc的malloc有两种分配内存的方式,小内存是在堆上面分配(可以被RLIMIT_DATA影响),但是超过阈值的内存分配是通过mmap来分配的,mmap分配的不在堆上,而他产生的地址空间是受RLIMIT_AS影响的。

所以这里应该是RLIMIT_DATA和RLIMIT_AS都要做限制,但是由于地址空间里面有些不是进程直接分配的内存,因此设置限制的时候乘以2了。

不过这个bug不影响测评的结果(最后会再次校验内存的使用情况)。

Thanks!

from lo-runner.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.