W6 - Memory Management (Part I) Flashcards

(34 cards)

1
Q

Why is memory management necessary?

A

The computer memory is shared by many processes.
The compiler has to produce code without knowing how many other processes there are, and where they are in memory.

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

Main requirements for memory management

A

1) Relocation
2) Protection & Sharing
3) Each process working in its own address space.

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

What is meant by relocation in memory management?

A

The ability to move the program from one place in memory to another.

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

How many bytes does the stack pointer move when pushing or popping data?

A

4 bytes on a 32-bit system (e.g., x86)

8 bytes on a 64-bit system (e.g., x86-64)
Because the stack stores word-sized values:

Word = 4 bytes (32-bit)

Word = 8 bytes (64-bit)

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

What is a virtual/logical address space in a process?

A

It’s the range of virtual memory addresses a process can use, which are translated to actual physical memory by the OS.
Each process gets a large, private virtual address space (e.g. too little on 16-bit, 4 GB on 32-bit, many TB on 64-bit).

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

Base and limit registers

A

Base: Smallest legal physical memory address for a process.
Limit: The size of the range.

These two form a section of physical memory a process is allowed to occupy, and if this process attempts to access something outside the range an addressing error occurs (it causes a trap, so we switch into kernel mode).

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

Logical/Virtual Address

A

Reference to a memory location, independent of the current use of memory. Instructions issued by CPU reference logical addresses (e.g. arguments for LOAD)

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

Physical/Absolute Address

A

The actual location in memory. It’s physical memory.

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

Address translation

A

Translating logical address into physical address using the page table.

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

Who can check the page table

A

The CPU and the OS

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

How does fixed partitioning work

A

Memory is divided into contiguous blocks at boot time, which don’t change. Requires a base register, which gets loaded by OS at context switch.

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

Problems with fixed partitioning.

A

Since partitions are fixed, programs can potentially run out of space. You also deal with internal fragmentation, where memory is reserved for a process which we are not fully using.

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

How does dynamic partitioning work

A

Partitions are created as programs are loaded. Requires a base register and limit register.

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

What kind of fragmentation do we encounter with dynamic partitioning?

A

External fragmentation. Unused memory is broken up into small regions that are unuasble. We don’t get internal fragmentation though!

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

What’s a better solution over partitioning?

A

Pages.

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

How does paging work?

A

Physical address space is split into equal sized frames.
Logical address space is divided into equal size pages.
Page size = Frame size.
Program gets loaded into available pages. Pages get mapped to frames, this is recorded on the page table.

17
Q

Describe the uniqueness of page numbers.

A

Unique for each process, since each process gets its own page table.

18
Q

What kind of fragmentation do we get with paging?

A

Some internal fragmentation. This gets worse if you pick larger frame sizes / page sizes.

19
Q

How does swapping a page out of main memory work?

A

The page no longer corresponds to the frame in memory. It corresponds to a specific location in the disk instead, being stored in one or more blocks.

20
Q

In the context of paging, what do physical addresses and logical addresses represent?

A

Physical -> Frame
Logical -> Page

21
Q

Advantages of paging

A

We eliminate external fragmentation. If a process needs another page, just give it any frame in memory. This is only possible because its Random Access Memory, optimized to be accessed anywhere. (In a disk you’d have to rotate, seek, …).

It’s easy to implement.

Easy to model protection and sharing.

Easy to allocate physical memory.

Naturally opens up the possibility for Virtual Memory (swapping pages to disk).

22
Q

Why is page size a trade off?

A

Too big and internal fragmentation becomes more problematic.
Too small and we end up with too many pages. We need to store data in memory for them (page table), and CPU spends time translating too.
As memory gets cheaper, we can increase it

23
Q

Page table

A

Maps logical addresses (pages) to physical addresses (frames). It is indexed by page number.

24
Q

How would memory sharing work?

A

Multiple processes each have pages that translate to the exact same frames, letting them access the same data.

25
How does paging protect processes?
Each process only has access to its allocated frames.
26
Logical addresses break down into what two components?
Page number (Most significant bits / left side) Offset, which is address within page (Least significant bits / right side)
27
We know the page number component of a logical address is made of X bits. What can we calculate from this?
The number of pages. 2^X
28
We know the offset component of a logical address is made of Z bits. What can we calculate from this?
The size of each page. 2^Z.
29
How do you actually extract the page number from the logical address.
You've got page number (X bits) on the left, and offset (Y bits) on the right. Shift the logical address to the left Y times (divide by 2^Y). Your page number is on the right hand side and can be read. You can do the same in reverse to form a logical address.
30
How can you build a logical address out of a page number (X bits) and a offset (Y bits)
Take your page number, and right shift it Y times (it creates enough space for your offset of Y bits). You do this by dividing by 2^Y. The remaining space is padded with Y zeros. Just add your offset now.
31
What data structure do we use for page tables?
Arrays.
32
What does a page table entry look like?
A bit sequence, where we have a bunch of page flags and the frame number. Flags indicate things like if page is in memory or disk, if it has changed, if it is read only, ....
33
How does address translation work?
Use the page number component of the logical address, and use a page table (special registers used to do this, page table stored in register) to find the frame number. Page number X Page table entry size = The exact page table entry you want, containing your frame number. Take your frame number, and multiply it by the size of the frame (each frame is 4096 bytes) to jump to the frame you want. Add your offset so you can select the exact byte out of 4096 that you want.
34
Problems with paging
PAGE TABLE IS LARGE. >> 4KB pages and 32 bit addresses means 4MB per page table. That's an additional 4MB per process. It gets even worse for 64 bit addresses. MEMORY ACCESS IS SLOW. >> One lookup in page table, and one lookup to access data in memory.