Swap File 생성하기
1.현재의 Swap 정보 확인
[root@testora /]# swapon -s Filename Type Size Used Priority /dev/dm-1 partition 4194300 1576020 -1 [root@testora /]# free -h total used free shared buffers cached Mem: 2.9G 2.7G 190M 715M 216M 1.0G -/+ buffers/cache: 1.4G 1.4G Swap: 4.0G 1.5G 2.5G
위 정보와 같이 Swap 공간이 모자르지는 않지만 테스트를 위해 Swap File을 추가 해 보기로 한다.
2.Swap File로 사용할 File을 생성
[root@testora /]# ls -al /imsi_swapfile ls: cannot access /imsi_swapfile: 그런 파일이나 디렉터리가 없습니다 [root@testora /]# dd if=/dev/zero of=/imsi_swapfile bs=1M count=500 500+0 records in 500+0 records out 524288000 bytes (524 MB) copied, 0.826755 s, 634 MB/s [root@testora /]# ls -lh /imsi_swapfile -rw-r--r--. 1 root root 500M 2019-04-15 11:07 /imsi_swapfile
3.적절한 파일 권한으로 변경
[root@testora /]# chmod 600 /imsi_swapfile [root@testora /]# ls -lh /imsi_swapfile -rw-------. 1 root root 500M 2019-04-15 11:07 /imsi_swapfile
4.Swap으로 등록
[root@testora /]# mkswap /imsi_swapfile mkswap: /imsi_swapfile: warning: don't erase bootbits sectors on whole disk. Use -f to force. Setting up swapspace version 1, size = 511996 KiB no label, UUID=8c632ca0-3a21-425f-8aa6-79c0a90e3db5 [root@testora /]# swapon /imsi_swapfile
재부팅 후에도 추가한 Swap 공간이 적용되어 사용되기를 원한다면 /ect/fstab 파일에 아래 항목을 추가해야 한다.
/imsi_swapfile swap swap defaults 0 0
5.추가된 Swap 정보 확인
[root@testora /]# swapon -s Filename Type Size Used Priority /dev/dm-1 partition 4194300 1576000 -1 /imsi_swapfile file 511996 0 -2 [root@testora /]# free -h total used free shared buffers cached Mem: 2.9G 2.8G 100M 715M 90M 1.3G -/+ buffers/cache: 1.4G 1.4G Swap: 4.5G 1.5G 3.0G [root@testora /]#
위와 같이 추가된 정보를 확인할 수 있다.
6.추가적인 정보
swappiness 설정이 존재한다. 시스템이 Swap 사용에 대한 선호도를 1-100 까지의 값으로 설정할 수 있다.
작은 값일수록 커널이 Swap 사용을 줄이려고 하며 큰 값일수록 커널이 Swap을 적극적으로 사용할려고 하는 경향이 커진다.
[root@testora /]# cat /proc/sys/vm/swappiness 60 [root@testora /]# sysctl vm.swappiness=50 vm.swappiness = 50 [root@testora /]# cat /proc/sys/vm/swappiness 50
이 파라미터 값을 재부팅 후에도 적용하고 싶다면 /etc/sysctl.conf 파일에 아래 항목을 추가한다.
vm.swappiness=50
# swappiness value vm.swappiness=50 "/etc/sysctl.conf" 52L, 1420C written
3.Swap File 삭제
[root@testora /]# swapoff -v /imsi_swapfile swapoff on /imsi_swapfile [root@testora /]# swapon -s Filename Type Size Used Priority /dev/dm-1 partition 4194300 1575988 -1 [root@testora /]# free -h total used free shared buffers cached Mem: 2.9G 2.8G 98M 715M 91M 1.3G -/+ buffers/cache: 1.4G 1.4G Swap: 4.0G 1.5G 2.5G [root@testora /]# ls -al /imsi_swapfile -rw-------. 1 root root 524288000 2019-04-15 11:09 /imsi_swapfile [root@testora /]# rm /imsi_swapfile rm: remove 일반 파일 `/imsi_swapfile'? y [root@testora /]# ls -al /imsi_swapfile ls: cannot access /imsi_swapfile: 그런 파일이나 디렉터리가 없습니다 [root@testora /]#
/etc/fstab에 적용해 놓았다면 해당 항목을 제거한다.
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
14 | nmon 사용법 | 명품관 | 2016.02.05 | 7828 |
13 | strace 사용법 | 명품관 | 2016.02.18 | 8332 |
» | Swap File 생성하기 | 명품관 | 2019.04.15 | 669 |
11 | Memory Usage 확인용 스크립트 [2] | 명품관 | 2019.04.15 | 1431 |
10 | "리눅스에 대한 마이크로소프트의 사랑", WSL 2의 이해와 시작하기 | 명품관 | 2019.09.23 | 544 |
9 | 59 Linux Networking commands and scripts | 명품관 | 2019.11.18 | 1594 |
8 | Oracle Linux 8.2 버전 chrony 설정하기 | 명품관 | 2020.09.17 | 2470 |
7 | Linux에서 LVM 사용 | 명품관 | 2020.11.10 | 860 |
6 | RAC SCAN 사용을 위한 DNS 서버 설정하기 | 명품관 | 2020.11.10 | 9249 |
5 | iscsi 서버/클라이언트 설정하기(with targetcli) | 명품관 | 2020.11.14 | 2264 |
4 | Alias 사용 | 명품관 | 2021.03.03 | 676 |
3 | 세마포어(semaphore) | 명품관 | 2021.12.21 | 494 |
2 | df 명령어 대신 사용할 수 있는 python용 pydf | 명품관 | 2023.03.14 | 188 |
1 | read 명령어 사용법 | 명품관 | 2024.01.22 | 69 |