OSTEP Chapter 21

ECE 3600, Fall 2022


Table of Contents


1. Memory Hierarchy

(fastest) L1 cache, L2 cache, L3 cache, main memory, disk/swap (slowest)

page table present bit, page fault


2. Exercises

See the book for exercises using mem.c and vmstat
$ /sbin/swapon -s
Filename                                Type            Size    Used    Priority
/dev/md1                                partition       7806972 827184  -2

$ cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/md1                                partition       7806972 827184  -2

$ top
top - 12:11:30 up 10 days,  4:36,  6 users,  load average: 0.09, 0.42, 0.42
Tasks: 286 total,   1 running, 220 sleeping,   4 stopped,   0 zombie
%Cpu(s):  1.4 us,  1.1 sy,  0.0 ni, 97.4 id,  0.1 wa,  0.0 hi,  0.1 si,  0.0 st
KiB Mem : 16188300 total,  2665948 free,  1447960 used, 12074392 buff/cache
KiB Swap:  7806972 total,  6979788 free,   827184 used. 14136572 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
11226 perry     20   0   44216   3936   3264 R  12.5  0.0   0:00.03 top
 2488 perry     20   0 3944640 334564  74652 S   6.2  2.1 275:49.35 gnome-shell
    1 root      20   0  225676   6100   3968 S   0.0  0.0   2:11.45 systemd
    2 root      20   0       0      0      0 S   0.0  0.0   0:00.33 kthreadd
...

3. Example

In one window:
$ ./mem 12000                                    <<-- time 1
allocating 12582912000 bytes (12000.00 MB)
  number of integers in array: 3145728000
loop 0 in 5604.98 ms (bandwidth: 2140.95 MB/s)
loop 1 in 2092.22 ms (bandwidth: 5735.54 MB/s)
loop 2 in 2088.83 ms (bandwidth: 5744.85 MB/s)
loop 3 in 2103.87 ms (bandwidth: 5703.77 MB/s)
^C                                               <<-- time 2
$
In another window:
$ vmstat 1
procs -----------memory----------    ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd    free    buff   cache   si   so    bi    bo   in   cs us sy id wa st
 1  0 827184 8436620 4084564 2224596    0    2   118    61    3    4  1  1 97  0  0
 0  0 827184 8436496 4084564 2224596    0    0     0     0  181  534  1  0 99  0  0
 0  0 827184 8436364 4084564 2224588    0    0     0     0  307 1054  2  1 96  0  0
 1  0 827184 8441324 4084564 2219468    0    0     0     0  318 1452  4  1 96  0  0
 1  0 827184 7307468 4084564 2224956    0    0     0   127  380  991  8  7 85  0  0  <<-- time 1
 1  0 827184 5073352 4084564 2225108    0    0     0     0  459  773 14 12 74  0  0
 1  0 827184 2856232 4084564 2224596    0    0     0     0  468  503 14 12 74  0  0
 1  0 827184  616916 4084564 2224596    0    0     0     0  463  467 15 11 74  0  0
 2  0 827184  165356 3384604 1191244    0   40     0    43  798 1245 13 20 66  0  0
 2  0 838704  153824 1897456  534920    0 11480  168 11516 1045 1368 13 25 62  0  0
 1  0 840496  258872 1662480  511156    0 1716   794  1717  700  952 25  4 71  1  0
 1  0 840496  258624 1662500  511664    0    0   264     0  458  499 26  0 74  0  0
 1  0 840496  258624 1662632  511664    0    0   132     0  469  468 25  0 74  0  0
 1  0 840496  258624 1662632  511664    0    0     0     0  439  504 25  0 74  0  0
 1  0 840496 10478440 1662632 513316    0    0  1652     0  490  817 17  9 74  0  0  <<-- time 2
 0  0 840496 12568236 1662632 513384    0    0    60     0  253  609  0  3 97  0  0
 0  0 840496 12573568 1662632 507976    0    0     0     3  183  570  1  0 99  0  0
 0  0 840496 12568112 1662632 513268    0    0     0     0  245  980  2  1 98  0  0
^C
$