What is the relationship between CPU usage and RAM?

22

20

I have seen many times that the CPU usage is 100% and only 50% of the RAM is in use. What is the relationship between these two? How does one's performance affect the other?

Gopi

Posted 2009-12-03T13:02:35.967

Reputation: 333

Answers

44

The CPU processes (performs instructions on things, such as adding) stuff in memory. RAM is just part of the memory pyramid (see below). So when you are processing lots of data, that data ( or maybe large portions of it) will likely get loaded into RAM so it is ready for the cpu, this is to speed things up because RAM is faster to access than storage devices. So CPU usage and RAM can often correlate, but don't have to.

A basic example might be an image editing program. I load up my 20MB jpeg, the program reads the entire image, and the OS keeps that in RAM for you (all working memory looks the same to the program, the OS decides if it goes to the page/swap file on disk or RAM). So the image is in RAM waiting to be processed, but I go for coffee before telling the program to apply some silly filter, so the CPU isn't doing anything: high RAM low CPU.

I come back, apply the filter to add some bubbles to the image, and the CPU goes to 100% and even more memory gets used because it keeps the preprocessed image in memory, so I can undo the change I just made. High RAM, high CPU.

When the program is done adding the bubbles, the CPU drops, but maybe not the memory.

Of course, it isn't quite this simple :-)

Picture of Memory Pyramid

Kyle Brandt

Posted 2009-12-03T13:02:35.967

Reputation: 3 089

what is the virtual RAM? – Ooker – 2018-06-08T03:55:56.130

@Ooker: I think he means virtual memory? – kailash19 – 2018-08-08T09:09:47.080

24

It's the same relationship as your brain have with a book. The faster brain = the faster your read, the bigger the book = the more pages it can contain.

pauska

Posted 2009-12-03T13:02:35.967

Reputation: 370

And the bookshelf is permanent storage. Mmmmmmm nice. – Charles Watson – 2016-03-18T14:06:01.823

Nice explanation :) – Jai – 2019-01-19T04:20:35.997

2Oohh... nice analogy! – MikeyB – 2009-12-03T14:35:47.847

10

RAM is used to save data. CPU time is used to process data.

There is no relationship between CPU and memory usage. A process can occupy all CPUs of a system but use only a minimal amount of memory. Also, a process can allocate all memory available on a system but only use minimal CPU time. So there is no relation between both.

joschi

Posted 2009-12-03T13:02:35.967

Reputation: 981

5

There's no consistent relationship between the two. CPU usage depends on how much processing or work that needs to be done by the app. RAM is how much space/memory it needs to hold the app while it's running.

More RAM = you can run more apps concurrently

More CPU = you can run more complex calculations/operations

Hope that helps.

Glen Y.

Posted 2009-12-03T13:02:35.967

Reputation: 133

2

They are not related. You some tasks use a lot of just one of those resources and some use a lot of both.

Amok

Posted 2009-12-03T13:02:35.967

Reputation: 186

1

No relationship. Think of it in terms of doing some heavy-duty number-crunching. RAM is how many of those numbers can be stored for faster retrieval, whereas CPU is how fast those numbers can have mathematical operations performed on them.

For how one affects the other, let's assume that you have a slow CPU but lots of RAM. That means that you can store quite a few of those numbers in memory - about half a billion of them on a typical 32 bit machine. But processing/computation/etc on those numbers will be slower.

On the other hand if you have a fast CPU but a small amount of RAM, processing of the numbers will be fast, but from time to time the machine will need to drag them from disk (and put them back again to make room for more), which is many times slower than taking them from RAM.

So really, each affects the other, and for best performance you need both to be good. However, this totally depends on what each application is actually doing, and there are other factors (such as disk speed, processor caches, etc) which we needn't go into too much detail about for now, but which you should be aware will complicate things.

Maximus Minimus

Posted 2009-12-03T13:02:35.967

Reputation: 190