Swap memory

From 탱이의 잡동사니
Revision as of 07:01, 8 September 2015 by Pchero (talk | contribs) (→‎Swap file)
Jump to navigation Jump to search

Overview

Swap 메모리 관련 내용 정리

Swap memory

Swap메모리는 주 메모리가 부족할 때 하드디스크와 같은 공간을 메모리로 사용하기 위한 가상 메모리이다.(윈도우에선 가상 메모리(페이징 메모리)라고 지칭함)

Check swap memory

free 명령어로 현재 설정되어 있는 swap 메모리 공간의 크기를 확인할 수 있다. <source lang=bash> pchero@earth:/etc$ free -m

            total       used       free     shared    buffers     cached

Mem: 1000 923 77 82 12 315 -/+ buffers/cache: 594 405 Swap: 1953 0 1952 </source>

Swap memory 늘리기

Swap 메모리 영역을 확보하기 위해서는 2가지 방법이 있다.

- Swap partition 구성하는 방법.
- Swap file 생성 후, swap 영역으로 지정하는 방법.

Swap file

이미 파일 시스템을 구성한 이후라면, 스왑 파티션을 생성하는 것이 부담스러울 수 있다. 이런 경우, 간단하게 스왑 파일을 생성하여 스왑 영역으로 사용하면 된다.

<source lang=bash> pchero@earth:/home$ sudo dd if=/dev/zero of=/home/swapfile bs=1024 count=2000000 2000000+0 records in 2000000+0 records out 2048000000 bytes (2.0 GB) copied, 6.53252 s, 314 MB/s

pchero@earth:/home$ ls -sh total 2.0G 4.0K pchero 2.0G swapfile

pchero@earth:/home$ sudo mkswap /home/swapfile Setting up swapspace version 1, size = 1999996 KiB no label, UUID=7373fad5-bfca-4bb9-b8e7-2a92cf17fa7d

pchero@earth:/home$ sudo swapon /home/swapfile swapon: /home/swapfile: insecure permissions 0644, 0600 suggested.

pchero@earth:/home$ free -m

            total       used       free     shared    buffers     cached

Mem: 1000 935 64 82 6 338 -/+ buffers/cache: 590 409 Swap: 1953 0 1953 </source>

파일 생성 후, /etc/fstab 에 다음과 같이 추가를 해주자.

# another swap file
/home/swapfile  none    swap    sw      0       0

Enable hibernate

절전모드 활성화 하기

$ cd /var/lib/polkit-1/localauthority/50-local.d/
$ sudo vi com.ubuntu.enable-hibernate.pkla
[Re-enable hibernate by default in upower]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes

[Re-enable hibernate by default in logind]
Identity=unix-user:*
Action=org.freedesktop.login1.hibernate
ResultActive=yes

Change lid option

Hibernate your laptop when lid is closed

$ sudo vi /etc/systemd/logind.conf

And change the line <source lang=bash>

  1. HandleLidSwitch=suspend

HandleLidSwitch=hibernate </source>

$ sudo restart systemd-logind

See also

References

<references />