Linux Memory Management Flashcards
What memory segments conform a linux process, and what are their purposes
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.
What system call allows a process to set the size of its data segment?
The brk system call, and it’s used by the malloc C library.
How does the stack of a process grow?
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
What does the stackc of a process contain initially?
It contains all the environment variables as well as the command line typed to the shell to invoke it.
How does linux manage the text segment of the same program running in different processes?
It supports shared text segments, were two process share the same text segment.
What is the purpose of memory-mapped files?
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.
What API allows creating memory-mapped files and what are the parameters?
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.
What’s the typical size of a linux process’ address space?
Each process typically gets 3GB for its virtual address space and 1GB reserved for its page tables adn other kernel data.
How is physical memory split in a linux system?
It’s split into three zones, DMA (Direct Memory Access), NORMAL which is regularly paged, and HIGH_MEM, not permanently mapped.
What information does the zone descriptor contain?
It contains memory utilization for each zone, number of active or inactive pages, low and high watermarks, and an array of free areas.
Describe the paging scheme used by linux
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.
When and what parts of the kernel paged out?
No part of the kernel is paged out ever.
What’s the name of the algorithm used for memory allocation?
Buddy algorithm
Describe how the memory allocation algorithm works
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
What’s a problem with the buddy algorithm and how is it solved?
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.