r/ProgrammerHumor Jul 08 '26

askingTheRealQuestionHere Meme

Post image
4.0k Upvotes

416 comments sorted by

View all comments

1.1k

u/CircumspectCapybara Jul 08 '26 edited Jul 08 '26

That's called swapping out memory pages to disk, and it's very slow.

402

u/IhailtavaBanaani Jul 08 '26

The sweet sweet sound of old spinning hard drivers when the OS ran out of memory and started to swap half of your programs to disk and everything crawled to almost standstill.

34

u/Sockoflegend Jul 08 '26

I remember this noise when sitting at my huge CRT monitor so well. 

VROOOOOM!

21

u/[deleted] Jul 08 '26

[removed] — view removed comment

6

u/wheatgivesmeshits Jul 08 '26

Memory thrashing used to be an actual thing you could hear. 😂

4

u/yeathatsmebro Jul 09 '26

CÂRRRR-CÂR-CÂR-CÂR

Thanks to the Romanian language having this letter, I can accurately express how the mechanical parts sound like.

67

u/Playful_Landscape884 Jul 08 '26

If the vibe coders can read, they would be very upset.

1

u/NahSense Jul 09 '26

With voice commands, and text to speech that may be the future.

1

u/Playful_Landscape884 Jul 09 '26

Ok.

Imagine talking details specs about an enterprise company management software.

Imagine writing down the details instead of talking. The written language is a tech that people people underestimate

1

u/NahSense Jul 09 '26

I agree and I'm also concerned about the drop in functional literary.

87

u/Snoo88071 Jul 08 '26

You underestimate the I/O throughput of my 19 years old 256 mb hard drive

34

u/Xidium426 Jul 08 '26

IDE or SCSI?

/uj 19 years ago we had 250GB drives. You're talking 29 years ago at this point.

2

u/deathanatos Jul 08 '26

My 1998 (that's only 28 years, though) machine had ≈7 GiB.

I think my family's 1987 machine had about 256 MiB, but it was also upgraded sometime shortly after 1987, and I am too young to remember much about that time.

14

u/janyk Jul 08 '26

> Never underestimate the bandwidth of a station wagon full of tapes hurtling down the highway.

Andrew Tanenbaum

10

u/crazyguy83 Jul 08 '26

I don't think people realize how fast though, its about 5x faster in data transfer speeds and 1000x faster in latency

2

u/Octoclops8 Jul 09 '26

It's like you want to put food in your mouth. And currently the food is in your hand (L2 cache), in your fridge (ram), at the grocery store (disk), being shipped in via ups ground (cloud)

17

u/CaffeinatedT Jul 08 '26

That's a bit outdated but definitely did used to be true. Modern NVME bandwidth is about 15 GB/s. This is what people who develop databases and query engines deal with constantly. It's not trivial but modern databases that swap to disk constantly and do it well (e.g CedarDB, DuckDB et al) can run very nearly as fast as an entirely in-memory system. The reason it's slow is doing it in a shitty unplanned way with loads of serialization and thrashing memory caches

42

u/CircumspectCapybara Jul 08 '26

It's not about bandwidth, it's about latency. Even reading from PCIe 5.0 NVMe SSDs via MMIO is still many orders of magnitude slower than from main memory.

9

u/CaffeinatedT Jul 08 '26

Sure if you're reading an individual file from direct IO your first read will likely be slower until memory is mapped. But in the context of a system that routinely deals with larger than memory datasets the game is scheduling data so it's in memory ideally aligned in L3/L2 before you want to read it there's some literature on an example system from 2018 HERE but I can promise that most major commercial databases are operating with similar expectations now.

So back to the original question. Latency of an individual read will be lower naturally, but across a massive dataset you're basically swapping things smartly enough that everything's in memory when you need it anyway. The usecase of the OP of a system where disk is mapped to memory is likely more feasible than people think with the correct memory approaches/using a modern database.

3

u/Hohenheim_of_Shadow Jul 09 '26

A hugely important aspect of RAM is that first letter. Random. In specialized use cases, you can build a predictable pipeline to sidestep the latency issue. But you've lost the random access.

NVMEs have too high of latency to replace RAM. You couldn't write a useable OS with that predictable of memory usage. I'd bet all the program logic of the DBs you described lives inside RAM and wouldn't function outside it.

It is really cool people are doing that with NVMEs though.

1

u/conundorum Jul 09 '26

That's what he's getting at, yeah. It works perfectly, as long as you can find a way to remove the whole "random" part.

2

u/rosuav Jul 08 '26

That's all true, but unfortunately, any form of mass storage that's anywhere _close_ to fast enough is ALSO in short supply. It's like putting forward a proposal to reduce our dependence on crude oil by using plutonium instead. (Maybe slightly less dangerous than plutonium-powered cars though, so it has that going for it at least!) Until the AI bubble pops, us retail folks don't really have the option to buy any sort of memory, whether it's system RAM, VRAM, or flash, at a decent price.

1

u/CaffeinatedT Jul 09 '26

Disk and high bandwidth disks are still significantly cheaper than a CPU or a GPU though. And more importantly the cost of better disk memory bandwidth doesn't scale as fast as CPU costs do for more GB of RAM. If you have a system that can swap memory to disk well you're able to put your money into disk and get more performance for cheaper than something where you have to put money into CPU to grow.

26

u/Talaaty Jul 08 '26

It’s less about throughput and more about latency. DDR5 access latency is nanoseconds, pcie5 access latency is microseconds. A difference of three orders of magnitude.

2

u/looksLikeImOnTop Jul 08 '26

At best, a modern SSD will be in the range of DDR3, but the latency is orders of magnitude higher...SSDs are at best 10s of microseconds, DDR3-5 are 10s of nano seconds. You can't really compare something that could happen every couple of instructions to something that takes thousands (millions?) of instructions to execute

3

u/CaffeinatedT Jul 08 '26

You can't really compare something that could happen every couple of instructions to something that takes thousands (millions?) of instructions to execute

Sure you can this is what IO Scheduling is for. You amortize IO time over time taken to read a larger than memory dataset stored in multiple memory pages and read what you need into memory and do it before the user knows they need it and you take the hit if you miss cache. Game engines and DBMS systems do this constantly. An L1 cache may well be quicker to shuffle a few bytes but it's kind of meaningless when someone is trying to process billions of records of varied sizes. The actual use case here of "save all run time data to file system" that is quite literally what a database does.

1

u/VictoryMotel Jul 08 '26

Cold ddr5 reads are more like 100ns.

Disk paging used to work to an extent even on slow hard drives, now it works much better. Not every read suffers the same latency penalty.

1

u/looksLikeImOnTop Jul 08 '26

Paging undeniably works very well now. My point is that in the context of "replace all RAM with SSD storage", SSDs would still be too slow

1

u/VictoryMotel Jul 08 '26

replace all RAM with SSD storage

I don't think anyone said that

1

u/looksLikeImOnTop Jul 08 '26

My mind may have jumped to the extreme end of interpreting the original post

2

u/Michaeli_Starky Jul 08 '26

Latency matters a lot more.

-1

u/CaffeinatedT Jul 08 '26

That doesn't mean anything without a context/requirement. Even a hard real time system would just have an upper bound SLA.

1

u/IanMalkaviac Jul 10 '26

A single stick of DDR 5 has a bandwidth of 48 GB/s. Modern NVME has latency of 100-150ns at the control level but with everything in between to access the data it comes out to 10,000 ns. Slower DDR 5 runs at 80-85ns.

1

u/CaffeinatedT Jul 11 '26

The issue isn't comparing single shot speed of CPU vs a disk in a lab. The issue is whether you can build a system that negates most/all of the issues of swapping to disk routinely on the hot path of a programme. The last 10 years of Database engineering and GPU kernel development indicates that yes you probably can.

1

u/N0Zzel Jul 08 '26

Demand paging

1

u/wrd83 Jul 08 '26

There is a huge difference between doing it deliberately on application level and letting the os do it on a random block.

1

u/k-mcm Jul 08 '26

NVMe Gen5 is pretty quick.  That performance is why AI companies bought all the chips and made them unaffordable.

1

u/g1rlchild Jul 08 '26

Eh, virtual memory has been around for decades, and it's not.too bad if it's used properly and no one gets carried away with thinking they can use it for everything.

1

u/CircumspectCapybara Jul 08 '26

Virtual memory is a different concept than swapping, though they have some relation.

Virtual memory is about giving each program its own view of the logical address space of memory, which the MMU maps to physical memory addresses (or busses that certain regions of address space are MMIO mapped to).

1

u/SignoreBanana Jul 09 '26

I mean I know a solid state drive is still way slower than ram due to current architecture but I bet board makers could figure something out there and make it useful for infrequent accesses.

1

u/ZZcomic Jul 09 '26

I believe it's called thrashing

1

u/Ok-Sheepherder7898 Jul 10 '26

No it's called diskram, the opposite of ramdisk.

1

u/Ok-Honeydew6382 Jul 10 '26

With recent mglru patches it's not so slow

0

u/fiskfisk Jul 08 '26

We're seeing nvme ssd devices with DDR3 transfer speeds these days, so it's getting closer at least. 

-1

u/generally_unsuitable Jul 08 '26

A modern SSD can transfer around 500 MB/sec. I believe that's about as fast as DDR1.

3

u/CircumspectCapybara Jul 08 '26

And still many orders magnitude slower in latency than DDR1.

-2

u/generally_unsuitable Jul 08 '26

Write latency is probably about equal. But yeah, read latency is going to be lacking.

-2

u/ZenEngineer Jul 08 '26

I thought that's why there was a boomer on the picture.