특정 커뮤니티에 스왑에대한 이야기가 나와 기존에 알고있던 물리 메모리의 2배 (예전 유행) 이야기가 나오길래 swap 에 대해서 찾아본 내용을 정리합니다.


Redhat 에서 권장하는 swap (https://access.redhat.com/ko/node/744483)


Red Hat Enterprise Linux 5

설치된 RAM 용량권장되는 스왑 용량
4GB or less2GB swap space
4GB - 16GB4GB swap space
16GB - 64GB8GB swap space
64GB - 256GB16GB swap space


Red Hat Enterprise Linux 6, Red Hat Enterprise Linux 7, Red Hat Enterprise Open Stack Platform 3 and Red Hat Enterprise Open Stack Platform 4

설치된 RAM 용량권장되는 스왑 용량최대절전을 허용할때 권장되는 스왑용량
2GB or lessRAM 용량의 2배RAM 용량의 3배
> 2GB - 8GBRAM 용량RAM 용량의 2배
> 8GB - 64GB적어도 4GB ~ RAM 용량의 1 / 2 배RAM 용량의 1.5배
> 64GB or more적어도 4GB최대절전이 권장되지 않음



ubuntu 에서 권장하는 swap (https://help.ubuntu.com/community/SwapFaq)


(last 3 columns denote swap space)

        RAM(MB) No hibernation  With Hibernation  Maximum
         256     256              512               512
         512     512             1024              1024
        1024    1024             2048              2048

        RAM(GB) No hibernation  With Hibernation  Maximum
          1      1                2                   2
          2      1                3                   4
          3      2                5                   6
          4      2                6                   8
          5      2                7                  10
          6      2                8                  12
          8      3               11                  16
         12      3               15                  24
         16      4               20                  32
         24      5               29                  48
         32      6               38                  64
         64      8               72                 128
        128     11              139                 256



Why do I need swap?

Memory consuming programs Sometimes, a large program (like LibreOffice, Neverwinter Nights, or a video editor) make the entire system need extra memory. A significant number of the pages used by these large programs during its startup may only be used for initialization and then never used again. The system can swap out those pages and free the memory for other programs or even for the disk cache. In these cases, swap will be used to help the system handle any extra load.

Hibernation (suspend-to-disk) The hibernation feature (suspend-to-disk) writes out the contents of RAM to the swap partition before turning off the machine. Therefore, your swap partition should be at least as big as your RAM size. The hibernation implementation currently used in Ubuntu, swsusp, needs a swap or suspend partition. It cannot use a swap file on an active file system.

Unforeseeable Circumstances Unforeseeable events can and will happen (a program going crazy, some action needing much more space than you thought, or any other unpredictable combination of events). In these cases, swap can give you an extra delay to figure out what happened, or to finish what you are working on.

Optimizing memory usage Since mechanical hard drives are considerably slower than RAM (SSD - Solid State Drive - storage is not as slow as physical drives, but still slower than RAM), when you need a file (be it a data file like a video, executables like Firefox, or libraries), the Linux kernel reads the file into RAM and keeps it there, so that the next time you need it, it is already in RAM and data access is much faster. The portions of RAM that accelerate disk read are called "cached memory." You will notice that they make a huge difference in terms of responsiveness. The Linux kernel automatically moves RAM reserved by programs--but not really used--into swap, so that it can serve the better purpose of extending cached memory.

Optimizing Swap performance Because swap space uses a disk device, this can cause performance issues in any system that uses swap space significantly because the system itself may also be using the same disk device at the same time that it is required for swap operations. One way to reduce this problem is to have swap space on a different physical drive so that the competition for that resource is either reduced or eliminated.


Debian 에서 이야기하는 swap (https://wiki.debian.org/Swap)

Things to consider when deciding how to setup swap space on your machine

  1. Do you intend to use the Hibernate and Suspend functions? If you intend to use either, you will need to ensure your available swap space is large enough to hold all information your running system will have in RAM. If you intend to use Hibernate you should ensure that your Debian installation has access to a swap partition or file that is NOT shared with another instance of GNU/Linux.
  2. How much memory does your machine have? If your machine has a large amount of RAM available to it and you don't need Hibernate or Suspend, then it will be safer to have less swap available to the system. If your machine has very little RAM available to it, such as the case in older machines and netbooks you should ensure to make a swap space that is large enough. Double the system memory would be a good suggestion in this case.
  3. How much memory will be taken by the applications you intend to run? The memory usage of a Debian GNU/Linux system will vary greatly on the applications you choose to run. For instance, running a lighter weight desktop environment such as Openbox or Xfce and their associated applications will use less memory than GNOME or KDE.
  4. How much hard disk do you have available? If using a small solid state disk or USB key for the installation of Debian this hard disk space might be at a premium. In such cases it might make more sense to install more system memory if needed than use a large swap space. This also has the benefit of speeding up the system, as the read/write speed of hard disks is much slower than RAM.

In the end, if your machine runs out of both RAM and swap space then the system will crash. This has lead to the simplistic but safe answer of use a swap space that is "double the amount of system memory".


suse 에서 이야기하는 swap (https://www.novell.com/support/kb/doc.php?id=7010157)

Is swap space required?
Strictly speaking, a swap partition is not required for SLES. However, swap space is recommended. The general explanation for this is that swap space allows for infrequently used memory to be swapped to disk, thereby freeing up physical RAM for active processes.

In addition to swap space being used to free RAM, having available swap space also changes the behavior of the oom-killer (Out of Memory Killer) in low memory situations. When swap space is available, under low memory conditions, the oom-killer first tries to swap out as many pages as possible. 

Swapping out pages is done in two passes. The first pass discards stale pages, to reduce the amount of I/O during the actual swap process. The second pass swaps out pages to disk. This swapping process slows the system, reducing the chances of more processes being run/started. More importantly, the oom-killer will only start killing processes after the paging process has completed, and the system is still out of memory. Hence, a delay has been added between determining that the system is low on memory, and actually killing active processes. This delay may provide enough time for the offending process to terminate itself, or for memory to be freed to prevent any processes from being killed.

Without a swap space available, the oom-killer starts killing processes immediately in a low memory situation.

How much swap space is recommended?
Every server environment is different, and swap space requirements vary greatly depending upon the software environment. As a general recommendation, a swap space size of 2GB is typically sufficient. (Some large database environments may require much larger swap spaces.)

In order to determine if a server has sufficient swap space, monitor the 'Swap' line in the output of the `free` command. If the amount of free swap space approaches zero, you may have insufficient swap space - or insufficient RAM. Some swap space usage is good, but too much usage may indicate the server has insufficient resources for all running processes.


위의 내용들을 종합해보면 이전과 같은 스왑은 필요하지 않는다 하지만 몇가지 조건에 따라서는 swap을 충분히 가지고 가야한다. 라는 결론이 나옵니다.

그 몇가지 경우중 보편적으로 이야기 나오는건은 "최대절전 모드" 입니다. 






'Linux > Document' 카테고리의 다른 글

mmm  (0) 2016.05.09
keepalived + haproxy + dns  (0) 2016.04.07
mariadb galera cluster 10.0 centos 6.x + LVS(LB)  (0) 2016.03.25
ubuntu banner 설정  (0) 2016.03.04
glusterFS  (0) 2016.03.04

+ Recent posts