Swap partition
Overview
Swap partition에 대한 기술 문서입니다.
Summary
- 무엇인가? - Swap partition
- 왜 필요한가? - HPC 및 서버 환경에서 필수 개념
- 언제 사용하는가? - 서버 구성, 성능 튜닝, 문제 해결 시
Purpose
이 문서가 존재하는 이유
- Goal: Swap partition에 대한 기술 정보 제공
- Scope: Swap partition의 개념, 사용법, 설정
- Non-goals: 다른 주제로의 확장
Key Concepts
| Concept | Description | Related |
|---|---|---|
| Swap partition | HPC/서버 환경에서 중요한 기술 개념 | Linux, Server |
Detailed Explanation
Swap partition acts as a disk memory in Linux when the RAM is exhausted, your Linux system uses part of the hard disk memory and allocates it to the running application. Although Linux can run without swap partition if the system has plenty of RAM, a little amount of swap is always advisable. In fact, a distribution like Ubuntu automatically creates a swap file of 2 GB in size. This should give you an indication that having some swap space is recommended. There are many discussion on what would be idle size of swap, RedHat recommend a swap size of 20% of RAM for modern systems (i.e. 4GB or higher RAM). CentOS has a different recommendation for the swap partition size. It suggests swap size to be:
- Twice the size of RAM if RAM is less than 2 GB
- Size of RAM + 2 GB if RAM size is more than 2 GB i.e. 5GB of swap for 3GB of RAM
Ubuntu has an entirely different perspective on the swap size as it takes hibernation into consideration. If you need hibernation, a swap of the size of RAM becomes necessary for Ubuntu. Otherwise, it recommends:
- If RAM is less than 1 GB, swap size should be at least the size of RAM and at most double the size of RAM
- If RAM is more than 1 GB, swap size should be at least equal to the square root of the RAM size and at most double the size of RAM
- If hibernation is used, swap size should be equal to size of RAM plus the square root of the RAM size
<syntaxhighlight lang="bash"> // Check SWAP partition and size
- swapon -s
// Create SWAP 2GB partition example
- fallocate -l 2g /swap
- chmod 0600 /swap
- mkswap /swap
- swapon /swap
Best Practices
- 최신 버전 사용 권장
- 공식 문서 참고
- 테스트 환경에서 먼저 검증
References
Related Pages
Knowledge Graph
Related