Sphere
Log in Join

Load average 40 with idle CPU: tracking down D-state processes on NFS

One of our batch hosts had a load average above 40 for most of a day. alerts were firing, but top showed 2% CPU and plenty of free memory. Nothing looked busy. This is the kind of problem where the number at the top of uptime is telling the truth and every other tool is measuring the wrong thing.

## What the numbers said

$ uptime
14:07:32 up 63 days, 3:11, 2 users, load average: 41.82, 39.04, 37.66

$ top -bn1 | head -5
top - 14:07:34 up 63 days, 3:11, 2 users, load average: 41.82, 39.04, 37.66
Tasks: 312 total, 1 running, 198 sleeping, 0 stopped, 113 zombie
%Cpu(s): 1.2 us, 0.8 sy, 0.0 ni, 97.6 id, 0.2 wa, 0.0 hi, 0.2 si, 0.0 st

113 zombies was my first wrong theory. Zombies do not raise load, they are already dead and waiting for a parent to reap them. The load number counts processes that are running or in uninterruptible sleep. With one running task and 97.6% idle, the other 40 had to be in D state.

## Finding them

$ ps -eo pid,ppid,stat,wchan:30,comm | awk '$3 ~ /D/'
PID PPID STAT WCHAN COMMAND
1241 1 D nfs_wait_bit_killable python3
1287 1 D nfs_wait_bit_killable python3
1330 1 D nfs_wait_bit_killable python3
...

All of them parked in nfs_wait_bit_killable. The batch jobs were reading input from an NFS mount that had gone away when the storage box was rebooted the night before. The clients were still holding stale file handles and waiting for a server that was not answering.

The application logs had this, which I had initially read as a slow disk:

OSError: [Errno 5] Input/output error: '/mnt/nfs/incoming/batch_20240314.csv'

## Why kill -9 did nothing

I tried killing a few of them. D-state processes ignore signals, including SIGKILL, because the signal can only be delivered when the process wakes up and it is stuck in a kernel call that is not returning. That is the whole point of uninterruptible sleep. kill -9 just leaves the process sitting there with a pending signal.

You cannot cleanly fix this from the client side. The options are to make the server respond again or reboot. In our case the NFS server was back but the mount was stale:

$ sudo mount -t nfs4
192.168.40.5:/export/incoming on /mnt/nfs type nfs4 (ro,timeo=600,retrans=2,clientaddr=192.168.40.31)

$ ls /mnt/nfs
ls: cannot access '/mnt/nfs': Input/output error

I could not even unmount it normally, because that also needs the server. A lazy unmount cleared the process's view of the mount:

sudo umount -l /mnt/nfs

That let the Python processes fail with an I/O error and exit. Load dropped back under 2 within a minute.

## The part that actually prevents it

Lazy unmount is a recovery trick, not a fix. The mount options were the real issue:

192.168.40.5:/export/incoming /mnt/nfs nfs4 defaults,nfsvers=4.2,timeo=100,retrans=2,hard,actimeo=30 0 0

With timeo=100 and retrans=2, a dead server should fail after roughly 20 seconds. What we had was timeo=600,retrans=10 copied from an old guide, which is over twenty minutes of waiting. I also added soft to the non-critical batch mounts so calls time out and return an error instead of hanging forever. Do not use soft on anything where a partial write would corrupt data; for read-only input directories it is the right trade-off.

Monitoring load average alone will not catch this. Alert on the count of D-state processes instead, it is a much cleaner signal.