2

On Linux, the load average is the average number of processes that are either runnable or waiting averaged over the past 1, 5 and 15 minutes.

On OpenBSD (and possibly other BSDs, but neither the quote nor the context really says), load average is "the number of processes which have (wanted to) run at least once in the most recent 5-second window, with a degradation over time".

However, I was unable to locate information on how load average is actually defined on FreeBSD.

What is the exact meaning of the load average numbers on FreeBSD?

  • Comment: Since recently (Dec 2016?), kernel threads counts towards the load average on OpenBSD. An idle OpenBSD system will therefore have a load of about 1. – Kusalananda Feb 1 '17 at 10:32
  • Ah sorry. :/ On irc discussions went that this could indeed be a bug in FreeBSD 11 as 10.2 does not behave the same way. – larsemil Feb 1 '17 at 10:54
  • @larsemil I have no idea what you are referring to. Are you saying that in FreeBSD 11, the existence of load averages is a bug? – a CVn Feb 1 '17 at 10:56
  • No. But how it handles it. I dont know, just quoting what was said in the FreeBSD IRC channel. – larsemil Feb 1 '17 at 11:00
  • Just to an update to my previous comment here: OpenBSD 6.2 now does no longer include kernel threads when calculating the load average. That was something happening in OpenBSD 6.1 only, it seems. – Kusalananda Oct 27 '17 at 8:01
1

In the tradition of UTSL, I've pasted in the code that runs the calculation. Here, nrun=sched_load() is the total "ready to run" processes this instant and avg is pointing to a structure with 3 fixed point numbers (1,5,15 minutes). cexp are magic numbers to decay the values for 1,5 and 15 minutes. For reference, this is in /usr/src/sys/kern/kern_synch.c ... which I might recommend as a fascinating read.

In FreeBSD, what most surprises people about responsive machines with high load averages is that a spot awakening of a large number of processes can inflate the numbers greatly. IE: if 400-ish processes all awake together (web servers or database servers sometimes do this.)

/*
 * Compute a tenex style load average of a quantity on
 * 1, 5 and 15 minute intervals.
 */
static void
loadav(void *arg)
{
    int i, nrun;
    struct loadavg *avg;

    nrun = sched_load();
    avg = &averunnable;

    for (i = 0; i < 3; i++)
        avg->ldavg[i] = (cexp[i] * avg->ldavg[i] +
            nrun * FSCALE * (FSCALE - cexp[i])) >> FSHIFT;
    /*
     * Schedule the next update to occur after 5 seconds, but add a
     * random variation to avoid synchronisation with processes that
     * run at regular intervals.
     */
    callout_reset_sbt(&loadav_callout,
        SBT_1US * (4000000 + (int)(random() % 2000001)), SBT_1US,
        loadav, NULL, C_DIRECT_EXEC | C_PREL(32));
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.