Skip to content
Tech News
← Back to articles

Linux Terminal Memory Usage

read original get Linux Memory Usage Monitor → more articles
Why This Matters

This article highlights the importance of monitoring and understanding memory usage in Linux terminals, especially as users run multiple instances that can significantly impact system performance. It underscores the need for effective tools like smem to diagnose issues and optimize resource management, which is crucial for both developers and everyday users running numerous terminal sessions.

Key Takeaways

I use terminals a lot. On most machines, I have anywhere from five to ten of them open across one to four desktops (there are 12 terminals open on two desktops on the machine I'm writing on). Having started using Linux in 1996, I used xterm because it was the baseline. I found rxvt around 1998 and used that for a few years. I'm not sure how it went from there, but about three years ago I was mostly using lxterminal but switched to alacritty because it did most things right and worked in both X11 and Wayland (I'm stuck between those two worlds). However, a little less than a year ago I discovered kitty which was very appealing because it ticked the same boxes as alacritty but also supported pixel-perfect rendering of photos IN THE TERMINAL (using timg - https://github.com/hzeller/timg) ... which is very handy when you're SSHed to a remote web server. I switched most of my machines to kitty .

About six weeks ago, I noticed that one of my machines was incredibly sluggish because it was drowning in swap. It's a relatively old machine with an i7 processor and a spinning disk ... but it had 16G of memory and I wasn't doing anything memory-intensive like video editing or running a large database. This provided a learning opportunity, and I discovered smem (https://www.selenic.com/smem/ ... also available in both the Fedora and Debian repositories). It reports the memory usage of processes (including USS, PSS - which smem claims is a better way of looking at memory usage, RSS, and Swap). And what I immediately found was that ten instances of kitty had chewed through all my swap. 50G of swap. (Why I had that much on the machine I don't know - probably some failed or forgotten experiment.) I killed all instances of kitty and replaced them with ten instances of xterm and the 50G of swap that had been full was completely empty.

xterm isn't particularly beautiful, but I don't use the stuff other people would miss like tabs and menus. I miss transparency a bit, but it's not a big deal. I'll keep kitty around because of timg , although that's a relatively rare use-case.

I started switching most of my machines back to alacritty , and wondered what I should use in the long term. This inspired me to devise a test: I would run every terminal I was considering all at once - better yet, one set on Wayland and one set on X11 - and then run the same set of commands in every terminal. And measure the memory usage.

Openbox / X11

Before the Commands Were Run

PID Command Swap USS PSS RSS 115733 st 0 2592 3008 12788 115892 xterm 0 6808 7414 17732 115207 lxterminal 0 6528 9891 41380 114856 /usr/libexec/gnome-terminal 0 10252 14984 52836 115034 /usr/bin/kitten __atexit__ 0 19772 19783 21168 114615 alacritty 0 34224 43478 98396 131279 konsole 0 35108 50308 101220 115005 kitty 0 56376 66584 129180 115381 ptyxis 0 54760 67603 144640

After the Commands Were Run

PID Command Swap USS PSS RSS 115733 st 0 3396 3834 13780 115207 lxterminal 0 7800 11159 42656 115892 xterm 0 11640 12266 22748 114856 /usr/libexec/gnome-terminal 0 10692 15416 53340 115034 /usr/bin/kitten __atexit__ 0 21972 21983 23368 114615 alacritty 0 40188 49444 104408 131279 konsole 0 38528 54193 106256 115381 ptyxis 0 58252 71107 148316 115005 kitty 0 70716 80917 143568

KDE / Wayland

... continue reading