LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Linux Memory calculation related (https://www.linuxquestions.org/questions/linux-general-1/linux-memory-calculation-related-4175599271/)

Vivekanandan Dhamodharan 02-08-2017 07:05 AM

Linux Memory calculation related
 
Hi,


I have using Ubuntu 14.04 LTS linux machine.I have run more than one application in my system. I want to run additional application at that time my RAM is fully used after that continuously run another application in this time my system running good but memory is used to swap memory.so i want to one doubt how to i calculate my system total memory size? for example My RAM size is 8GB and swap memory is also allocated upto 8GB.

1.This total memory is RAM memory only or RAM+SWAP memory?

2.How to find the System memory size? and what is the main use of swap memory in linux?

r3sistance 02-08-2017 07:23 AM

top will probably be the first port of call if you're using command line only. It will display CPU and memory statistics in itself and can be used to list processes by their actually %mem usage.

Swap is an expansion of the paging system on to another peripheral generally a hard drive but could be an SSD, a flash card or potentially a number of any other devices. By extending the paging to these devices it means lesser used memory can be shifted off of the paging on RAM to the paging on the SWAP device/file to free up RAM for other more important tasks. Swap has a cost associated to it's usage, if you swap too heavily or make swap too large then you will see decreased performance from it.

MensaWater 02-08-2017 07:26 AM

If you run "free" it will show you memory information.

Output would look similar to this:
total used free shared buffers cached
Mem: 2903116 2677956 225160 0 443788 1896044
-/+ buffers/cache: 338124 2564992
Swap: 5079032 148 5078884

Note that Linux pre-caches and buffers most of its memory so the "free" column on top line is the amount is based on that.
The line below that has what is actually "free" in that the pre-cached memory and buffers are easily reclaimed for use in other processes.

Swap in Linux as in UNIX these days is used more for "paging" than "swapping" meaning as memory pages age they get written to swap and on occasion may be read back from there. A system that is doing heavy reads from swap usually is under heavy memory pressure and you'll see performance issues. You should allocate swap to allow for normal aging writes and a low level of reads but if you're doing heavy reads you really need to increase RAM.

You can see more details of memory with vmstat, sar and in /proc/meminfo.

sundialsvcs 02-08-2017 08:09 AM

Also: cat /proc/meminfo.

The /proc "directory" is actually an operating-system API where lots of important information can be found. While it all appears to be "files" and "directories," it's actually all a figment of the operating system's imagination.

If you are running memory-intensive applications, you need to know that you have enough physical RAM to accommodate all of them. ("Splurge. Buy more. Chips are Cheap.™")

You need to plan the purchase of resources against the needs of the application-mix that you intend to run.

You can use commands such as ulimit to impose limits upon an application, e.g. how much memory it is permitted to allocate. But you must be sure that the application is actually prepared to handle being denied a request to obtain memory. If the application has configuration-file controls which inform it of limits that it is expected to honor, first use those controls, then perhaps use ulimit to give them teeth.

"Swapping" uses disk space as an adjunct for RAM, and it is always expensive since the application comes to a dead stop while the so-called "page fault" is being resolved. Furthermore, swapping becomes a very substantial load on the disk-I/O subsystems of the computer, in addition to (and usually, pre-empting) ordinary application disk traffic. In these days and times, when RAM is cheap and plentiful, it is a thing to be avoided.

---
Incidentally, you will observe that Linux will use all available RAM for some purpose, such as "file buffers" if nothing else. RAM is a resource that is "there to be used," and all of it will be used for something.

Vivekanandan Dhamodharan 02-08-2017 10:23 PM

Quote:

Originally Posted by MensaWater (Post 5667091)
If you run "free" it will show you memory information.

Output would look similar to this:
total used free shared buffers cached
Mem: 2903116 2677956 225160 0 443788 1896044
-/+ buffers/cache: 338124 2564992
Swap: 5079032 148 5078884

Note that Linux pre-caches and buffers most of its memory so the "free" column on top line is the amount is based on that.
The line below that has what is actually "free" in that the pre-cached memory and buffers are easily reclaimed for use in other processes.

Swap in Linux as in UNIX these days is used more for "paging" than "swapping" meaning as memory pages age they get written to swap and on occasion may be read back from there. A system that is doing heavy reads from swap usually is under heavy memory pressure and you'll see performance issues. You should allocate swap to allow for normal aging writes and a low level of reads but if you're doing heavy reads you really need to increase RAM.

You can see more details of memory with vmstat, sar and in /proc/meminfo.




It's ok, but the system memory consider with RAM memory only or RAM+SWAP memory. Please explain clearly

pan64 02-09-2017 12:20 AM

probably you need to read: www.linuxatemyram.com

sundialsvcs 02-09-2017 08:46 AM

Let's briefly talk about what "swap" is. To do that, we must discuss what "virtual memory" is.

Every process that is running has its own so-called "address space." This is its view of what "memory" contains. But you could have 100 different processes out there, all with a different notion of "what's in memory-location $12345678." They can do this because it is virtual memory.

Physically, memory is divided into equal-sized units called "pages," and the virtual-memory hardware in the CPU translates the addresses issued by the program ("$12345678") into some other address that is actually sent to the memory chips. Processes don't see this happening, but this is why each of them can have an entirely different notion of "what's in location $12345678." Each of them is subject to a different virtual-address-to-physical-address mapping, courtesy of the hardware (which they never perceive).

The data for any given page, for any given process, can be "anywhere in RAM," or "not in RAM!" The data might have been removed from RAM and swapped out to disk. When (and if) the process references that page again, a page fault interrupt will be generated by the CPU, and Linux will swap in the data from disk again. (After possibly swapping-out some other page to make room.)

Linux will always use all of physical RAM for some purpose. Virtual-memory "page frames" are only one possible use. If nothing else, Linux will use RAM for file-system buffers, pre-reading data from a disk file and stashing it in memory in anticipation of near-future use. As memory-load manifests itself, Linux has various priorities for how RAM will be used. (And, in cases of extreme unction, there is also the dreaded "OOM Killer" – "OOM == Out Of Memory." Yes, to save itself, Linux will start killing processes.)

onebuck 02-09-2017 09:39 AM

Moderator Response
 
Please post a single post for your problem to avoid problems/confusion. Your other thread has been closed; http://www.linuxquestions.org/questi...am-4175599353/

MensaWater 02-09-2017 10:02 AM

Quote:

Originally Posted by Vivekanandan Dhamodharan (Post 5667584)
Please explain clearly

That's the kind of thing that is most likely to prevent me trying to help you further. I responded to the question as you initially asked it. If my response wasn't helpful then you didn't ask the question you meant and should rephrase or ask a new question based on the responses you got.

MadeInGermany 02-09-2017 10:34 AM

Hint: always have some swap, even half a GB helps Linux if there is memory pressure.
Linux cashes all it finds, thus maneuvers itself near a memory pressure situtation.

Regarding monitoring, everybody asks how to measure RAM and swap usage separately.
However it is impossible to find good alert thresholds.
Monitoring RAM+swap makes more sense.
That's one of the reasons I wrote my own Nagios plugins. Extract the check_vmem.sh that measures RAM+swap usage. (And makes a rough assumption of cache availability.)

TB0ne 02-09-2017 12:38 PM

Quote:

Originally Posted by MensaWater (Post 5667844)
That's the kind of thing that is most likely to prevent me trying to help you further. I responded to the question as you initially asked it. If my response wasn't helpful then you didn't ask the question you meant and should rephrase or ask a new question based on the responses you got.

And that's the kind of thing that makes me think "Gee, this is a homework question"....:)

Crippled 02-09-2017 09:47 PM

Quote:

Originally Posted by Vivekanandan Dhamodharan (Post 5667078)
Hi,


I have using Ubuntu 14.04 LTS linux machine.I have run more than one application in my system. I want to run additional application at that time my RAM is fully used after that continuously run another application in this time my system running good but memory is used to swap memory.so i want to one doubt how to i calculate my system total memory size? for example My RAM size is 8GB and swap memory is also allocated upto 8GB.

1.This total memory is RAM memory only or RAM+SWAP memory?

2.How to find the System memory size? and what is the main use of swap memory in linux?

You have something wrong if you run out of 8GB of ram. I have 8GB ram also and I do more than that and have at least 2GB ram to spare.

sundialsvcs 02-12-2017 06:35 PM

[list][*] "Applications" are not created equal ... and-d-d-d ...[*] "It's only 'ones and zeros,' kid!" Das Komputenmachin is [only] just that: a machine.

If you tried to lift the Statue of Liberty using your tow-truck, and your truck fell into New York Harbor in the process of trying your stupid stunt, then you would have only yourself to blame for those millions of 'tweets' and mocking YouTube videos. :rolleyes:

You have to be aware of exactly what it is you are asking your Das Komputenmachin to do, and of the resource-requirements needed to do it effectively and successfully. You need to be sure that the machine in question has the necessary hardware resources. No one else can do this for you.

- - -
However, if you have a particular situation that you need help with, such that you think that someone else here might also have encountered it, then please give us more details about your particular situation and requirements. I do not intend my post here to be a "shut-up and go-away" rebuttal. Not at all. Not at all ...


All times are GMT -5. The time now is 08:47 AM.