I have a program that needs LOTS of RAM to for a computation project I need to run for a weekend. Obviously I don't have supercomputer ram and my limits as a consumer is 32GB. Windows has memory virtualization in the form of a pagefile that expands the amount of virtual memory I can leverage by using the hard disk, albeit traditionally much slower. M.2 NVMe drives is the new hotness for fast data access SSDs. If I have an 1TB M.2NVMeSSD main drive, and allocate say 480GB of memory as my pagefile, does that mean I can effectively have plenty of memory? Or will this be abysmally slow anyway? Will it kill my drive? Can a program even use all available ram + virtual-ram simultaneously and actively?
This concept seems too good to be true that I can just make up as much ram as I have disk space, so I need to know what's wrong with my theory.
11 Answer
Memory access will be as fast or as slow as your NVMe drive is.
Note that modern SSDs, even NVMe ones, have limitations. They are fast, but that speed is typically conditional upon the amount of data written.
You see, fast high endurance flash storage is expensive so to offset that expense they typically have a small ultra-fast SLC write cache (expensive part) backed by relatively slow MLC flash (cheaper). That cache may be 1 to 8 or even 16GB but once it is filled you need to give the drive time to "catch up" and write the cache to the slower area of the drive.
It could be that you see up to 2 to 3GB/s for the first couple of GB written, but that may well drop to 500MB/s or less depending on your SSD.
Reading should be fine and achieve high speed across the drive, it is just the initial writing that would have this big performance step. Whether that is acceptable depends on your use case. You might be fine waiting for that initial filling for the extra speed later.
Modern SSDs also claim high lifetime "terabytes written" (TBW) figures, but I still wouldn't want to be constantly rewriting every block of the drive 24/7. Every write will reduce the lifetime of the drive slightly, though it may well last years doing so anyway.
You can use an SSD as a page file device, but you need to be aware of it's limitations.
You might find it better to go with an "on demand" cloud service where you can rent time on an appropriately specced server. In terms of time it would be a much better investment as it will likely be a lot faster (as it would have all the real RAM) and be a comparable cost.
Or if this is your own program you might want to consider writing it better to make use of low-memory and do the file handling yourself rather than expecting the OS to do it all.
For every block of RAM you access that is paged out to the drive your program will be suspended while reading that block takes place. If another block needs to be evicted from physical memory first then that time will be longer. How much performance is lost is questionable and dependent on your program. Virtual memory might make your task easier by offloading the management to the OS, but you lose control and granularity you would have by controlling the data access yourself.
3