나무 숲

Memory Management 본문

Career

Memory Management

wood.forest 2016. 6. 4. 22:56

Background

- important roles of the operating system

* to protect the operating system as well as the user processes


* Limit register - size of the range

* Base register - smallest legal physical memory address


base(300040)+limit(120900)=420940









아래 그림을 보면 각 프로세스가 분리된 메모리 공간을 가졌음을 알 수 있다

Guaranteed that each process has a separate memory space



Address Binding

- Address binding of instructions and data to memory addresses can happen at three different stages

    * Compile time

        if memory location is known priori, absolute code can be generated at compile time

        must recompile if starting location changes

    * Load time

        must generate relocatable code if memory location is not known at compile time

    * Execution time

        binding delayed until run time

        need h/w support for address maps(base, limit registers)



Logical/Physical memory space

- Logical address(=Virtual Address)

        * generated by CPU

- Physical address

        * address seen by the memory unit

- Logical address and physical address are the same in compile-time and load-time address binding schemes. Differ in execution-time address binding scheme



Memory Management Unit

- h/w device that maps virtual to physical address

- in MMU scheme, the value in the relocation register is added to every address generated by a user process at the time it is sent to the memory

- The user program deals with logical addresses; it never sees the real physical address

위 그림을 보면 relocation register에 있는 값은 유저 프로세스에서 생성된 모든 주소들이 메모리로 보내질 때 그에 더해지며, 유저 프로그램은 logical address만 알고 진짜 physical address는 알 수 없다.



Dynamic Loading

- Routine is not loaded until it is called

- Better memory-space utilization; Unused routines are never loaded

- Useful when large amounts of codes are needed to handle infrequently occurring cases

- No special support form the operating system is required; Implemented through program design

불리기 전까진 사용되지 않으며 많은 양의 코드들이 발생에 따라 처리되어야 할 때 유용.(메모리 공간 사용율이 낫다) 운영체제의 support가 필요없다



Dynamic Linking

- Linking is postponed until execution time

- Small piece of code, stub, is used to locate the appropriate memory-resident library routine

- Stub replaces itself with the address of the routine, and execute the routine

- OS needed to check if routine is in processes' memory space

- Dynamic linking is particularly useful for libraries; Shared libraries

링킹은 execution time까지 기다리며, stub라는 (주소값을 갖는.. 포인터같은 역할) 작은 코드가 메모리 위치를 가리키고, routine의 주소와 교체되어 routine을 실행한다. 



Swapping

- A process can be swapped temporarily out of memory to a backing store and then brought back into memory for continued execution

- Major part of swap time is transfer time

* total transfer time is directly proportional to the amount of memory swapped

프로세스는 실행될 때만 메모리에 들어오고 그 외에는 backing store에 가있는데 이 왔다갔다 과정을 swap이라고 하고 걸리는 시간이 transfer time이다. swapping 시 각각의 동작 속도+transfer time이 고려된다.



Memory Allocation Schemes

Continuous Memory Allocation

- Multiple-partition allocation

* Hole

- block of available memory

- Holes of various sizes are scattered throughout memory

사용 가능한 공간이며 디스크 조각모음을 했을 때 보이는 것처럼 빈 공간이 메모리 전체에 흩뿌려져 있다

* When a process arrives, it is allocated memory from a hole large enough to accommodate it

* OS maintains information about Allocated partitions & Free partitions


- How to satisfy a request of size n from a list of free holes

* First-fit

- Allocate the first hole that is big enough

충분히 큰 빈 공간이 첫번째로 찾아지면 할당

search time이 짧아 할당시간이 적게 걸린다

* Best-fit

- Allocate the smallest hole that is big enough

- Must search entire list, unless ordered by size

- Produces the smallest leftover hole

할당가능한 것들 중 가장 작은 데 할당

다 찾아봐야 해서 search time이 가장 길지만 가장 효율적

* Worst-fit

- Allocate the largest hole

- Must search entire list, unless ordered by size

- Produces the largest leftover hole

가장 큰 공간에 할당

search time이 길고 가장 비효율적


- Fragmentation

* External fragmentation

- Total memory space exists to safisfy a request, but it is not continuous

* Internal fragmentation

- Allocated memory may be slightly larger than requested memory; This size difference is memory internal to a partition, but not being used


- To reduce External fragmentation

* Compaction

- To shuffle memory contents to place all free memory together in one large block 디스크 조각모음을 실행하는 것과 비슷

- is possible only if relocation is dynamic (e.g execution-time address binding)

* To permit the logical address of the process to be noncontinuous, thus allowing a process to be allocated physical memory wherever such memory is available; 

1 Paging

* To permit the physical address space of process to be noncontinuous

* How?

- Divide physical memory into fixed-sized blocks called frames

- Divide logical memory into blocks of the same size called pages

- To run a program of size n pages, it is needed to find n free frames and load the program

- Set up a page table to translate logical to physical addresses

- Internal fragmentation 

>> http://woodforest.tistory.com/10



2 Segmentation

* Memory management scheme that supports user view of memory

* A program is a collection of segments

- A segment is a logical unit such as.. Main program, Procedure, Function, Method, Object, Local variables, global variables, Common block, Stack, Symbol table.....

>> http://woodforest.tistory.com/11


728x90
반응형

'Career' 카테고리의 다른 글

RISC vs CISC  (0) 2016.06.07
File System  (0) 2016.06.06
Demand Paging  (0) 2016.06.05
Virtual Memory Management Strategy  (0) 2016.06.05
Deadlock  (1) 2016.06.04
Comments