Monday, April 14, 2008

Resource Limits

시스템의 리소스 제한값을 보거나 설정하는 것은 아래 함수를 통해 할 수 있다.

#include <sys/time.h>
#include <sys/resource.h>

struct {
rlim_t rlim_cur; // soft
rlim_t rlim_max; // hard
};

int getrlimit(int resource, struct rlimit *rlim);
int setrlimit(int resource, const struct rlimit *rlim);

리소스 제한 값에는 soft limit과 hard limit 두가지가 있는데, soft limit는 hard limit 한도내에서 자유롭게 변경할 수 있다. 각 값들은 0인 경우 disable이고, RLIM_INFINITY(-1) 인 경우 무한대이다. limit 값들의 flag 이름들은 아래와 같다.

  • RLIMIT_AS : address space 제한

  • RLIMIT_CORE : 코어파일 크기

  • RLIMIT_CPU : 최대 CPU 사용시간

  • RLIMIT_DATA : data segment 크기 제한

  • RLIMIT_FSIZE : File size

  • RLIMIT_LOCKS : 최대 File Lock 개수

  • RLIMIT_MEMLOCK : CPY_SYS_IPC 설정없이 mlock(), shmctl()등으로 가질수 있는 메모리 크기

  • RLIMIT_MSGQUEUE : massage queue 크기

  • RLIMIT_NICE

  • RLIMIT_NOFILE : fd갯수 제한

  • RLIMIT_NPROC : user가 돌릴 수 있는 process 수 제한

  • RLIMIT_RSS : maximun number of pages

  • RLIMIT_RTPRIO

  • RLIMIT_SIGPENDING : 최대로 queue될 수 있는 signal갯수

  • RLIMIT_STACK : 프로세스 스택 크기 제한


이러한 값들을 가지고 설정하거나, 값을 확인하는 코드 예는 아래와 같다.

struct rlimit rlim;
int ret;

// get RLIMIT_CORE value
ret = getrlimit(RLIMIT_CORE, &rlim);
if (ret == -1) perror("getrlimit"), return 1;

printf ("RLIMIT_CORE sft(%ld), hrd(%ld)\n", rlim.rlim_cur, rlim.rlim_max);

// set RLIMIT_CORE value
rlim.rlim_cur = 32 * 1024 * 1024;
rlim.rlim_max = RLIM_INFINITY;
ret = setrlimit(RLIMIT_CORE, &rlim);
if (ret == -1) perror("setrlimit"), return 1;

No comments:

Post a Comment