gavd.co.uk

Frail and faltering follower of Jesus

Linux command of the day, 8 of 31 - top part 2

By Gavin Davies

I didn’t finish investigating top yesterday, so here’s part 2!

I’m looking briefly at a Linux command every day for a month. I didn’t finish investigating top yesterday, so here’s part 2! This isn’t intended to be a tutorial, just some brief notes for fun

Yesterday I got stuck in to top but I mostly focused on load averages, which are available in other tools such as iostat and uptime. Top offers a LOT more!

top | head -n11
Processes: 482 total, 2 running, 480 sleeping, 2405 threads
2020/08/08 16:54:13
Load Avg: 1.99, 2.41, 2.83
CPU usage: 4.2% user, 9.95% sys, 86.1% idle
SharedLibs: 296M resident, 63M data, 20M linkedit.
MemRegions: 213345 total, 8574M resident, 179M private, 4552M shared.
PhysMem: 27G used (5020M wired), 4916M unused.
VM: 3575G vsize, 1991M framework vsize, 6543880(0) swapins, 7114909(0) swapouts.
Networks: packets: 14198504/9282M in, 15484550/3037M out.
Disks: 7869978/139G read, 38693800/296G written.

I’ll go line-by-line - I used this Stack Overflow question to help me understand this.

It strikes me that I should have called this series something different as I’m running all this stuff on a Mac just because that’s what I have available to me! I didn’t want to run a VM or container, I wanted to run all these tools right on the metal, particularly when figuring out tools like top!

  • Processes: 482 total, 2 running, 480 sleeping, 2405 threads: simple counts of how many processes are running on the machine
  • 2020/08/08 16:54:13: Timestamp of when I ran top
  • Load Avg: 1.99, 2.41, 2.83: Load averages, covered yesterday
  • CPU usage: 4.2% user, 9.95% sys, 86.1% idle: I think that on my mac this has been averaged out across all my CPUs, but from what I’ve read you can get figures of >100% on multi CPU Linux systems.
    • user - how much time is spent on userland processes
    • system - how much time spent on system stuff
    • idle is doing nowt - if this is 0 then something’s probably gunning your machine pretty hard
    • linux systems will then display niceness but my mac doesn’t show me that
  • MemRegions: 213345 total, 8574M resident, 179M private, 4552M shared. - this is about memory pages
  • 27G used (5020M wired), 4916M unused
    • used I have 32gb on this mac (it’s not mine, it’s a company one!) From a bit of digging I see Docker (what else?!) is using 17GB. I kill docker and used goes up to 30GB!! Well, used apparently means it can be ‘speculatively used’, as in, something is loaded in to the physical memory but it’s not necessarily “in use” - the OS has said “hey let’s have this in memory” but it may not be ‘wired’ right now.
    • wired Wired means it’s actually being used right now - so you can’t page it out to disk. This is stuff like the OS itself. So I could think of this as pages that are “patched in” in a modular synth, I guess.
    • unused is just ready to rock with nothing in it, so here I have 5GB in here that the OS could load anything into
  • 3575G vsize, 1991M framework vsize, 6543880(0) swapins, 7114909(0) swapouts. I stared at this for ages before I twigged that it’s not talking about a virtual machine, but virtual MEMORY! I’ve spent too many years running EC2 and Vagrant!
  • Networks: packets: 14198504/9282M in, 15484550/3037M out. “Number and total size of input and output network packets”. OK great, but over what time? After a reboot, I see Networks: packets: 4299/3557K in, 6289/3687K out. which is next to nothing, so I conclude it’s from boot.
  • Disks: 7869978/139G read, 38693800/296G written. - How much data has been read from/written to disk since boot (after a reboot I see Disks: 289760/4163M read, 74084/1312M written.)

One thing I notice is in zooming iTerm WAAAAAAAAY out I can see a lot more columns! It shows me things like cycles and a bunch of columns that show nothing but N/A. One column is faults which apparently occur when memory page that’s not in physical RAM is referenced, so it has to be paged in. So, I think to really look like 1337 hackerman you need a ridiculously large monitor to get all those columns showing at once! ;-)

Wow, all that and we haven’t even gotten past top‘s header section yet! Part… 3 tomorrow?! What was this about “small sharp tools”?!