I encountered this strange behavior yesterday on one of our servers. ps
, pgrep
and htop
(on startup) were very slow. strace ps
showed that read('/proc/$pid/cmdline
) took several seconds on some processes. Why did this happen?
Some observations:
- The processes executable was on NFS
- The processes (about 20+) were doing
unlink
andsymlink
operations on files also on NFS, in parallel - They're forked from the same parent process
- There're 80GB of RAM available (mostly cached), but swap (only 4GB) is in full use
- I run
while true; do cat /proc/$pid/status; sleep .1; done
,cat
returned immediately ifState
isS
orR
, but took several seconds whenState
isD
I did some Google'ing and found some SO answers suggesting that when State
is D
, reading /proc/$pid/cmdline
would stall. Is that true? And how does that work? Why was /proc/$pid/cmdline
, which was set before the program started, affected by what it was doing after that?
Best Answer
Same here, reading /proc/$pid/cmdline for a special $pid was very slow, even when State is R. And thanks to the links above which point out it might related to NUMA, I found out it caused by numad moving processes from nodes to nodes, this is from /var/log/numad.log :
When moving processes, read cmdline is slow, because cmdline is from user space and kernel need to lock(?) the page and read.
I guess the later move from the same node1 to node1 is needed because the process 9565 was on node1, but it might use remote memory.
Thanks.