Memapi
Memapi
Memapi
Code
Stack
Recap: Process address space
- If all processes
Code have same address space, how they map to actual memory?
- Address space represents memory state of
- Architecture support used by OS to perform memory virtualization i.e.,
Data (Static)
a process
translateHeap
virtual address to physical address (will revisit)
- Address space layout is the same for all
- What are the responsibilities of the OS during program load?
the processes
- HowFree CPU register state is changed?
- Exact layout can be decided by the OS,
- Creating address space, loading binary, updating the PCB register state
conventional layout is shown
- What is the role of OS in dynamic memory allocation?
Stack
- Maintain the address space and enforce access permissions
User API for memory management
Library API USER
malloc( )
calloc( )
- Generally, user programs
free( )
…..
use library routines to
allocate/deallocate
System calls Code
(brk, mmap, ...) memory
Data
- OS provides some address
PCB Heap
space manipulation system
Memory state calls
Free
OS
Stack
User API for memory management
Library API USER
malloc( )
calloc( )
- Generally, user programs
free( )
Can the size of segments change at runtime? If yes,
-…..
use which
libraryones
routines
and to
how?
- HowSystem
can calls allocate/deallocate
we know about the segment layout at program load and runtime?
Code
- How(brk,
tommap,
allocate
...) memory
memory chunks with different permissions?
Data
- What is the structure of PCB memory state?
- OS provides some address
PCB Heap
space manipulation system
Memory state calls (today’s agenda)
Free
OS
Stack
Dynamically sizing the segments (UNIX)
Code
- Code segment size and initialized data
Data (initialized) segment size is fixed (at exe load)
Data (uninitialized)
Heap
Free
Stack
Dynamically sizing the segments (UNIX)
Code
- Code segment size and initialized data
Data (initialized) segment size is fixed (at exe load)
Data (uninitialized) - End of uninitialized data segment (a.k.a.
Heap
BSS) can be adjusted dynamically
Free
Stack
Dynamically sizing the segments (UNIX)
Code
- Code segment size and initialized data
Data (initialized) segment size is fixed (at exe load)
Data (uninitialized) - End of uninitialized data segment (a.k.a.
Heap
BSS) can be adjusted dynamically
- Heap allocation can be discontinuous,
Free
special system calls like mmap( ) provide
the facility
Stack
Dynamically sizing the segments (UNIX)
Code
- Code segment size and initialized data
Data (initialized) segment size is fixed (at exe load)
Data (uninitialized) - End of uninitialized data segment (a.k.a.
Heap
BSS) can be adjusted dynamically
- Heap allocation can be discontinuous,
Free
special system calls like mmap( ) provide
the facility
Stack - Stack grows automatically based on the
run-time requirements, no explicit system
calls
Sliding the BSS (brk, sbrk)
int brk(void *address);
- Increments the program’s data space by size bytes and returns the old value
of the end of bss
- sbrk(0) returns the current location of BSS
Finding the segments
- etext, edata and end variables mark the end of text segment, initialized data
segment and the BSS, respectively (At program load)
- sbrk(0) can be used to find the end of the data segment
- Printing the address of functions and variables
- Linux provides the information in /proc/pid/maps
User API for memory management
Library API USER