Memory Management: Virtual Memory Flashcards

1
Q

What is the programmer’s ideal memory model?

A

he ideal memory for programmers would have these characteristics:
○Private
○Infinitely large
○Infinitely fast
○Nonvolatile
○Cheap

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the primary goals of an Operating System’s (OS) memory management?

A

OS memory management aims to achieve the following:
○ Main Memory Allocation: Determine the allocation of main memory, addressing:
■Where to locate the kernel in memory
■How many processes to allow concurrently
■How to allocate memory effectively to each process

○Protection: Ensure robust memory access control to prevent:
■Processes from corrupting the OS or other processes
■Processes from reading data belonging to other processes (privacy)

○Transparency: Create an abstraction of memory that hides the complexities of shared memory from processes, ensuring that:
■Processes remain unaware that they are sharing memory with others
■Memory management functions correctly irrespective of the number or location of running processes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How is memory protected to prevent one process from accessing the memory of another process or the kernel?

A

Memory protection is achieved by adding a check mechanism between the CPU and memory. This check ensures that every memory access request from the CPU is validated against the process’s allocated memory space. If a process attempts to access memory outside its designated region, an error is triggered, preventing unauthorized access

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is memory transparency in the context of operating systems?

A

Memory transparency means that programmers do not need to be concerned about:
○ The physical location of their program in memory.
○ The location or existence of other programs in memory
●The OS handles the mapping between virtual and physical addresses, allowing programs to run as if they have their own isolated memory space.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the typical memory location for the OS kernel and why?

A

The kernel is almost always located in low memory. On x86 architectures, this placement is primarily due to the location of interrupt vectors in low memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain the concept of virtual memory and its significance.

A

Virtual memory separates the memory addresses used by a program (virtual addresses) from the actual physical addresses in RAM. This separation is crucial because:

○ It allows processes to run even if they are only partially loaded in main memory.
○ It enables the OS to provide each process with the illusion of a large, private address space, even if the physical memory is shared.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Distinguish between virtual and physical address spaces.

A

○ Virtual Address Space: This is the address space that a program or programmer perceives. It represents the program’s view of memory.

○ Physical Address Space: This is the actual memory space available on the physical RAM chips. It represents the hardware’s view of memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Explain how the Memory Management Unit (MMU) facilitates virtual to physical address translation and protection.

A

The MMU is a hardware component that translates virtual addresses to physical addresses. It acts as a bridge between the CPU and memory, intercepting every memory access request from the CPU. Key functions include:
○ Address Translation: The MMU uses a mapping mechanism (typically a page table) to translate the virtual address generated by the CPU into the corresponding physical address.
○ Protection: It enforces protection rules by verifying if the process is allowed to access the requested memory location based on the process’s permissions. This prevents unauthorized memory access and ensures process isolation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Describe the base and bounds memory mapping scheme.

A

The base and bounds scheme uses a base register and a bounds register to define a process’s address space:

○ Base Register: Stores the starting address (base address) of the process’s allocated memory in physical memory.
○ Bounds Register: Holds the size of the allocated memory space, defining the upper limit (bound).
● The MMU adds the virtual address to the base address to get the physical address, ensuring it falls within the bounds

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Explain the problem of external fragmentation in memory management, particularly in the context of the base and bounds scheme.

A

External fragmentation occurs when enough free memory is available to satisfy a request, but it is scattered throughout physical memory in non-contiguous blocks, making it unusable for allocating to processes. This happens in base and bounds because as processes are loaded and removed, gaps (holes) are created in memory. Over time, these holes become too small to accommodate new processes, leading to wasted space and inefficient memory utilization

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Describe the process of a context switch in the base and bounds memory management scheme.

A

A context switch involves switching the CPU from executing one process to another. Key steps include:

1.Saving the Current Process State: The OS saves the current process’s registers (including the base and bounds registers) to its Process Control Block (PCB).

  1. Loading the New Process State: The OS loads the new process’s registers from its PCB into the CPU, effectively switching the base and bounds to point to the new process’s allocated memory area.
  2. Resuming Execution: The CPU continues execution from the instruction where the new process left off
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is internal fragmentation in the context of memory management?

A

Internal fragmentation occurs when a process is allocated more memory than it actually needs, leading to wasted space within the allocated memory block. Unlike external fragmentation, this wasted space is internal to the allocated block and cannot be easily reclaimed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Describe the concept of segmentation in memory management.

A

Segmentation divides a program’s address space into logical units called segments. These segments can represent different components of a program, such as:
○Code: Instructions of the program
○Heap: Dynamically allocated memory
○Stack: Function call stack and local variables
●Segments are stored separately in physical memory, and their location and size are tracked in a segment table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Explain how a virtual address is structured in a segmentation-based memory management scheme.

A

A virtual address in segmentation has two parts:
1.Segment Number (s): This part identifies the segment to which the address belongs.
2.Offset (d): This part specifies the location (offset) within the identified segment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How does the MMU translate virtual addresses to physical addresses in a segmentation-based system?

A

The MMU uses a segment table for address translation:
1. Index the Table: It uses the segment number (s) from the virtual address to index into the segment table.
2. Retrieve Base and Limit: It retrieves the base address and limit (size) of the segment from the corresponding segment table entry.
3. Check Bounds and Calculate: The MMU checks if the offset (d) is within the segment’s limit. If valid, it adds the offset to the base address to calculate the physical address

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How does segmentation provide a mechanism for sharing memory between processes?

A

Segmentation simplifies sharing by:
1. Shared Segment Creation: A segment containing the data to be shared is created.
2. Segment Table Mapping: Entries pointing to the shared segment are added to the segment tables of the processes that need access. This allows different processes to have their virtual addresses mapped to the same physical memory location, enabling shared access to the data in the shared segment

17
Q

What is memory compaction, and why is it necessary in segmentation?

A

Compaction is the process of rearranging segments in physical memory to eliminate external fragmentation. It involves:

1.Stopping Processes: Halting the execution of processes using the affected memory segments
2.Moving Segments: Copying the data from the segments to be moved to a new location in memory.
3.Updating Segment Table: Modifying the base addresses in the segment table to reflect the new locations of the moved segments

●Necessity: While segmentation can reduce internal fragmentation, it can still suffer from external fragmentation as segments vary in size. Over time, gaps between segments can become too small to be useful, leading to a need for compaction to create larger contiguous blocks of free space

18
Q

What are the primary disadvantages of memory compaction?

A

○ Expensive: It requires significant time and resources to stop processes, copy memory contents, and update segment tables.
○ Inefficient: Compaction can make subsequent memory allocation slower, especially if a segment needs to grow, potentially leading to further fragmentation and a need for more compaction

19
Q

Describe the fundamental concept of paging in memory management.

A

Paging divides both virtual and physical memory into fixed-size units:
○ Pages: Fixed-size blocks of virtual memory
○ Frames: Fixed-size blocks of physical memory. Often called “page frames”
● Pages and frames are the same size. The OS maintains a page table for each process, mapping virtual pages to physical frames

20
Q

Explain the structure of a virtual address in a paging-based system.

A

A virtual address in paging consists of:
1. Virtual Page Number (VPN): This identifies the page number within the virtual address space.
2. Offset: This specifies the location (offset) of the desired data within the identified page

21
Q

What is a page table, and what is its role in a paging-based memory management system?

A

A page table is a data structure used to translate virtual addresses to physical addresses. Key aspects:
○ Process-Specific: Each process has its own page table.
○ VPN as Index: The VPN portion of the virtual address acts as an index into the page table.
○ Frame Number Storage: Each entry in the page table stores the corresponding frame number (location of the page in physical memory)

22
Q

Why can page tables become excessively large, particularly in systems with vast address spaces?

A

Page tables can grow extremely large due to:
○ Direct Mapping: Every single page in the virtual address space potentially requires an entry in the page table, even if the page is unused.
○ Large Address Spaces: Modern systems use 32-bit or 64-bit addressing, resulting in a massive number of possible pages.
■Example: A 32-bit address space with 4KB pages would need 2^20 (1 million) page table entries.
■A 64-bit address space with 4KB pages would need 2^52 (petabytes) page table entries!

23
Q

How does the valid/invalid bit help manage page tables and address space usage?

A

The valid/invalid bit in each page table entry indicates whether a page is:
○ Valid: The page is currently in physical memory (RAM)
○ Invalid/Absent: The page is not currently in RAM, potentially because:
■ It has been swapped out to secondary storage.
■ It belongs to an unused part of the address space.
● This bit allows the OS to detect and manage pages that are not resident in RAM, preventing access to invalid or non-resident memory locations.

24
Q

Briefly explain how multi-level page tables address the issue of large page table size.

A

Multi-level page tables employ a hierarchical structure to manage large page tables more efficiently:
○ Hierarchy of Tables: They use a hierarchy of page tables where entries in higher-level tables point to lower-level tables.
○ On-Demand Allocation: Lower-level page tables are created and allocated only when needed, meaning that unused portions of the virtual address space do not consume physical memory for page table entries.
○ Invalid Bits in Higher Levels: Invalid bits in higher-level page tables indicate that an entire branch of the page table hierarchy does not exist, saving significant space

25
Q

What is internal fragmentation in paging, and why is it generally considered a less severe problem than external fragmentation?

A

Internal fragmentation in paging happens because the last page allocated to a process might not be fully utilized. If a process needs a size of memory that is not a multiple of the page size, the remaining space within the last page is wasted.

○ Less Severe: It’s generally considered less problematic than external fragmentation because the wasted space is limited to the size of a single page. With reasonably sized pages, this wastage is relatively small and does not significantly affect memory utilization