r/linuxquestions • • 17d ago

Why can a Linux system have plenty of free RAM but still become extremely slow under heavy disk I/O?

I'm trying to understand Linux performance beyond basic CPU and memory utilization.

Imagine a system with low CPU usage and plenty of available RAM, but applications are responding slowly during heavy disk activity.

How would you distinguish between I/O wait, filesystem bottlenecks, memory pressure, and processes stuck in uninterruptible sleep?

Which metrics would you check first, and why?

12 Upvotes

29 comments sorted by

14

u/ipsirc 17d ago

How would you distinguish between I/O wait, filesystem bottlenecks, memory pressure, and processes stuck in uninterruptible sleep?

$ vmstat 1

3

u/Dolapevich Please properly document your questions :) 17d ago

I prefer sar -dr, but ymmv.

1

u/Aresharmajee 17d ago

That’s exactly what I’m trying to explore here, how experienced engineers distinguish between these symptoms rather than treating them as separate problems.
My initial approach would be:
iostat -xz 1 to check device latency, queue depth and utilization.
vmstat 1 to look at blocked processes, I/O wait and swapping activity.
cat /proc/pressure/io and /proc/pressure/memory to understand actual resource stalls.
ps to identify D-state processes, followed by /proc/<pid>/wchan or kernel stack inspection where permitted.
The tricky part is that these symptoms can overlap. A process in D-state might be waiting on disk I/O, but it could also be blocked on NFS or another kernel operation.
I’m particularly interested in how people determine the root cause when the usual CPU and memory metrics look perfectly normal. Have you encountered anything like that in production?

5

u/ipsirc 17d ago edited 17d ago

Up until now, I’ve always been able to tell from vmstat or dstat (dool) whether the machine was waiting for the CPU or for I/O.

If your problem is exactly this:

Imagine a system with low CPU usage and plenty of available RAM, but applications are responding slowly during heavy disk activity.

then you have to tune the scheduler. By default, the kernel weights everything equally, and a heavy I/O operation can take resources away from the processes you’d like to see remain responsive. Have you ever heard about kernel preemption or sched autogroup? If your plan to run i/o heavy applications in background, it would be better to start them with a much lower io.weight. There are plenty of kernel patches and user space tools which tries to find out which processes the unimportant background ones and which ones have to responsive in all cases - but all of them are just guessing... almost randomly.

So put your unimportant processes to a lower schedule, and the important ones to higher schedule. For example I have 2 cgroups: idle and high. All background processes goes to 'idle' (the best example is cron, so all processes started from cron will run at the lowest priority), and pipewire/pulseaudio and the video/audio player goes to 'high' group, so it won't lag even under VERY heavy loads. But it is only my practice, you can create your own environment. An example: it could lead to really extreme situations, when my taskbar/panel is not responding for half a minute, my mouse cursor is lagging for 2-3 seconds constantly, BUT the video which is played in mpv doesn't get even a single frame drop. Because I gave mpv the highest priority, so my whole desktop seems to be frozen, but the video is still going on. That's what you are trying to achieve?

1

u/Aresharmajee 7d ago

Keeping interactive work responsive is one case I had in mind, yes. Your cgroup example makes that concrete. Which I/O controller and scheduler are you using for those groups? I'd want to establish that the weights are actually taking effect before treating priority changes as the fix.

6

u/aieidotch 17d ago

ps -ef?
htop
strace -p
netstat
what storage? what filesystem? number of files in single directory?

can be everything…

0

u/Aresharmajee 17d ago

Agreed, there are quite a few variables involved.
I was thinking of this more as a general troubleshooting scenario rather than a specific incident. Say it’s an ext4 or XFS filesystem on SSD/NVMe storage, with low CPU usage and plenty of available RAM, but applications are experiencing high latency.
My initial approach would be iostat -xz 1, vmstat 1, checking D-state processes with ps, and possibly pidstat -d 1 to identify which processes are generating I/O.
Would you prioritize tracing individual processes with strace, or checking system-wide block I/O latency first? I’m interested in how others narrow it down efficiently.

3

u/cajunjoel 17d ago

This is all overkill. In this case, I'd run htop and look at the I/O tab. Use the easy tools first because they are easy. :)

1

u/aieidotch 17d ago

what applications are that exactly? i would start there

3

u/Aresharmajee 17d ago

Just to clarify above post, I’m interested in the diagnostic approach rather than troubleshooting one particular machine.
What makes this interesting to me is that low CPU utilization and plenty of available RAM can make a system appear healthy at first glance, even when application latency is terrible.

I’d probably start by correlating iostat, vmstat, PSI (/proc/pressure/io), and process states before digging into filesystem or application-specific behavior.
Curious if anyone has encountered a case where the obvious I/O metrics looked normal but the actual bottleneck turned out to be somewhere unexpected.

7

u/_Lost-In-The-Weeds_ 17d ago

If you are talking about spinning rust the issue is likely limited IOPS of the disk. Does not actually have much to do with Linux at all but a mechanical limitation of the read/write heads. Can only be so many places in a second.

Pooled drives mitigates this some. 

1

u/Aresharmajee 17d ago

That’s a fair point. On spinning disks, seek latency and random I/O can become the bottleneck long before CPU or memory utilization looks concerning.
I’m curious how you’d approach the same situation on SSD/NVMe storage, though. Even without mechanical seek limitations, couldn’t high queue depth, latency spikes, or filesystem contention cause similar symptoms?
Would you start with iostat -xz 1 to distinguish device saturation from other bottlenecks?

2

u/_Lost-In-The-Weeds_ 17d ago

My workload has never been able to saturate flash storage, 

1

u/LasevIX 17d ago

if your workload is able to take a whole PCIe lane of bandwidth you should be using a specialized filesystem like ZFS or at least XFS

2

u/RandomUser3777 17d ago

If you queue up enough writes to hit the dirty_cache limit then ALL writes will get paused until enough writes are written. the ratio with values is 10% of ram and 20% of ram, when you hit 20% then writes will stop until you get down to 10%. I have when having issues switch to the _bytes setting (it uses one setting or the other) and lowered the spread between the 2 values such that the freeze is much shorter.

Ie 10% of ram on a 16gb machine is 1.6gb of writes and on a spinning disk that is 15-30 seconds, on a sata connected ssd that is still a few seconds.

sysctl -a | grep -i dirty | grep -E 'bytes|ratio' ; grep -i write /proc/meminfo

vm.dirty_background_bytes = 0

vm.dirty_background_ratio = 10

vm.dirty_bytes = 0

vm.dirty_ratio = 20

Writeback: 0 kB

WritebackTmp: 0 kB

1

u/Aresharmajee 7d ago

Dirty writeback is a useful example here. I'd qualify the thresholds, though: the ratios use available memory containing free and reclaimable pages, not total installed RAM. The background threshold starts flushing; it isn't simply a rule that all writes stop at 20% until usage falls to 10%.

4

u/brighton_it 17d ago

cat /proc/pressure/io
cat /proc/pressure/cpu
cat /proc/pressure/memory
https://docs.kernel.org/accounting/psi.html

1

u/usecornercase 17d ago

One thing worth adding to your list: free RAM doesn't protect you from stalls caused by dirty page writeback. When a process writes faster than the disk can flush, the kernel throttles it in balance_dirty_pages, so it sleeps in D state even though nothing looks wrong in CPU or memory. You can see it with grep -E 'Dirty|Writeback' /proc/meminfo during the slowdown, and the vm.dirty_background_bytes / vm.dirty_bytes sysctls control when it kicks in. Also, for the 'is it the disk or something else' question, look at await and aqu-sz in iostat -x, and compare the 'some' and 'full' lines in /proc/pressure/io: full means every runnable task was stalled on I/O, not just one. For D-state tasks, cat /proc/<pid>/stack as root or the wchan column in ps -eo pid,stat,wchan:32,cmd tells you whether they're stuck in the block layer, a filesystem journal, or NFS.

1

u/Aresharmajee 7d ago

The writeback example helps. One small correction: PSI full means all non-idle tasks are stalled on that resource simultaneously, rather than all runnable tasks. I'd check that alongside Dirty, Writeback and the blocked task's stack before changing the dirty limits.

2

u/Interesting_Debate57 17d ago

netstat -n

And then look from there. top (or ps) will tell you which processes are using the most CPU and RAM and which are spending the most time idle.

There's also iostat which will help you watch disk flurries.

There's plenty built into the system to help you see what's happening.

Probably the thing that requires the least intelligence to use is "top" and then sort by whichever column you're interested in.

This will all make more sense after reading the relevant man pages.

1

u/symcbean 17d ago

'top' is a good place to start.

High CPU usage - CPUs too slow

High user/sys load - not enough CPUs

High memory / some swap uage - fire up vmtat to check how much swapping is going on

Hi iowait - disk bottleneck

1

u/tabbekavalkade 17d ago
  • Change swappiness. Set it to 10 to see if it improves the situation.
  • Change the IO scheduler (not the CPU scheduler) to something like bfq.
  • Change the CPU scheduler (probably not the cause, but something like BORE is worth a try).
  • Test with the lowlatency kernel.

1

u/throttlemeister 17d ago

Linux is largely optimized for server use, ie throughput prioritization. For desktop use you want latency prioritization. You can fix that somewhat with tools and settings but since there is no single set of desktop processes it is always possible to trigger said behavior even with ssd or nvme and tuning.

0

u/allunia333 17d ago

Why do you need to distinguish common sense? I/O storage is orders of magnitude slower than system RAM which in turn is orders of magnitude slower than cache...

This has always been the bottleneck in all computers and still is...