[OS] Signal, Memory Management

seunghyunΒ·2023λ…„ 3μ›” 2일
0

πŸ’»

λͺ©λ‘ 보기
5/15

UNIX Concurrency Mechanisms

Signals

πŸ’‘ μœ μ € 레벨의 핸듀링 λ©”μΉ΄λ‹ˆμ¦˜μ΄λΌκ³  μ‰½κ²Œ 말할 수 μžˆλ‹€.
A software mechanism that informs a process of the occurrence of asynchronous events (similar to a hardware interrupt)

βœ”οΈ Sending a signal

  • Kernel sends (delivers) a signal to a destination process by updating some state in the context of the destination process
  • Kernel sends a signal for one of the following reasons:
    • Kernel has detected a system event such as divide-by-zero (SIGFPE) or the termination of a child process (SIGCHLD)
    • Another process has invoked the kill system call to explicitly request the kernel to send a signal to the destination provess

βœ”οΈ Receiving a signal

  • A destination process receives a signal when it is forced by the kernel to react in some way to the delivery of the signal
  • Two possible ways to react
    • Default action (ignore, terminate the process, terminate & dump)
    • Catch the signal by executing a user-level function called a signal handler
  • Akin to a hardware exception handler being called in response to an asynchronous interrupt

Signal Concepts

βœ”οΈ A Signal is pending if it has been sent but not yet received

  • There can be at most one pending signal of any particular type
  • Signals are not queued
    • If a process has a pending signal of type k, then subsequent signals of type k that are sent to that process are discarded

βœ”οΈ A process can block the receipt of certain signals

  • Blocked signals can be delivered, but will not be received until the signal is unblocked

βœ”οΈ Kernel maintains pending and blocked bit vectors in the context of each process

Memory Management

Terminology

πŸ’‘ Frame
A fixed-length block (unit) of main memory

πŸ’‘ Page
파일의 고정적인 크기의 물리적 ꡬ성 λ‹¨μœ„
A fixed-length block of a program. It is a unit of transfer between secondary storage and main memory

πŸ’‘ Segment
파일의 가변적인 크기의 논리적 ꡬ성 λ‹¨μœ„
A variable-length block of a program. An entire segment may be copied into main memory (segmentation) or the segment may be divided into pages which can be individually copied into main memory (segmented paging)

Memory Organization

βœ”οΈ Logical Organization

  • Users view programs as a collection of modules
    • modules can be written and compiled independently
    • different protection (read-only, execute-only) are given to different modules
    • module level sharing corresponds to the user's way of viewing the problem
  • Segmentation is the tool that most readily satisfies requirement

βœ”οΈ Physical Organization

  • Computer memory is organized as main memory and secondary memory
  • Main memory is organized as a linear array of bytes
    • main memory available for a program may not be sufficient
    • programmer does not know how much space will be available

βœ”οΈ Memory management technique involve

  • Paging, segmentation, overlaying, and virtual memory, etc
  • Overlaying allows various modules to be assigned the same region of memory with a main program responsible for siwtching the modules in and out

Memory partitioning

가상메λͺ¨λ¦¬ 이전에 λ©”λͺ¨λ¦¬ 관리 기법 Memory partitioning 에 λŒ€ν•΄ μ‚΄νŽ΄λ³Έλ‹€.

βœ”οΈ Fixed partitioning

  • Physical Memoryλ₯Ό 고정적인 크기의 νŒŒν‹°μ…˜μœΌλ‘œ μ‹œμŠ€ν…œμ΄ 생성될 λ•Œ μͺΌκ°œλŠ” 방법이닀. ν•œ ν”„λ‘œμ„ΈμŠ€λŠ” μžμ‹ μ˜ 이미지보닀 μž‘κ±°λ‚˜ 큰 νŒŒν‹°μ…˜μ— λ‘œλ”©λ˜λŠ”λ° 이 방법은 κ΅¬ν˜„μ΄ μ‰½μ§€λ§Œ κ½€ λΉ„νš¨μœ¨μ μ΄λ‹€.
  • Problem
    • Internal Fragmentation : wasted space inside a fixed partition (λ‚­λΉ„λ˜λŠ” 곡간)
    • νŒŒν‹°μ…˜ μˆ˜μ— 따라 μ‹€ν–‰κ°€λŠ₯ν•œ ν”„λ‘œμ„ΈμŠ€μ˜ 수 (degree) κ°€ μ •ν•΄μ Έμžˆλ‹€.

βœ”οΈ Buddy System

  • Use both fixed and dynamic partitioning (μ ˆμΆ©μ•ˆ)

βœ”οΈ Dynamic partitioning

  • λ‹€μ–‘ν•œ 크기λ₯Ό κ°€μ§ˆ 수 μžˆλŠ” ν”„λ‘œμ„ΈμŠ€μ— 맞좜 수 μžˆλ‹€.
  • ν”„λ‘œμ„ΈμŠ€ 이미지에 λ”°λΌμ„œ ν”„λ‘œμ„ΈμŠ€κ°€ μš”μ²­ν•œ 만큼 ν• λ‹Ήν•œλ‹€. νŒŒν‹°μ…˜ μˆ˜μ— 따라 μ‹€ν–‰κ°€λŠ₯ν•œ ν”„λ‘œμ„ΈμŠ€μ˜ μˆ˜κ°€ μœ λ™μ μœΌλ‘œ λ³€ν•œλ‹€.
  • Problem
    • External Fragmentation (hole) : Memory becomes more and more fragmented
  • Compaction
    • Technique to overcome External Frangmentation
    • It is a overhead time consuming process, wasting CPU time

πŸ’‘ Process Image
ν”„λ‘œκ·Έλž¨ μ½”λ“œ, 데이터와 μˆœκ°„μ  process μƒνƒœ(λ ˆμ§€μŠ€ν„° λ‚΄μš©, ν”„λ‘œμ„Έμ„œ μƒνƒœ μ›Œλ“œ, 기타) 의 집합이며, μΌμ’…μ˜ μŠ€λƒ…μƒ·μ΄λΌκ³  μƒκ°ν•˜λ©΄ 될 λ“―ν•˜λ‹€. PCB μ—λŠ” 이미지와 process contextκ°€ μ €μž₯λœλ‹€
(μ•„λž˜ κ·Έλ¦Ό μ°Έκ³ )

Paging

πŸ’‘ Paging

  • Partition memory into equal fixed-size chunks (page frames)
  • Process image is divided into the same fixed-size chunks (pages)

πŸ’‘ Page Table
μ–΄λ–€ νŽ˜μ΄μ§€κ°€ μ–΄λ–€ νŽ˜μ΄μ§€ ν”„λ ˆμž„μ— λ‘œλ“œλ˜μ–΄μžˆλŠ”μ§€?

  • Contains the mapping between pages and frames
    • For each page in the process, PTE (page table entry) contains the frame number
  • Maintained by operating system for each process
  • CPU must access the page table to generate a physical address for the current process
  • TLB(MMU) 의 μ‚¬μš© 이유?

Segmentation

πŸ’‘ Segmentation

  • A program is divided into variable-length sgments
  • The address consists of segment number + offset
  • No internal fragmentation
  • But, external fragmentation
    • Similar to dynamic partitioning

πŸ”— Reference

ν”„λ‘œμ„ΈμŠ€ 이미지에 κ΄€ν•΄μ„œ μ°Έκ³ ν•œ λΈ”λ‘œκ·Έ
[KUOCW] 졜린 κ΅μˆ˜λ‹˜μ˜ 운영체제 κ°•μ˜λ₯Ό μˆ˜κ°•ν•˜κ³  μ •λ¦¬ν•œ λ‚΄μš©μž…λ‹ˆλ‹€. 잘λͺ»λœ λ‚΄μš©μ΄ μžˆλ‹€λ©΄ λŒ“κΈ€λ‘œ μ•Œλ €μ£Όμ‹œλ©΄ κ°μ‚¬ν•˜κ² μŠ΅λ‹ˆλ‹€ 😊

0개의 λŒ“κΈ€