Lecture 06
Lecture 06
Lecture topic
Memory Management
Michael Kerrisk, The LINUX Programming Interface, 1st Edition, No Starch Press ISBN-13 978-
1593272203
virtual address
Physical address – address seen by the memory unit
Major part of swap time is transfer time; total transfer time is directly
proportional to the amount of memory swapped
interrupt vector
User processes then held in high memory
Relocation registers used to protect user processes from each other, and
from changing operating-system code and data
Base register contains value of smallest physical address
Multiple-partition allocation
Hole – block of available memory; holes of various size are scattered
throughout memory
When a process arrives, it is allocated memory from a hole large
enough to accommodate it
Operating system maintains information about:
large block
Compaction is possible only if relocation is dynamic, and is done at
execution time
I/O problem
Page number (p) – used as an index into a page table which contains
base address of each page in physical memory
Page offset (d) – combined with base address to define the physical
memory address that is sent to the memory unit
Memory can leak when your app references objects that it no longer needs to
perform the desired task. Referencing these objects prevents the garbage
collector from reclaiming the memory used.
dotnet-counters ps
Examine managed memory usage
34
When analyzing possible memory leaks, you need access to the app's memory
heap to analyze the memory contents. Looking at relationships between
objects, you create theories as to why memory isn't being freed. A common
diagnostic data source is a memory dump on Windows or the equivalent core
dump on Linux.
Generate memory dump
37
When analyzing possible memory leaks, you need access to the app's memory heap to
analyze the memory contents.
Once the dump is collected, you should have sufficient information to diagnose the failed
process. If the failed process is running on a production server, now it's the ideal time for
short-term remediation by restarting the process.
dumpheap -stat
Restart the failed process
40
gcroot 00007f6ad09421f8
how and why the object is rooted:
Class assignment
42
Shared code
One copy of read-only (Reentrant) code shared among processes
The pages for the private code and data can appear anywhere in
Hierarchical Paging
50
A logical address (on 32-bit machine with 1K page size) is divided into:
a page number consisting of 22 bits
a page offset consisting of 10 bits
Since the page table is paged, the page number is further divided into:
a 12-bit page number
a 10-bit page offset
12 10 10
where pi is an index into the outer page table, and p2 is the displacement within the
page of the outer page table
Address-Translation Scheme
51
Three-level Paging Scheme
52
Hashed Page Tables
53
same location
extracted
Hashed Page Table
54
Inverted Page Table
55
main program
procedure
function
method
object
local variables, global variables
common block
stack
symbol table
arrays
User’s View of a Program
58
Logical View of Segmentation
59
4
1
3 2
4
reside in memory
limit – specifies the length of the segment
Protection
With each entry in segment table associate:
Group9 Group10
Reference
70
Michael Kerrisk, The LINUX Programming Interface, 1st Edition, No Starch Press
ISBN-13 978-1593272203