What is the point of loading a program into RAM if virtual memory is just going to put it back on the disk?

1

After reading this question about virtual memory, I was inspired to ask: it seems like walking in a circle when a program is run it is loaded into memory from disk but then there's not enough space in memory so it is loaded back onto disk (as the page file). Is it necessary for computers to load 100% of a program into memory initially? I recall learning about something that gives each process the perception that it is running alone in address space so it can start at the very first address, is this the primary reason to virtualize memory or has this got nothing to do with it?

Celeritas

Posted 2013-09-26T08:02:37.287

Reputation: 7 487

3Some programs can choose what to do here (to use RAM or Virtual RAM etc). However, As a general rule, Virtual Memory is used when you've run out of RAM. – Dave – 2013-09-26T08:05:58.417

the above comment is your answer. plain and simple. – Lorenzo Von Matterhorn – 2013-09-26T08:17:31.253

Answers

1

Reason is Speed. Also a process can grow while it runs, like k-meleon. Or spawn new processes while it runs like chrome.exe. Cache memory is faster than RAM which is faster than disk.

So things get put in cache where cache is available. Ideal is if CPU is executing things in cache. Second to that is if it's executing things in RAM.

CPU never processes things on disk, it doesn't address things on disk, it only addresses RAM locations or no doubt, cache locations. Or locations that read/write to devices.

It's not like everything even everything you might want to run is swapped out to disk and then back to RAM. Only Things not currently being used and not likely to be used soon are preferred when swapping things out, so as to free RAM up for things that are more in use.

Web browsers have a cache too, a disk cache! They store things locally on disk, rather than fetch from from online. There are web proxies that you can run locally that store a website locally and if it changes online then it will fetch. This enables you to browser much quicker. (though I suppose you can run into the problem of a website not specifying properly that a change was made, and you get stuck loading an old copy from your local disk cache) but the idea is that it's faster. In that situation the quicker area is the local hard disk and the slower area is the remote/online area.

You do this kind of swapping in life, with things you need near you, and things you don't need in storage. You don't put everything in storage/garage arguing that there's loads of room in storage/garage. It'd be too slow.

barlop

Posted 2013-09-26T08:02:37.287

Reputation: 18 677

0

  1. The organisation on disk can (almost certainly will) be different so the page/swap file partition is optimised to load pages of virtual memory whilst your every-day file-system will be optimised for it's particular characteristics, eg "don't waste disk space".
  2. Also your executable is not quite runable whilst on disk, relative pointers are adjusted to the virtual address space upon loading, so once this has been done upon load it's all there ready to be paged in and out.
  3. Your program may be minuscule on disk, and then the first thing it does is allocate a huge chunk of memory for something, this can get paged out into swap for use later in the programs execution.

To sum-up it's generally faster to do it the way it works.

X Tian

Posted 2013-09-26T08:02:37.287

Reputation: 182