본문 바로가기
오류노트

AWS ec2 t3.micro 서버 스프링부트 빌드 오류 error='Cannot allocate memory' (errno=12)

by 어컴띵 2021. 4. 26.

 

OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x000000010096c000, 131072, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 131072 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /home/ec2-user/app/step1/springboot-demo-webservice/hs_err_pid4082.log

위와 같은 오류가 발생하여 찾던중 가상메모리를 추가하는 방법이 있다. ec2 t3-micro 서버의 메모리가 1기가 뿐이라 메모리 부족오류가 발생 다음과 같이 swapfile을 이용한 가상메모리를 추가하여 해결한다.

 

1. 스왑파일 2기가 생성 (128MB x 16 = 2GB)

$ sudo dd if=/dev/zero of=/swapfile bs=128M count=16

2. 스왑파일 읽기쓰기 업데이트

$ sudo chmod 600 /swapfile

3. linux 스왑영역 설정

$> sudo mkswap /swapfile

4. 스왑공간에 파일을 추가하여 스왑파일을 즉시 사용할수 있게 함

$> sudo swapon /swapfile

5. 프로시저가 성공적인지 확인

$ sudo swapon -s

6. /etc/fstab 파일을 편집하여 부팅시 스왑파일을 활성화

$ sudo vi /etc/fstab

7. 파일 맨아래에 다음 내용을 추가

/swapfile swap swap defaults 0 0

8. ec2 서버 재부팅

Swap이 생성된걸 확인할수 있다.

재부팅 하고 다시 빌드를 하니 오류없이 빌드가 잘된다.

 

 

참조:

aws.amazon.com/ko/premiumsupport/knowledge-center/ec2-memory-swap-file/

sightstudio.tistory.com/12