1

So i noticed how linux sometimes uses swap memory (located in internal HDD / SSD).

When ram is overloaded PC stores some ram data in swap to make things faster it guess.

So if you can store ram data in HD can you do the opposite and store HD data in ram (maybe temporary)?

I know this is impractical but still...

4
  • No I think not possible May 4, 2020 at 10:42
  • 2
    Well, of course. That happens every time you load something, a document or a program or whatever. The information necessary to run/view it is copied from the HDD to RAM. That's kind of the whole point of RAM. Are you thinking of something like preload? Or the standard disk caching? Please edit your question and clarify what you are asking.
    – terdon
    May 4, 2020 at 10:57
  • 1
    OP might be looking for ramfs? wiki.debian.org/ramfs Also, swapping slows the system down, not speed it up.
    – Panki
    May 4, 2020 at 11:07
  • yes ramfs would be it i do it rather frequently especially for temporary files, caches and such but i use tmpfs instead...
    – der bender
    May 4, 2020 at 13:32

1 Answer 1

1

Can you store files in RAM? Yes you can using something like ramfs (as mentioned in a comment), but this is unrelated to how and why the system swaps. In fact it could happen that some of your files stored in RAM end up swapped into disk.

Linux (and Windows) have a concept of virtual memory, where the operating system loads and saves pages into memory. There is a process in the background that moves pages from RAM into swap (disk) if RAM space starts to run out using a particular criteria. This is a tradeoff of speed versus stability, since if you ran out of RAM space, the system will halt (actually it doesn't the OOM will kill processes randomly until you have more RAM, but this is destructive).

So you only have data in swap if you start consuming a significant amount of RAM. You cannot decide what to swap and what to keep in RAM.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .