Linux Memory Management Flashcards

1
Q

What memory segments conform a linux process, and what are their purposes

A

The text segment: program executable code (instructions), the data segment: storage for program variables, and the stack segment: stores the call stack of the current program.

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

What system call allows a process to set the size of its data segment?

A

The brk system call, and it’s used by the malloc C library.

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

How does the stack of a process grow?

A

If the stack pointer is moved below the stack segment of a process a hardware fault occurs and the operating system lowers the bottom of the stack segment by one page

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

What does the stackc of a process contain initially?

A

It contains all the environment variables as well as the command line typed to the shell to invoke it.

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

How does linux manage the text segment of the same program running in different processes?

A

It supports shared text segments, were two process share the same text segment.

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

What is the purpose of memory-mapped files?

A

It maps a file onto a portion of a process’ address space so that the file can be read and written to as if it were a byte array in memory, making accesses much easier than I/O system calls.

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

What API allows creating memory-mapped files and what are the parameters?

A

Memory-mapped files are created using the mmap and unmmap syscalls, the parameters are addr: the address at which the file is mapped , len: nof bytes to map, prot: protection mode and flags: whether it’s sharable or not.

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

What’s the typical size of a linux process’ address space?

A

Each process typically gets 3GB for its virtual address space and 1GB reserved for its page tables adn other kernel data.

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

How is physical memory split in a linux system?

A

It’s split into three zones, DMA (Direct Memory Access), NORMAL which is regularly paged, and HIGH_MEM, not permanently mapped.

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

What information does the zone descriptor contain?

A

It contains memory utilization for each zone, number of active or inactive pages, low and high watermarks, and an array of free areas.

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

Describe the paging scheme used by linux

A

It’s a four-level paging scheme. Each virtual address is broken up into five fields: directory fields are used as indexes into the appropiate page directories of which one is a private for each process.

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

When and what parts of the kernel paged out?

A

No part of the kernel is paged out ever.

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

What’s the name of the algorithm used for memory allocation?

A

Buddy algorithm

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

Describe how the memory allocation algorithm works

A

Initially memory consists of a single contingous piece. When a request for memory comes in, it’s rounded up to a power of 2, and the available memory memory is split half by half until an appropriate size is matched

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

What’s a problem with the buddy algorithm and how is it solved?

A

It leads to considerable internal fragmentation because allocation requests off by just a little above the closest power of two are doubled up. To alliviate the slab allocator is used.

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

Describe how the slab allocator works

A

It takes chunks using the buddy algorithm but carves slabs (smaller units) from the allocated halves and manages them separately.

17
Q

What data structure describes the properties of a virtual memory area?

A

The vm_area_struct

18
Q

How is the copy on write mechanism implemented under the hood?

A

Memory areas (vm_area) are marked as read/write but copied memory pages are only marked as read. When the page is written to a page, a protection fault occurs and the kernel gives the process a copy of the page and marks it as read/write.

19
Q

What data structure holds information about all vm areas?

A

It’s called the mm_struct

20
Q

What is a memory page frame?

A

It’s a physical memory location the same size of a page, where a page is loaded into when it’s paged in.

21
Q

Where does the paging logic reside?

A

Partly in the kernel and partly in the page daemon (process 2). The page daemon runs periodically.

22
Q

Where is the text, stack, data and heap of a program paged out into?

A

They are paged out into their respective files on disk. Everything else is paged to the paging partition if present or one of the fixed-length paging files (swap area).

23
Q

Why is paging to a separate partition more efficient than paging to a paging file?

A
  1. There is no mapping between file blocks and disk blocks, physical writes can be of any size, not just the file block size, and the page is always written contigously to disk; with a paging file that may or may not be the case.
24
Q

What types of pages does the PFRA distinguish? Explain their differences.

A

Unreclaimable: locked or reserved pages (never paged out). Swappable: must be wrotten bacck to swap area before being reclaimed. Syncable must be written back to disk if marked as dirty. Discardable: pages that can be reclaimed immediately.

25
Q

What challenge do shared pages impose in the memory management system?

A

All page tables of all address spaces sharing the page must be updated synchronously.

26
Q

Define the term swappiness of the system.

A

The ratio of pages with backing store vs pages which need to be swapped out selected during PFRA.

27
Q

How many states can a page be in for the PFR Algorithm and which flags encode these states?

A

4 states, encoded by PG_active, and PG_referenced