Memory Managementإدارة الذاكرة

الشريحة 1 من 13

مقدمة الفصل

تفاصيل المصدرشرائح الفصل 3a · الشريحة ⁦2⁩
المصدر
شرائح الفصل 3a · الشريحة ⁦2⁩

The need for memory managementالحاجة لإدارة الذاكرة

  • Applications are demanding more and more memory — there is never enough.
  • Memory management involves swapping blocks of data from secondary storage.
  • Memory I/O is slow compared to a CPU → the OS must cleverly time the swapping to maximise the CPU's efficiency.
  • Goal: a reasonable supply of ready processes to consume available processor time (slide 4).
تفاصيل المصدرشرائح الفصل 3a · الشرائح ⁦3–4⁩
المصدر
شرائح الفصل 3a · الشرائح ⁦3–4⁩

Memory management requirementsالمتطلبات الخمسة

تذكّر معنى كل متطلب.

  1. Relocation
  2. Protection
  3. Sharing
  4. Logical organisation
  5. Physical organisation

Figure 7.1 — addressing requirements for a process (slide 8)

  • From low to high (increasing address values): Process Control Block (process control information), Program (entry point to program; a branch instruction refers within it), Data (a reference to data from the program), Stack (current top of stack).

Why must memory protection be checked at run time rather than at compile time?

تفاصيل المصدرشرائح الفصل 3a · الشرائح ⁦5, 6, 8, 9, 10, 11, 12⁩
المصدر
شرائح الفصل 3a · الشرائح ⁦5, 6, 8, 9, 10, 11, 12⁩

Frame, page and segmentالإطار والصفحة والقطعة

Memory management terms: frame, page, segment

Table 7.1 Memory Management Terms (slide 7)
TermالمصطلحDescription (Table 7.1, slide 7)الوصف
FrameFixed-length block of main memory
PageFixed-length block of data in secondary memory (e.g. on disk)
SegmentVariable-length block of data that resides in secondary memory

Which memory-management term means a VARIABLE-length block of data that resides in secondary memory?

تفاصيل المصدرشرائح الفصل 3a · الشريحة ⁦7⁩
المصدر
شرائح الفصل 3a · الشريحة ⁦7⁩

Fixed partitioningالتقسيم الثابت

  • Partitioning is an early method (pre-virtual memory, not used much now); virtual memory has evolved from the partitioning methods.
  • Types (slide 14): fixed partitioning, dynamic partitioning, simple paging, simple segmentation, virtual memory paging, virtual memory segmentation.
Equal-size fixed partitions
Any process whose size is less than or equal to the partition size can be loaded into an available partition; the OS can swap a process out if none are in a ready or running state.

Problems (slide 16)

  • A program may not fit in a partition → the programmer must design the program with overlays.
  • Main memory use is inefficient: any program, no matter how small, occupies an entire partition → internal fragmentation.

With equal-size fixed partitions of 8 MB, a 2 MB program occupies a whole partition. What is the wasted space inside the partition called?

تفاصيل المصدرشرائح الفصل 3a · الشرائح ⁦13–16⁩
المصدر
شرائح الفصل 3a · الشرائح ⁦13–16⁩

Unequal partitions and placementالأقسام غير المتساوية

Partitioning and fixed partitioning

  • Unequal-size partitions lessen both problems but don't solve them completely: programs up to 16M without overlay (Fig 7.3b); smaller programs in smaller partitions → less internal fragmentation.
Figure 7.3 — memory assignment for fixed partitioning (slide 19)

(a) One process queue per partitionطابور لكل قسم

  • New processes go into a separate queue for each partition.

(b) Single queueطابور واحد

  • All new processes wait in one queue and are sent to any partition.
Placement algorithm (slide 18)

Equal-size

  • Placement is trivial (no options)

Unequal-size

  • Assign each process to the smallest partition within which it will fit
  • A queue for each partition
  • Minimize wasted memory within a partition

Remaining problems with fixed partitions (slide 20)

  • The number of active processes is limited by the pre-determined number of partitions.
  • A large number of very small processes will not use the space efficiently.

With unequal-size fixed partitions, where is a process placed?

تفاصيل المصدرشرائح الفصل 3a · الشرائح ⁦17, 18, 20⁩
المصدر
شرائح الفصل 3a · الشرائح ⁦17, 18, 20⁩

Dynamic partitioningالتقسيم الديناميكي

Dynamic partitioning
Partitions are of variable length and number; a process is allocated exactly as much memory as required.
External fragmentationالتجزئة الخارجية
Memory external to all processes is fragmented.
Compactionالضغط
The OS moves processes so that they are contiguous — resolves external fragmentation but is time consuming and wastes CPU time.

What is the cost of compaction?

تفاصيل المصدرشرائح الفصل 3a · الشرائح ⁦21–22⁩
المصدر
شرائح الفصل 3a · الشرائح ⁦21–22⁩

Placement algorithmsخوارزميات الوضع

Dynamic partitioning placement (slides 23–25)
AlgorithmالخوارزميةHow it choosesطريقة الاختيارNotes on the slidesملاحظات الشرائح
Best-fitThe block closest in size to the request
  • Worst performer overall
  • leaves the smallest fragments
  • compaction must be done more often
First-fit
  • Scans from the beginning
  • the first block large enough
  • Fastest
  • processes pile up at the front end, which must be searched over
Next-fitScans from the location of the last placement
  • Often allocates at the end, breaking up the largest block
  • compaction needed to get a large block at the end

Which placement algorithm scans memory from the beginning and takes the first block that is large enough?

تفاصيل المصدرشرائح الفصل 3a · الشرائح ⁦23–26⁩
المصدر
شرائح الفصل 3a · الشرائح ⁦23–26⁩

Relocation and types of addressإعادة التوطين

Relocation, addresses and registers

  • When a program is loaded, the actual (absolute) memory locations are determined.
  • A process may occupy different absolute memory locations during execution — because of swapping and compaction.
Logicalمنطقي
Reference to a memory location independent of the current assignment of data to memory.
Relativeنسبي
Address expressed as a location relative to some known point.
Physical or absoluteفعلي (مطلق)
The actual location in main memory.
تفاصيل المصدرشرائح الفصل 3a · الشرائح ⁦27–28⁩
المصدر
شرائح الفصل 3a · الشرائح ⁦27–28⁩

Base and bounds registersالأساس والحدود

Relocation, addresses and registers

Base registerمسجل الأساس
Starting address for the process.
Bounds registerمسجل الحدود
Ending location of the process.
  • These values are set when the process is loaded or when the process is swapped in.

During execution (slide 31)

  1. 1

    The base register is added to a relative address to produce an absolute address.

  2. 2

    The resulting address is compared with the bounds register.

  3. 3

    If the address is not within bounds, an interrupt is generated to the operating system.

المسألة

Illustrative numbers (not from the slides): base register = 5000, bounds register = 5800, relative address = 300.

Base register = 12000, bounds register = 12500. A process uses relative address 700. What happens?

تفاصيل المصدرشرائح الفصل 3a · الشرائح ⁦30–31⁩
المصدر
شرائح الفصل 3a · الشرائح ⁦30–31⁩

Simple pagingالتصفيح

Simple paging
Partition memory into small equal fixed-size chunks and divide each process into the same size chunks: process chunks are pages, memory chunks are frames; page size = frame size.

المسألة

Slide 32: program size 16 M, frame (page) size 8 M.

الصيغة

# of pages = program size / page size

خطوات الحل

  1. 16 / 8

النتيجة

2 pages.

Paging (slide 38): a 16-bit logical address = 6-bit page # + 10-bit offset
ItemValue
Logical address000001 0111011110 (page 1, offset 0111011110)
Process page table
  • page 0 → 000101
  • page 1 → 000110
  • page 2 → 011001
Physical address000110 0111011110 (frame 000110 + the same offset)
  • The OS maintains a page table for each process: the frame location for each page.
  • A memory address = page number + offset within the page.

A 24 KB program is loaded with simple paging and a 4 KB page size. How many pages does it have?

تفاصيل المصدرشرائح الفصل 3a · الشرائح ⁦32, 33, 34, 35, 38⁩
المصدر
شرائح الفصل 3a · الشرائح ⁦32, 33, 34, 35, 38⁩

Simple segmentationالتقطيع

  • A program can be subdivided into segments; segments may vary in length; there is a maximum segment length.
  • Addressing: a segment number and an offset.
  • Segmentation is similar to dynamic partitioning.

Pagingالتصفيح

  • Equal fixed-size chunks
  • Address = page number + offset

Segmentationالتقطيع

  • Segments may vary in length (with a maximum)
  • Address = segment number + offset
  • Similar to dynamic partitioning

Simple segmentation is said to be similar to which method?

تفاصيل المصدرشرائح الفصل 3a · الشرائح ⁦36–37⁩
المصدر
شرائح الفصل 3a · الشرائح ⁦36–37⁩

الخلاصة

تفاصيل المصدر
المصدر
شرائح الفصل 3a

خريطة الفصل

    1. 1مقدمة الفصل
    1. 2The need for memory managementالحاجة لإدارة الذاكرة
    1. 3Memory management requirementsالمتطلبات الخمسة
  1. Memory management terms: frame, page, segmentمصطلحات: الإطار والصفحة والقطعة

    1. 4Frame, page and segmentالإطار والصفحة والقطعة
  2. Partitioning and fixed partitioningالتقسيم والتقسيم الثابت

    1. 5Fixed partitioningالتقسيم الثابت
    2. 6Unequal partitions and placementالأقسام غير المتساوية
  3. Dynamic partitioning and external fragmentationالتقسيم الديناميكي والتجزئة الخارجية

    1. 7Dynamic partitioningالتقسيم الديناميكي
  4. Placement algorithms: best-fit, first-fit, next-fitخوارزميات الوضع: الأنسب والأول والتالي

    1. 8Placement algorithmsخوارزميات الوضع
  5. Relocation, addresses and registersإعادة التوطين والعناوين والمسجلات

    1. 9Relocation and types of addressإعادة التوطين
    2. 10Base and bounds registersالأساس والحدود
    1. 11Simple pagingالتصفيح
    1. 12Simple segmentationالتقطيع
    1. 13الخلاصة