| >> If you really think about it, the only real difference between main memory blocking and disk blocking is the amount of time they may block.
>
> This is a somewhat confusing analysis you have here. Direct read/write from memory for all intents and purposes doesn't block. Why do you say that reads and writes may also block? Reads and writes from actual, physical, hardware memory might block, depending on how you define "block", in the sense that some reads may miss CPU cache. But once you get to that point, you could argue that every branch might block if the branch misprediction causes a pipeline stall. This is not a useful definition of "block". The thing is, most programs are almost never low-level enough to be dealing with memory in that sense: they read and write virtual memory. And virtual memory can block for any number of reasons, including some pretty non-obvious ones like. For example: - the system is under memory pressure and that page is no longer in RAM because it got written to a swap file - the system is under memory pressure and that page is no longer in RAM because it was a read-only mapping from a file and could be purged -- e.g. it's part of your executable's code - this is your first access to a page of anonymous virtual memory and the kernel hadn't needed to allocate a physical page until now - you're in a VM and the VMM can do whatever it wants - the page is COW from another process |
I think what I'm saying is that calling file I/O "blocking" is also not a useful definition of "block". Because I don't really see the fundamental difference between "we have to wait for main memory to respond" and "we have to wait for disk to respond".
> this is your first access to a page of anonymous virtual memory and the kernel hadn't needed to allocate a physical page until now
And said allocation could block on all sorts of things you might not expect. Once upon a time I helped debug a problem where memory allocation would block waiting for the XFS filesystem driver to flush dirty inodes to disk. Our system generated lots of dirty inodes, and we were seeing programs randomly hang on allocation for minutes at a time.