Swap memory

From 탱이의 잡동사니
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

우분투 14.04 최초 설치때, swap 영역을 지정안했더니, 컴퓨터 종료 옵션에서 Hibernate 옵션이 비활성화가 되어있었다. 아마도, swap 영역이 지정되지 않아서 메모리 내용을 저장할 디스크 공간이 없었기 때문으로 생각된다. 아무튼, 다시 Hibernate 모드를 활성하하고자 한다면 다음의 파일을 수정해주면 된다.

Check hibernate available

먼저 hibernate 모드가 가능한지 아닌지를 확인해야 한다. 다음의 명령어로 hibernate 모드로 진입되는지 여부를 확인하자. 만약 다음의 명령어로 hibernate 모드가 안된다면 다시 설정을 확인해봐야 한다. <source lang=bash> $ sudo pm-hibernate </source>

Enable hibernate

Ubuntu-14.04

$ 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

Ubuntu-15.10

$ sudo vi /etc/polkit-1/localauthority/50-local.d/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;org.freedesktop.login1.hibernate-multiple-sessions
ResultActive=yes

Change lid option

만약 모니터 덮개를 덮었을 때 절전모드로 진입하게 하고 싶다면 다음의 파일을 아래와 같이 수정하면 된다.

$ 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 />