How is "/proc/loadavg" updated regularly on Linux?

Asked 2 years ago, Updated 2 years ago, 38 views

From the Linux source code, we know that get_avenrun() is called in fs/proc/loadavg.c to take the average load average for 1 minute, 5 minutes and 15 minutes (for example, cat/proc/loadavg).And if you look at the source code [*2] of get_avenrun() in kernel/sched/loadavg.c, you can see that avenrun[i] is simply substituted for the first argument.Calling this function periodically is because you cannot update /proc/loadavg.

kernel/sched/loadavg.c has only two functions to write the unsigned long avenrun[3] global variable.

  • static void calc_global_nohz(void)
  • void calc_global_load (unsigned long ticks)

Which internal process or thread periodically invokes the above functions, or can avenrun[3] be updated periodically in a different way?

Also, what is the distinction between the two functions?

11 https://github.com/torvalds/linux/blob/345671ea0f9258f410eb057b9ced9cefbbe5dc78/fs/proc/loadavg.c#L17

22 https://github.com/torvalds/linux/blob/345671ea0f9258f410eb057b9ced9cefbbe5dc78/kernel/sched/loadavg.c#L73

linux

2022-09-30 19:39

1 Answers

I'm not sure about the Linux kernel, so it's appropriate, but the comments in calc_global_load() on the link are as follows, so I think it's a timer interrupt.

/*
 * calc_load-update the avenrun load estimates 10 ticks after the
 * CPU have updated calc_load_tasks.
 *
 * Called from the global timer code.
 */

So calc_global_nohz() is a Tickless process by name.


2022-09-30 19:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.