1992.12.22

SUBJECT: Memory Management 

STATUS OF THIS MEMO:
System Performance Tuning°ú °ü·ÃÇÏ¿© MEMORY Management¸¦ À§ÇÑ
utility¸¦ Á¤¸®ÇÑ °ÍÀÓ

CONTENTS:
1. Memory Performance
   1) How to tell if your system is paging
   2) Using vmstat (System V ¿¡¼­´Â sar -w & sar -p)
2. Managing the Swap Area
   1) Swap area·Î /dev/disk2b¸¦ AddÇÒ °æ¿ì
   2) Filesystem Paging
   3) Swap Area Size
3. Computing Memory Requirements
   1) Estimating Memory for BSD Systems
   2) Estimating Memory for System V
4. Shared Memory

DESCRIPTION:

1. Memory Performance

   1) How to tell if your system is paging

      - BSD¿¡¼­ vmstat command¸¦ »ç¿ëÇÏ¿© Memory check (vmstat -s)

      - page ins  : pages moved from disk to memory
      - page outs :     ,,      from memory to disk
      - swap ins  : processes moved form disk to memory
      - swap outs :     ,,      ,,  from memory to disk

   2) Using vmstat (System V ¿¡¼­´Â sar -w & sar -p)

      % vmstat n m       nÃÊ °£°ÝÀ¸·Î m¹øÀ» ½ÇÇà report
      % vmstat 2 3
      procs     memory              page           disk       faults     cpu
      r b w   avm   fre  re at  pi  po  fr  de   s0 d1 d2   in  sy  cs us sy id
      0 0 0     0  2504   0  1   1   0   0   0    1  0  0    7  47   6  1  2 97
      0 0 0     0  2504   0  0   0   0   0   0    0  0  0    6  62   4  2  2 96
      0 0 0     0  2460   0  0   0   0   0   0    0  0  0    3  48   3  2  1 97

       - r   : The number of runnable processes during the interval
       - b   : external event³ª high-speed I/O¸¦ À§ÇØ ´ë±âÁßÀÎ procedssÀÇ ¼ö
       - w   : swapped outµÈ runnable processÀǼö·Î ¸¸¾à, ÀÌ field°¡
               0 ÀÌ ¾Æ´Ï¸é ÀÌ systemÀº memoryÀÇ ºÎÁ·À» ´À³¤´Ù
       - avm : The total amount of active virtual memory
       - fre : The number of pages currently on the free list,
               the amount of physiacl memort in KByte
       - pi  : The number of 1-KB pages per second that have ben paged in
       - po  :     ,,        ,,       ,,        ,,        ,,     paged out since
               the last report
       - de  : memory ºÎÁ·À» ³ªÅ¸³»¸ç, ¸¸¾à ÀÌ field°¡ 0 ÀÌ ¾Æ´Ï¸é
               memoryÀÇ ºÎÁ·ÀÌ ½É°¢ÇÔÀ» ÀǹÌÇÑ´Ù
       - s0, d1, d2
               The number of disk operations per second on each disk drive
       - sy  : system»óÅ¿¡¼­ ¼Ò¿äµÈ total CPU timeÀÇ percentage
       - us  : user»óÅ¿¡¼­     ,,        ,,             ,,
       - id  : idle»óÅÂÀÇ total CPU timeÀÇ percentage

      À§¿¡¼­ °¡Àå Áß¿äÇÑ field´Â po(page-out)¿Í w(the number of swapped-
      out processes)ÀÌ´Ù 

2. Managing the Swap Area

   1) Swap area·Î /dev/disk2b¸¦ AddÇÒ °æ¿ì
      
      - ¸ðµç file systemµéÀ» backupÇÑÈÄ /dev/disk2b partitionÀ» newfs

      - Build a new kernel that can use /dev/disk2b for swapping
           config  vmunix  swap  on  disk0b  and  disk2b

      - Modify /etc/fstab to reflect the disk's new organization
           /dev/disk2b swap swap rw 0 0   # Systems that support NFS
           /dev/disk2b:swap:sw:0:0        # Systems that don't support NFS

      - Check /etc/rc & the command /etc/swapon -a enable

      * in case System V
        
        # swap -a dev low len
             dev  : The special file for your swapping partition
             low  : The starting address of the swapping area within 
                    the swapping partition
             len  : The size of the swapping partition, in 512-byte disk blocks

        - /etc/rc2.d file¿¡ ´ÙÀ½°ú °°ÀÌ swap srea¸¦ ±â¼ú
             swap /dev/dsk/ls2 0 29984

   2) Filesystem Paging

      - Under SunOS
        # mkfile size filename
        # /usr/etc/swapon filename

      - Under System V
        # swap filename

   3) Swap Area Size
    
      % pstat -s  # shows you how mush of your swap space is in use
     
      % /etc/swap -l      # in case System V

      % sar -r    # To get a long-term picture of swap usage

3. Computing Memory Requirements

   1) Estimating Memory for BSD Systems

      % ps -avx

        PID TT STAT  TIME SL RE PAGEIN SIZE  RSS   LIM %CPU %MEM COMMAND
        142 p1 R     0:05  0 13      2  296  928    -8 10.3  3.2 cmdtool
        167 p1 R     0:00  0  1      0  360  824    -8  7.7  2.8 ps
        148 p3 S     0:28 13 36     14  296  720    -8  0.0  2.5 cmdtool
        165 p3 S     0:00 17 36      0  432  552    -8  0.0  1.9 vi

        - SIZE  : The total amount of virtual memory allocated to the 
                  program's data & stack segments, in KByte
        - RSS   : Resident sets; The total amount of physical memory allocated
                  to the program's data & stack segments, in KByte 
        - LIM   : The limit applied, if any, to the program's resedent size
        - TSIZ  : Text size; the total amount of virtual memory allocated to
                  the program's text segment, in KByte
        - TRS   : Text resident set; the total amount of virtual memory
                  allocated to the program's text segment, in KByte

      % size /bin/ls     # Under SunOS
        text    data    bss     dec     hex
        12560   2536    2552    17648   44f0   ( size in KByte )
 
   2) Estimating Memory for System V

      % size /usr/local/bin/myprog

      % ps -el

4. Shared Memory

   - applicationÀÇ ÇÊ¿ä¿¡ ÀÇÇØ shared memory¸¦ »ç¿ëÇÒ¼ö ÀÖÀ¸¸ç SHMMAX³ª SHMSIZE
     configuration parameterÀÇ ¼öÁ¤¿¡ ÀÇÇØ shared memory size¸¦ º¯°æÇÒ¼ö ÀÖ°í
     ±âº»Àº  1 MBÀÌ´Ù

   - shared memory¸¦ »ç¿ëÇÏ°íÀÚ Çϸé kernel configue file¿¡¼­ System V IPC
     facility¸¦ »ç¿ëÇϱâÀ§ÇØ option IPCSHMEM ºÎºÐÀ»commant outÇÏ¿© enableÇÏ°í
     /sys/sys/shm.h file¿¡¼­ SHMMAX³ª SHMSIZE °ªÀ» º¯°æÇÑÈÄ kernel build

   - shared memory »ç¿ë·®ÀÇ ÃøÁ¤Àº "ipcs -a"¸¦ »ç¿ëÇÏ¿© report
     
   - shared memoryÀÇ »ç¿ëÀº application¿¡¼­ shmget functionÀ» callÇÏ¿© »ç¿ë



Revision History
Created      on Dec  22 ,1992