[OS] Signal, Memory Management

seunghyunยท2023๋…„ 3์›” 2์ผ
0

๐Ÿ’ป

๋ชฉ๋ก ๋ณด๊ธฐ
5/16

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] ์ตœ๋ฆฐ ๊ต์ˆ˜๋‹˜์˜ ์šด์˜์ฒด์ œ ๊ฐ•์˜๋ฅผ ์ˆ˜๊ฐ•ํ•˜๊ณ  ์ •๋ฆฌํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. ์ž˜๋ชป๋œ ๋‚ด์šฉ์ด ์žˆ๋‹ค๋ฉด ๋Œ“๊ธ€๋กœ ์•Œ๋ ค์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค ๐Ÿ˜Š

profile
๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ป๐ŸŽฎ

0๊ฐœ์˜ ๋Œ“๊ธ€