Subject : Memory ManageMent Concept ¹× ¿ë¾îÇؼ³

Description :

. Âü°í¹®Çå

 UNIX SYSTEM ARCHITECTURE 
 Prentice-Hall Inc, Prabhat K.Andleigh
                                      

. UNIX system Àº virtual memory system À¸·Î µ¿ÀÛ ÇϱâÀ§ÇØ pages
 ¶ó´Â conceptÀ» »ç¿ëÇÑ´Ù.
 Physical memory´Â °°Àº sizeÀÇ segments·Î ³ª´©¾îÁø´Ù.
 ¿¹¸¦µé¾î °¢°¢ 1K Bytes¾¿ segments ¸¦ pages ¶ó ºÎ¸£ÀÚ.
 ÀÌ°°Àº mapping°ú ÇÔ²² memory ÀÇ ¸ðµç page ´Â page number¿¡ 
 ÀÇÇØ addressed µÇ¾î Áú ¼ö ÀÖ´Ù.
 ¾î¶² ÁÖ¾îÁø ½Ã°£¿¡ ½Ã½ºÅÛ¿¡¼­ ¸¹Àº ¼öÀÇ processes °¡ Á¸ÀçÇÏ¿©
 Á¦ÇÑµÈ ¼ýÀÚÀÇ ÇÁ·Î¼¼½º ¸¸ÀÌ À¯È¿ÇÑ physical memory¿¡ »óÁÖÇÒ ¼ö 
 ÀÖ´Ù¸é, ³ª¸ÓÁö´Â disk·Î swap out µÉ °ÍÀÌ´Ù.
 ÇÁ·Î¼¼½º´Â full ¶Ç´Â ºÎºÐÀûÀÎ image·Î disk·Î ÀúÀåµÈ´Ù.
 AT&T UNIX version 7 ºÎÅÍ System V ¿¡¼­ ¼Ò°³µÈ Swapping scheme,
 4.2BSD¿¡¼­ Ãß°¡µÈ demand paging, AT&T UNIX system V ¿¡¼±
 demand paging°ú swapping ÀÇ Çâ»óµÈ Á¶ÇÕÀ» ÁغñÇÏ°í ÀÖ´Ù.

. Physical & Virtual Memory Organization

 physical memoryÀÇ addressing°ú OrganizationÀÇ ±âÃÊÀûÀÎ concept
 °ú ¿¬°üµÈ data±¸Á¶´Â memory management scheme¿¡ Å©°Ô ÀÇÁ¸ÇÑ´Ù.

 1) Physical memory manage¸¦ À§ÇÑ data±¸Á¶°¡ ÁغñÇØ¾ßµÉ ´É·Â

   @ large Physical memory space¸¦ À§ÇÑ addressing(32M bytes ÀÌ»ó)
   @ Physical memoryÀÇ ºü¸¥ allocation & deallocation
   @ Large virtual memory( gigabyte range ) ÀÇ »ç¿ë
   @ °³º°Àû process memory ¸¸Å­ÀÇ kernel ÀÇ º¸È£

   UNIX system Àº ÀüÇüÀûÀ¸·Î ¸¹Àº ¼öÀÇ users ¸¦ Áö¿øÇÑ´Ù.
   ÀÌ·¯ÇÑ users ¿¡ ÀÇÇØ ¿ä±¸µÈ memory ´Â ÀϹÝÀûÀ¸·Î
   physical memory º¸´Ù Å©´Ù.
   ½ÇÇàµÇµµ·Ï ½ºÄÉÁìµÇÁö ¾ÊÀº ÇÁ·Î¼¼½º´Â disk »óÀÇ swap device¶ó
   ºÒ¸®´Â Ưº°ÇÑ Àå¼Ò·Î ÀϽÃÀûÀ¸·Î ÀúÀåµÈ´Ù.
   swap device ´Â memory ¿Í À¯»çÇÏ°Ô ´Ù·ç¾îÁö´Â µð½ºÅ© »óÀÇ
   configurable ÆÄƼ¼Ç ÀÌ´Ù.
   process ¾È¿¡¼­ ½ÇÇàµÇ´Â programÀº memory address range¿¡ ´ëÇÑ
   À§¿Í°°Àº °¡Á¤ ÀÇ ±âÃÊ¿¡¼­  compile µÇ°í linked µÈ´Ù.

 2) Ä¿³ÎÀÇ task

   @ free physical memoryÀÇ ºü¸¥ ŽÁö
   @ Allocation & deallocation of physical memory
   @ virtual memory °ø°£¿¡¼­ physical memory ·ÎÀÇ mapping ÀýÂ÷
   @ Allocation & deallocation of swap memory(on swap device)
   @ virtual address space¿¡¼­ swap memory·ÎÀÇ mapping ÀýÂ÷

   ¾î¶»°Ô virtual memory¸¦ physical memory¿Í swap memory·Î 
   mappingÇÏ°í data ±¸Á¶´Â ±×°Í°ú ¿¬°üµÇ¾î ÀÖ´ÂÁö ¾Ë¾Æº¸ÀÚ.
   ÀÌ°°Àº mapping¿¡¼­ page tableÀº Áß¿äÇÑ databaseÀÌ´Ù.
   Page tableÀº virtual memory page¸¦ physical memory pages·Î
   mapping ¿¡ »ç¿ëÇÑ´Ù.
   Page tableÀº page table entries·Î ºÒ¸®´Â data±¸Á¶ÀÇ ¿¬¼ÓÀûÀÎ
   list¸¦ ´ã°íÀÖ´Ù.
   Page tableÀº process ÀÇ regionÀ̶ó ºÒ¸®´Â text,data,stack 
   segment¸¦ À§ÇÑ virtual memory °ø°£À» ¹¦»çÇÑ´Ù.

   UNIX process ´Â user code ¶Ç´Â system call À» setup ÇϱâÀ§ÇÑ
   runtime library ·Î ºÎÅÍÀÇ code ¸¦ ½ÇÇàÇÏ´Â µ¿¾È user mode¿¡
   ÀÖ´Ù°í ¸»ÇØÁø´Ù.
   trap À» ¼öÇàÇÏ´Â µ¿¾È user mode ¿¡¼­ kernel mode ·Î ¹Ù²ï´Ù.
   kernel service routine ¸¦ À§ÇÑ code ¸¦ kernel code ¶ó ÇÑ´Ù.
   process °¡ kernel code ·Î ¼öÇàµÉ ¶§ ±×°ÍÀº º¸È£µÇ¾îÁø´Ù.
   user mode ÇÁ·Î¼¼½º´Â kernel¾È¿¡¼­ ¾î¶² codeµµ Á÷Á¢ÀûÀ¸·Î
   È°µ¿ÇÒ ¼ö ¾øÀ¸¸ç kernel¾ÈÀÇ ¾î¶² data µµ access ÇÒ ¼ö ¾ø´Ù.
   kernel Àº user mode process ·Î ºÎÅÍ data ¸¦ accessÇÒ ¼ö ÀÖ´Ù.
   ÀÌ°°Àº user¿Í kernelÀÇ ±¸º°Àº kernel page tableÀÇ Ä¿³Î¿¡ ´ëÇÑ
   grouping page table°ú user mode page tables¿¡¼­ÀÇ user¿¡ ´ëÇÑ
   grouping page tables¿¡ ÀÇÇØ ´Ù·ç¾îÁø´Ù.
 
 3) Data Structures

   UNIX system Àº Àüü physical memory ¸¦ pages¶ó ºÒ¸®´Â µ¿µîÇÑ
   sizeÀÇ segment ·Î ³ª´©´Â °Í¿¡ ±âÃÊÇÏ¿© memory °ü¸®¸¦ ÇÑ´Ù.
   pagesÀÇ ÀüÇüÀû size´Â ±¸Çö¿¡ µû¶ó 512byte¿¡¼­ 16K bytesÀÇ 
   ¿µ¿ª¿¡ ÀÖ´Ù.
   page table entry´Â ¸Þ¸ð¸® pages ÀÇ »ç¿ë¹ýÀ» ¸í½ÃÇÑ´Ù.

   @page table entryÀÇ ±¸¼º¿ä¼Ò

    - page frame number.
    - Age.
    - page modified bit.
    - page protection.

     a. kernel mode readable only
     b. kernel mode writable only
     c. user mode writable
     d. kernel mode writable, user mode readable
     e. user & kernel mode readable only.

    - page valid bit.

   page frame number ´Â physical memory page¸¦ °í¼öÇÑ´Ù.
   page °¡ ¼öÁ¤µÇ¾ú´ÂÁö ¿©ºÎ¿Í page º¸È£¸ðµå ±×¸®°í ±×°ÍÀÌ
   À¯È¿ÇÑ pageÀΰ¡¸¦ Æ÷ÇÔÇÑ´Ù.

   ÇÁ·Î¼¼½ºÀÇ virtual address °ø°£Àº text,data,stack, ±×¸®°í
   hared memory regions ·Î ³ª´©¾îÁø´Ù.

   @virtual address structure

    - Byte Offset
    - Virtual Page Number
    - Rigion

   page tableÀº physical address¿Í virtual address ÀÇ »óÈ£°ü°è¸¦
   ÁغñÇÑ´Ù.

 4) UNIX System memory Organization

   ¸Þ¸ð¸®´Â ÀϹÝÀûÀ¸·Î user memory¿Í system memory·Î ¾Ë·ÁÁø
   ¼¼°¡Áö ÁÖ¿ä ½Ã½ºÅÛ ±¸¼º¿ä¼Ò¿¡ ´ëÇÑ memory·Î ÇÁ·Î¼¼½º¿¡ ÀÇÇØ
   »ç¿ëµÈ´Ù.

   @UNIX system memory ÀÇ ±¸¼º¿ä¼Ò

    - Low core component

     .Interrupt vectors
     .Device handlers
     .Physical memory mapping routines.

    - Kernel code

     .Memory management
     .Process management
     .Disk management
     .I/O management
     .Interprocess communication.

    - System data

     .Process table
     .User structure
     .Kernel stacks
     .Buffer pool
     .In-core Inodes

    - In-core processes.

 5) Memory Swapping

   Á¤ÀÇ

   Swapping systemÀº ÀüüÀûÀÎ processes(text,data,stacks,±×¸®°í
   processµéÀÌ main memory¿¡ Àִµ¿¾È process¸¦ °ü¸®Çϴµ¥ ÇÊ¿äÇÑ
   ´Ù¸¥ ½Ã½ºÅÛ tableµé)¸¦ swap in ¶Ç´Â swap out ÇÑ´Ù.
   ÇÁ·Î¼¼½º´Â ½ÇÇàÀÌ ÁغñµÈ »óÅ·Πdisk¿¡ Á¸ÀçÇÏ¸ç ¸ÞÀÎ ¸Þ¸ð¸®¿¡
   swap in µÇ¸é ¿ì¼±¼øÀ§¿¡ ÀÇÇÑ scheduleÀ» ¾ò´Â´Ù.

   memory map allocation

   swap device´Â º»ÁúÀûÀ¸·Î physical memory¿Í °°ÀÌ ´Ù·ç¾îÁø´Ù.
   swap device¿¡ ´ëÇÑ memory mapÀº swap map À̶ó ºÒ¸°´Ù.
   swap mapÀº µÎ°¡Áö parameter(map address,map size) ¸¦ °¡Áø
   map structure¸¦ °®´Â´Ù.

   Malloc routines

   swap memory¸¦ allocateÇϴµ¥ »ç¿ëÇϸç Physical memory´Â 
   process°¡ re-scheduled µÉ¶§¸¸ allocateµÈ´Ù.

   Mfree Routines

   mfree·çƾÀº swap memory¸¦ free upÇÏ°í swap map¿¡ restoreÇÑ´Ù.

 6) Demand Paging

   Á¤ÀÇ

   Demand paging ±¸Á¶´Â ¿ä±¸¿¡ µû¶ó¼­ disk·Î ºÎÅÍ physical memory
   ·Î page¸¦ loadingÇÏ´Â °ÍÀÌ ÇÊ¿äµÈ´Ù.
   ÀüüÀûÀÎ process¸¦ swappingÇÏ´Â ´ë½Å ½ÇÁ¦ÀûÀ¸·Î ÇÊ¿äÇÑ ºÎºÐ
   ¸¸À» load ÇÑ´Ù.(processÀÇ ´Ù¸¥ page¸¦ °¡Á®¿À±âÀ§ÇØ page faults
   ¶ó´Â °³³äÀ» »ç¿ë)
   ÀÌ°ÍÀÇ ÀÌÁ¡Àº ¾î¶² ½Ã°£¿¡µµ ¸¹Àº ¼öÀÇ process¸¦ ½ÇÁ¦ÀûÀ¸·Î 
   swap in µÇ¾îÁú ¼ö ÀÖ´Ù´Â °ÍÀÌ´Ù.

   page faults

   page faults mechanismÀº physical memory¿¡ ¿ä±¸µÇ´Â page°¡ 
   ¾øÀ»¶§ ÀϾ¸ç actionÀº virtual memory·ÎºÎÅÍ physical memory·Î 
   ¿ä±¸µÇ´Â page¸¦ ÀоîµéÀδÙ.

   page faults activities

    - Adjusting in-core page tables to accept a new page
    - Setup for a page to be read in from disk
    - Sleep until page is loaded
    - Start execution at start of new page when re-scheduled

   Cache memory

   page faults¸¦ ȸÇÇÇϱâ À§Çؼ­ CPU¿¡ ÀÇÇØ ¿ä±¸µÇ¾îÁö±âÀü¿¡ 
   ¿¹»óµÇ´Â page¸¦ memory·Î ÀûÀçÇϱâ À§Çؼ­ ä¿ëµÇ¾ú´Ù.

   Free page pool

   demand page memory ¿¡´ëÇÑ buffer poolÀÌ´Ù.



Revision History

ÀÛ¼ºÀÏÀÚ : 96.06.27
ÀÛ¼ºÀÚ : ¸ÍÀ±È£

¼öÁ¤ÀÏÀÚ : 
¼öÁ¤ÀÚ :