Hacker News new | ask | show | jobs
by boltn 3238 days ago
how would one go about running code/operations on ram as opposed to the hd?
2 comments

On most operating systems you can use part of your RAM as disk. Format it like a regular disk, mount it and save files on it.

The data is gone if you restart tho.

I've wondered for a while how fast we could make a phone (or PC) that operated entirely in RAM disk and used flash storage just as a one-to-one backup and storage when powered off. Obviously this would require your phone to have 128GB of RAM. You'd write changes to the flash storage, but it'd mirror RAM as closely as possible without destroying power management or storage life.

Imagine if there was no lag opening any app because everything was in memory. Imagine your code getting simpler because you don't need to load assets off disk - that's done all in one go at boot time. You want to render an image out? Just do it - a reference to a file is a reference to a file, no loading it or wondering if it's loaded.

Flash storage in phones is fast enough these days that it's probably not worth it, and simply giving traditional phones lots of RAM will probably give 80% of the improvement for 20% of the cost. But I've been curious about the idea for some time.

> I've wondered for a while how fast we could make a phone (or PC) that operated entirely in RAM disk and used flash storage just as a one-to-one backup and storage when powered off. Obviously this would require your phone to have 128GB of RAM. You'd write changes to the flash storage, but it'd mirror RAM as closely as possible without destroying power management or storage life.

PuppyLinux did this for the Eee PC. Worked wonderfully. The only problem was that the distro eventually became outdated, filled with old packages.

http://www.puppylinux.org/wikka/EeePC

The first Nexus phone had .5GB RAM and .5GB flash.

In other words, you don't need a ton of space. 8GB split among OS, apps, an running programs would do pretty well, honestly. 16GB is definitely enough. The question becomes more about how much space you want for photos and mp3s, and whether there is actually a benefit to putting those in RAM at all.

The hot stuff already is in the disk cache, so _IF_ the applications are written well, I don't think the difference would be large.

Also, you may need more RAM than flash, as large resources may/should be compressed in Flash (and personal data should be encrypted)

Then if the phone had originally 4 gigs of ram, you’d need an extra 4 gigs of ram for each app. I guess you could partition your ram to have 4 gigs as scratch, but that would limit the number of programs you can run.
On most Linux distros, /tmp is a ramdisk.
I don't think this is nearly universal - certainly none of the systems I use have /tmp as tmpfs.

/dev/shm, on the other hand, is almost always guaranteed to be a tmpfs on glibc systems.

No.... some, sure. Not most.

RHEL7, and all it's derivatives (CentOS, Oracle Linux etc.) don't use tmpfs for /tmp by default, and they are arguably the most used linux distros in the world.

But with only 1 GB capacity
It depends on your setup. The default when no size is given is to use half the RAM.
Half? That seems kind of excessive. Are you sure that’s right?
I would guess that it’s given that capacity, but the memory is allocated lazily.
Correct; tmpfs only uses as much memory as as is used by the files it contains.