Linux Load avg calculation

How to calculate the load average, for example my system has 4 cores and 3 processor. So what is the avg load limit to take care?

Hi:

You can check the load avg in linux just using “cat /proc/loadavg” in the terminal. The first number is by 1 minute period, the second five minutes period and the third one shows the avg by 10 minutes period. The fourth column shows the actual running process and the total of the system. The last column shows the last id process used. You can also use uptime. or another tools like btop or htop, etc. But if you only want the load avg, i find it more useful to read directly by /proc/loadavg and use a pipeline with awk to extract the data needed.

If your question is to understand how the load avg is calculated, the you can check this post from Brendan Gregg: Linux Load Averages: Solving the Mystery

Hi

I understood how to check the load avg, but am curious about how to define the load avg or set the limit of load avg.
for ex: if my load avg of last 1 min is 1.6 which is high or low? on what basis we will say the load avg is high.

Hi

In theory you can get all the information to define a new metric for your load avg in the /proc/ folder, and mostly, I assuming is in /proc/stat file. So you can make a shell script to define a new metric with your requirements.

As far as I know, if your load avg is 1 it means one of your cpu cores is fully loaded with tasks. So if you have a one core cpu that means 100%, but if you have a dual core it means 50%, quad core 25% and so on. So if I’m not remembering wrong, you can be able to know when your load avg is high, depending of the total cores that your cpu have.

To set a limit, I guess you can limit the total process by the user that you want to do the tasks that you need. This is called a hard limit. In redhat based distros the config file mostly is in /etc/security/limits.d/20-nproc.conf , but this could change in other distros. You can search by nproc limit through the internet and find more information. But by setting the max number process that an user can instantiate in the system, in theory you will also define that an user can just use a certain amount of the cpu implicitly.