smem on Termux: Diagnosing Memory Pressure Without Root
TL;DR: smem is not in Termux's package repos, and pip install smem pulls an unrelated IPC library — a trap we hit so you don't have to. The verified path: pkg install python, grab the official smem 1.5 script from the selenic.com Mercurial repo, and run it with python. Expect a narrow view: Android's SELinux and hidepid mean Termux only sees its own processes, and "swap" on a phone is zram, not disk.
Why does every Termux memory tutorial quietly skip smem? I used to think it was an oversight. Now I know better: I spent an afternoon trying to install it, and the tool isn't there.
It started the usual way. The phone had been running a long Termux session — a python scraper, an sshd, a proot-distro instance chewing through a recon script — and everything had gone sluggish. On the desktop I'd have reached for smem -k -rs swap and had the answer in one screen. On the phone, I had a question and no tool. This is the story of how that afternoon went, including the two wrong turns that cost me the first hour.
House rules first: this is about your own phone and your own Termux. Memory forensics on a device that isn't yours is a crime, full stop. Everything below assumes the terminal belongs to you.
The Itch
Termux runs as a normal Android app, unprivileged, no root. That one fact decides everything that follows, so let's park it here: you cannot see other apps' memory from Termux, and you cannot create swap. What you can do is diagnose the memory behavior of your own Termux processes — which is exactly what a long pentest session needs when things start crawling.
Wrong Turn One: pkg install smem
First instinct, same as the desktop:
pkg install smem
Result: Unable to locate package smem. I checked the package index twice, then a third time by hand. smem is simply not in the Termux repos — not in the main repository, not in x11-packages, not as an arch-independent package. We pulled the official package listing and grepped it: nothing. If a tutorial tells you to pkg install smem, it's copy-paste from a desktop article, and it will fail on your phone.
pkg search smem confirms it the polite way:
pkg search smem
Zero hits. Fine. Plan B.
Wrong Turn Two: pip install smem
smem is a Python script, so pip felt like the natural next stop. It is a trap, and I want you to read this twice: the smem package on PyPI is not the memory reporting tool. It's an unrelated IPC/shared-memory library for Python. Same name, different universe. pip install smem succeeds, imports fine, and has nothing to do with swap, USS, PSS, or /proc.
I only caught it because the installed module didn't ship a smem command at all. If you're reading this before trying it: don't. The name on PyPI belongs to someone else's project, and there is no official pip release of Matt Mackall's smem.
The Catch: What "Swap" Even Means on Android
Before hunting for the tool, it's worth asking what we're hunting for. Stock Android has no swap partition and no swap file. When memory runs short, the system doesn't page to disk — it kills cached apps via lmkd, the low-memory killer. That's the Android way.
Except for zram. Many devices compress RAM pages into a zram block device, and the kernel reports that block device as swap. Check it yourself:
grep -i swap /proc/meminfo
If SwapTotal is 0, your device has no zram and no swap of any kind — the "swap diagnosis" question is moot, and memory pressure is the only game in town. If SwapTotal is a few hundred MB, that's your zram ceiling, and "swap usage" on this phone means "compressed RAM," not disk I/O. Google's own docs tell developers to read SwapTotal from /proc/meminfo to find the zram size. Same file, same field, different meaning than on a server.
And there's the second half of the catch: Android mounts /proc with hidepid=2 and layers SELinux on top. Termux can read its own processes' /proc/PID/smaps — that's what makes smem possible at all — but every other app's process directory is a locked door. Even /proc/stat, /proc/uptime and /proc/loadavg are restricted on modern Android. So the tool, once installed, sees a phone-sized slice: Termux and its children, nothing else.
The Fix: Python + the Official Script
smem upstream is a single self-contained Python script. The official source lives on Matt Mackall's site, and the Python 3-compatible release is the 1.5 snapshot from the Mercurial repo. Version matters: the old 1.4 tarball is Python 2 code, and under Python 3 it dies with NameError: name 'xrange' is not defined. Termux ships Python 3. So: 1.5, not 1.4.
Step one, python:
pkg install python
Step two, pull the 1.5 snapshot from the official Mercurial repo:
curl -L -o smem-1.5.tar.bz2 https://selenic.com/repo/smem/archive/98273ce331bb.tar.bz2
Step three, unpack:
tar xjf smem-1.5.tar.bz2
Step four, run it. The archive extracts to a smem-<changeset> directory; the glob keeps you safe whatever the exact name:
python smem-*/smem -k -rs swap
Same flags as the desktop: -k human units, -s swap sort by swap, -r reverse so the biggest sits on top. If zram is active, the Swap column shows compressed pages per process — real numbers, honest attribution, phone-sized scope.
Two things to know before you get attached. First, --bar is broken under Python 3 in the upstream script — it still uses xrange — so stick to the table or --pie (which needs pkg install matplotlib, a heavy install for a phone; the table is usually enough). Second, -p percentages divide by SwapTotal; with zram off, the column reads N/A.
What smem Can Actually See on Termux
Here's the honest limit, and it's a big one: on stock Android, smem lists only Termux's own processes. Your python scraper, your sshd, your proot-distro children — all visible, because they share Termux's UID. The rest of the phone is a black box, by design. That's not a bug in smem. Android's sandbox is doing exactly what it's supposed to do.
Which is still useful. When a proot-distro instance eats the phone, smem names it. When a scraper leaks, smem shows the Swap and USS climbing. You're diagnosing your own lab environment, which is the part you can actually fix.
Diagnosing Memory Pressure Without smem
If the full smem setup feels like too much for a quick check, the procps tools in Termux cover the basics. free -h reads the same /proc/meminfo and shows zram as swap; top shows your own processes with RSS. Neither attributes swap per process in a default quick check — that's the smem gap — but they answer "is the phone under pressure?" in one line:
free -h
And if your device exposes it, cat /proc/swaps lists the actual swap devices — usually a zram node. Some ROMs restrict it; if you get a permission error, that's SELinux, and the answer is the same as everywhere else on this page: root, or accept the limit.
The deeper point: on Android, "who's in swap" is usually the wrong question. The right one is "how much memory pressure is Termux under," because the phone's killer will reclaim memory before you ever see a swap column fill. Watch MemAvailable in /proc/meminfo — when it scrapes the floor, your session is one allocation away from being killed, and smem's job is to tell you which of your own processes is holding the bag.
What I'd Do Differently
Check the repo before the tutorial. pkg search smem costs five seconds and would have saved me the first wrong turn. Read the PyPI page before pip-installing anything with a familiar name — the smem on PyPI is a different project, and the README says so in its first lines. And I'd have remembered the Android constraint earlier: the tool was never going to see the whole phone, and that's fine, because the part I can fix is the part it can see.
One more thing worth saying: none of this needs root, and none of it should tempt you to chase root. The sandbox is the point. Diagnose what your own terminal does, fix your own processes, and leave the rest of the phone alone.
Go deeper: Who's Eating Your Swap? Diagnosing Swap Usage with smem for the full desktop version of this tool · The /proc Filesystem on Termux and Android for what Android lets you read and why · Termux on Android (Non-Root): Complete Setup Guide for the environment this all runs in.
On a phone, swap is a rumor and smem is a mirror — it shows you the part of the machine that's yours.
