THINK FIRST·CODE LATER

← All labs

Linux in practice: measuring page faults

Problem

On Linux (VM, WSL or cloud instance), measure virtual-memory behaviour. Record commands and outputs.

  1. Write a small Java or C program that allocates an array of 1 GB and (a) touches one byte every 4,096 bytes, (b) touches every byte sequentially, (c) touches pages in random order. Run each with /usr/bin/time -v and record minor/major faults, time and maximum resident set size. Explain the numbers (how many faults for 1 GB with 4 KiB pages?).
  2. Read a large file twice with cat bigfile > /dev/null and measure both runs with /usr/bin/time -v. Explain the difference using the page cache.
  3. Run vmstat 1 while starting several memory-hungry programs until the system is under pressure (in a VM!). Identify the columns that show swapping and I/O wait. If available, read /proc/pressure/memory.
  4. Check cat /proc/sys/vm/swappiness, swapon --show and whether zram is used (zramctl). What would you configure on an 8 GB edge device running inference services, and why?

Work it out on paper, in a document or here, then compare with the model answer. Your answer stays in your browser — it is never sent to or stored on the server.