- demo: browser memory use
- demo: buffer cache use
- demo: cache memory and cache misses / duration
- demo: memory leak
running software needs memory
- CPU interacts with memory: read / featch, write
- instructions / code and actual data
who uses memory:
- kernel (in kernel mode)
- processes / applications (in user mode)
memory relevance:
- functionality: software requires memory to run
- correctness: improper use leads to crashes, bugs, exploits
- security: memory can be exploited: information leaks, control flow hijack
- performance: proper placement of data in memory and proper operations increases performance
- efficiency: memory use can be wasteful; a clever design reduces memory use
CPU communicates with memory
data and code are loaded from storage into memory
data is flushed from storage to disk
memory is faster than disk
diagram: memory and storage
storage may be absent - load from network
storage is used for persistence
the buffer cache stores recent storage data in memory
allocate: a new chuck or increase an existing chunk
deallocate: a chunk or decrease an existing chunk
diagram: allocation and deallocation
use: address and access: point to address + read from / write to address
diagram: addressing and accessing
demo: memory operations: allocation/ and memory-access/
at load time
at runtime
at load time: allocate + populate (from executable)
- static allocation
at runtime: allocate
- eventually populate with program generated information
- dynamic allocation
diagram: memory allocation: static (load time) and dynamic (runtime)
demo: program: dynamic allocation and static allocation snippets
memory areas:
- different permissions
- different types: static, dynamic
- different sources of input
demo: run pmap on static and dynamic executable
diagram: the process virtual address space
table: different memory areas with different properties
from executable to memory
diagram: from executable sections to process areas
see executable sections: size, protections
static non-PIE binary
demo: GDB: info proc mappings
bss region doesn't consume space in the executable
demo: dynamic binary
no connection to the executable
stack + dynamic allocation - malloc()
diagram: heap, stack, mapped memory regions
demo: increase stack
malloc() uses an allocator
- provided by libc
- heap: issues: large size, fragmentation, concurrency
demo: malloc() vs different calls: brk() vs mmap()
- Memory is essentials for running software.
- Memory stores instructions and data used by the CPU.
- Memory is allocated and used.
- Memory allocation is static (happens at load-time) or dynamic (happens at runtime).
- The application / process uses a process address space: a list of memory areas.
- Dynamic allocation may be backed by heap or memory mapping.