lkml.org 
[lkml]   [2023]   [Apr]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] sysinfo: Saturate 16-bit procs rather than wrapping
struct sysinfo has a 16-bit field for the number of processes. Current
systems can easily exceed this. Rather than wrapping around, saturate
the value at U16_MAX. This is still incorrect, but more likely to
help the user know what's going on; a caller can then (for instance)
parse the full value out of /proc/loadavg.

Signed-off-by: Josh Triplett <josh@joshtriplett.org>
---

Not sure what tree changes to kernel/sys.c should flow through. Andrew,
could you take this through your tree (assuming you agree with it), or
suggest what tree it should go through instead?

diff --git a/kernel/sys.c b/kernel/sys.c
index 495cd87d9bf4..ba05fca26927 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -2699,7 +2699,7 @@ static int do_sysinfo(struct sysinfo *info)

get_avenrun(info->loads, 0, SI_LOAD_SHIFT - FSHIFT);

- info->procs = nr_threads;
+ info->procs = min_t(typeof(nr_threads), nr_threads, U16_MAX);

si_meminfo(info);
si_swapinfo(info);
--
2.40.0
\
 
 \ /
  Last update: 2023-04-02 05:58    [W:0.076 / U:0.332 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site