Quiz Flashcards
(34 cards)
Linux memory area
- a chunk of virtual memory mapped to a VM area space structure
task_struct
- The OS stores process state in a data structure called process control block. There is one per process
called task_struct in linux
mm_struct
kernel’s representation of a process’s address space
important fields:
-mm_users = # of processes using the address space
-mm_count = main reference count; when the kernel operates on an address space, it bumps up the reference counter. all users = 1 count
-mmap and mm_rb: contain all the memory areas in this address space
pgd_t *pgd: physical address of the first thing in the pgd??? do we add the PGD offset to the start address of the PGD?
all of the mm_struct structures of every process are strung together in a doubly linked list via the mmlist field
vm_area_struct
describes a single memory area over a CONTIGUOUS VIRTUAL ADDRESS INTERVAL in a given address space
each VMA possesses certain permissions and associated operations
each VMA structure can represent different types of memory areas
important struct fields:
-VMA start (lowest address in the interval)
-vm_end (first byte AFTER the highest address in the interval)
length in bytes of memory area = vm_end - vm_start
pgd
the page global directory (pgd) which consists of an array of pgd_t types. The entries in the pgd point to entries in the second level directory, the PMD. The second-level page table is the page middle directory (PMD), which is an array of pmd_t types. Entries in the PMD point to entries in the PTE. Final level = page table; consists of page table entries of type pte_t. Page table entries point to physical pages
Difference between segmentation fault and protection fault?
- segmentation fault occurs when request and address is not in the VMA
- protection fault occurs when you don’t have permissions to access that address
memory mapping
- structure of data indicating how memory is laid out
anonymous file
a temporary file without a descriptor
swap file (swap space)
- portion of the memory used for virtual memory
shared object
- a file that contains binary code and data that can be loaded into memory and linked dynamically
shared area
- virtual memory that are shared by more than one process and then can be used by multiple programs simultaneously. Although virtual memory allows processes to have separate address spaces, there are times when you need processes to share memory.
copy-on-write
- copy file and save new only when wrote to otherwise access the same file
dynamic memory allocator
Maintains an area of a process’s virtual memory, known as heap
allocated memory
- allocated memory is memory that is filled
How does the VM system used for the execve function?
The shell stores the environment in memory and passes it to the execve() system call. The child process inherits it as an array pointer called environ
What does the mmap function do?
- allows you to comb through a file like it is an array. Asks the kernel to create a new virtual memory area
implicit allocator
- implicit allocators implicitly allocates memory
- does not free the space
What does malloc do when it cannot satisfy a memory request?
- it returns a NULL
How does free work?
It accepts a pointer as its parameter. The free command does two things: The block of memory pointed to by the pointer is unreserved and given back to the free memory on the heap. It can then be reused by later new statements.
Throughput
- how many commands per second
aggregate payload
- this is all the payloads added together
internal fragmentation
- type of fragmentation where the payload is smaller than the block size it is going into
external fragmentation
- type of fragmentation where the payload…space cannot be filled
- to explain more the area that is free in the block cannot be filled by the payload
Why use dynamic memory allocation?
When you need a lot of memory. Typical stack size is 1 MB, so anything bigger than 50-100KB should better be dynamically allocated, or you’re risking crash. Some platforms can have this limit even lower.
When the memory must live after the function returns. Stack memory gets destroyed when function ends, dynamic memory is freed when you want.
When you’re building a structure (like array, or graph) of size that is unknown (i.e. may get big), dynamically changes or is too hard to precalculate. Dynamic allocation allows your code to naturally request memory piece by piece at any moment and only when you need it. It is not possible to repeatedly request more and more stack space in a for loop.