My Mac has 18 GB of RAM, and most days it’s full. Swap was sitting at 24 of 25 GB when I wrote this. When things slow down, I open htop. It shows me 95 rows of Google Chrome Helper (Renderer), a pile of node processes and a lot of things I don’t recognise. What it doesn’t answer is the only question I have at that moment: what can I quit to get my RAM back?

So I wrote ramchk, a small Rust tool that answers exactly that.

What it looks like

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$ ramchk top
RAM  15.6 GB / 18.0 GB used (86%), 7.8 GB available
Swap 24.2 GB / 25.0 GB used

APP                              PROCS    MEMORY   %RAM    CPU%  KILL?
Google Chrome                       95   24.1 GB 133.9%   14.2%  safe
limactl (VM)                         3    7.0 GB  38.7%    9.1%  caution
node                                72    4.1 GB  22.9%    0.6%  caution
Slack                                8    2.2 GB  12.5%    0.7%  safe
ruby                                 9    749 MB   4.1%    2.7%  caution

One row per app, not per process. Chrome’s 95 processes are one line. Every row says whether it is safe to kill.

And when I just want a number back:

1
2
3
4
$ ramchk free 4G
To free 4.0 GB, quit:
  1. Google Chrome                    24.1 GB  [safe]  -> 31.9 GB available
     regular app: quitting is safe, save your work first

Running ramchk with no arguments opens an interactive view (built with ratatui). It shows memory gauges, the app list, a panel with the selected app’s processes and a “free up RAM” suggestion. Press x or k to quit the selected app, Enter to expand it into its processes, / to filter, s to change the sort and g to switch between grouped and per-process views.

ramchk’s interactive view: apps grouped and sorted by memory, Google Chrome expanded into its processes, with the selected process and a list of what to quit on the right

The interactive view, shown here with sample data.

Install

1
brew install coderhs/tap/ramchk

Or build from source (needs Rust):

1
curl -fsSL https://raw.githubusercontent.com/coderhs/ramchk/main/install.sh | sh

It runs on macOS and Linux. The macOS-specific parts are explained below; on Linux it falls back to the standard numbers.

How it works

The whole thing is about 1,400 lines of Rust. Most of the work went into four decisions.

1. Measure what Activity Monitor measures

The obvious number is RSS (resident set size), and it’s what most tools show. On macOS it’s misleading. RSS counts shared pages in every process that maps them, and it ignores memory the OS has compressed or swapped out. An app can look small in htop while being the reason your Mac is swapping.

Activity Monitor’s “Memory” column uses the physical footprint instead. You get it from proc_pid_rusage() with the RUSAGE_INFO_V2 flavor, which fills a struct with a ri_phys_footprint field. The function isn’t in the libc crate, so ramchk declares it and the struct by hand. When it fails (for example, a root process you can’t inspect), it falls back to RSS.

That’s why Chrome above shows 133.9% of RAM. The footprint includes compressed and swapped memory, so a single app can “use” more than the machine physically has. That number is the honest one: it’s what you get back when you quit.

2. Group processes into apps

A modern app is dozens of processes. Chrome’s renderers live at paths like:

1
/Applications/Google Chrome.app/Contents/Frameworks/Google Chrome Framework.framework/.../Google Chrome Helper (Renderer).app/...

ramchk groups by the outermost .app bundle in the executable path, so every helper nested inside Google Chrome.app adds up to “Google Chrome”. Processes that aren’t in a bundle (node, ruby, postgres) are grouped by name. --flat turns grouping off if you want one row per process.

3. Charge helpers to the app that asked for them

Some memory belongs to an app but runs from a system binary. Safari’s web content runs in WebKit processes under /System/Library/. Docker, Colima and Lima run their Linux VM in com.apple.Virtualization.VirtualMachine, which also lives there. By path alone, a 7 GB VM looks like part of macOS.

macOS keeps track of which app is “responsible” for each process; that’s how Activity Monitor attributes them. The call is responsibility_get_pid_responsible_for_pid(), a private but long-stable libsystem function. ramchk looks it up at runtime with dlsym, so the binary still runs if it ever disappears. It only does this for processes you own that run from /System/Library/. That’s how my Lima VM shows up as limactl (VM) instead of vanishing into the system bucket. Seeing it there is what made me lower Colima’s memory limit.

4. Say what is safe to kill

Every group gets one of four labels:

  • safe: a regular app. Quitting it is like pressing ⌘Q (save your work first).
  • caution: a background process or CLI tool you own, such as a dev server, a database or a VM. It’s killable, but something may depend on it. VMs get their own warning, because killing one stops every container inside it.
  • session: the terminal, shell and multiplexer ramchk is running in. ramchk walks up its own parent processes and marks them, so you can’t kill the window you’re typing in.
  • system: processes owned by another user, anything under /System/ or /usr/libexec/, and a short list of critical names (WindowServer, launchd, systemd, Xorg and so on). These are shown but can’t be killed from ramchk.

Only safe and caution rows can be killed. Killing sends SIGTERM first so apps can shut down cleanly. If something ignores it, the confirmation dialog offers F to send SIGKILL.

The “free 4G” planner

ramchk free <SIZE> accepts sizes like 4G, 512mb or 1.5 GiB. It works greedily: safe apps first, then caution, biggest first within each, skipping anything under 50 MB. It stops once the expected available memory reaches the target. Then it removes any pick that turned out to be unnecessary, so it never tells you to quit three apps when the biggest one alone would do.

Building it

The stack is small:

  • sysinfo for the process list, built with default-features = false and only the system feature, and refreshed only for memory, CPU, exe and command line.
  • ratatui for the interface, using the crossterm backend it re-exports.
  • clap for the top and free subcommands.
  • libc for kill, dlsym and the rusage call.

CPU percentages need two samples, so the CLI commands take two readings a moment apart before printing. The interactive view refreshes every two seconds.

With lto = true and strip = true, the universal macOS binary (Apple Silicon and Intel joined with lipo) is about 1.1 MB compressed.

Shipping it

Pushing a v* tag runs a GitHub Actions workflow that:

  1. builds the universal macOS binary,
  2. builds static Linux binaries for amd64 and arm64 with musl, on native runners for each,
  3. creates a GitHub release with the three tarballs,
  4. generates a Homebrew formula with the SHA-256 of each tarball, installs and tests it on a runner, then commits it to my homebrew-tap.

The formula picks the right prebuilt binary for the platform, so brew install takes a second and nobody needs a Rust toolchain.

One gotcha: my first tag didn’t trigger the workflow, because I pushed the workflow file and the tag together. GitHub only starts tag workflows that already exist in the repository. Deleting the remote tag and pushing it again fixed it.

What it doesn’t do

ramchk only shows memory and kills processes. It doesn’t purge caches, free “inactive” memory or anything like that, because on macOS those tricks mostly make the next minute slower. If you want to see what’s happening on your GPU instead, I wrote about htop-like tools for the GPU a while back.

The code is MIT-licensed and on GitHub. Issues and pull requests are welcome.