Swap memory(size)

Server/CentOS 2021. 7. 10. 17:57

시스템 메모리가 부족할 때 하드디스크의 공간을 메모리로 사용하는 가상 메모리를 Swap memory 라고 한다. 필요시 swap 메모리를 늘리거나 복구하는 상황에 아래를 참고한다.

 

 

1. swap memory 확인

 

# free -h
              total        used        free      shared  buff/cache   available
Mem:           7.6G        478M        159M        1.8G        7.0G        5.0G
Swap:          3.0G         14M        3.0G

7.6G 의 시스템 메모리와 3.0G 의 Swap 메모리를 확인할 수 있다.

 

 

2. swap memory 파일 생성

 

# dd if=/dev/zero of=/home/swapfile bs=1024 count=1000000
1000000+0 records in
1000000+0 records out
1024000000 bytes (1.0 GB) copied, 2.2715 s, 451 MB/s

swap 메모리 파일명은 /home/swapfile 이고, 크기는 1024(byte) * 1,000,000 = 1GB 크기의 파일이 생성되었다. 파일명은 무엇이든 상관없다.

 

 

3. 파일에 swap memory 영역 설정 (mkswap)

 

# mkswap /home/swapfile
Setting up swapspace version 1, size = 999996 KiB
no label, UUID=e355981c-ed51-4dde-b6c0-ae7a542ac40e

 

 

4. swap memory 활성화 (swapon)

 

# swapon /home/swapfile
swapon: /home/swapfile: insecure permissions 0644, 0600 suggested.
# chmod 644 /home/swapfile

 

 

5. swap memory 확인

 

# free -h
              total        used        free      shared  buff/cache   available
Mem:           7.6G        397M        4.2G        1.8G        3.0G        5.2G
Swap:          4.0G        101M        3.9G

Swap 메모리가 1.0G 추가되었다.

 

 

6. 재부팅 후에도 적용 (fstab)

 

# vi /etc/fstab
/home/swapfile    swap    swap defaults    1 1

 

 

7. 사용 후 swap memory 삭제 (swapoff)

 

# swapoff /home/swapfile
# rm -rf /home/swapfile

 


WRITTEN BY
손가락귀신
정신 못차리면, 벌 받는다.

,