linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] sched: make nr_running() return "unsigned int"
@ 2020-03-11 21:06 Alexey Dobriyan
  2020-03-11 21:08 ` [PATCH 2/2] sched: make nr_iowait_cpu() " Alexey Dobriyan
  2020-03-12 10:44 ` [PATCH 1/2] sched: make nr_running() " Peter Zijlstra
  0 siblings, 2 replies; 4+ messages in thread
From: Alexey Dobriyan @ 2020-03-11 21:06 UTC (permalink / raw)
  To: mingo, peterz; +Cc: linux-kernel

I don't anyone have been crazy enough to spawn 2^32 threads.
It'd require absurd amounts of physical memory.

Meanwhile save few bits on REX prefixes.

And remove "extern" from prototypes while I'm at it.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 fs/proc/loadavg.c          |    2 +-
 fs/proc/stat.c             |    2 +-
 include/linux/sched/stat.h |    2 +-
 kernel/sched/core.c        |    4 ++--
 4 files changed, 5 insertions(+), 5 deletions(-)

--- a/fs/proc/loadavg.c
+++ b/fs/proc/loadavg.c
@@ -16,7 +16,7 @@ static int loadavg_proc_show(struct seq_file *m, void *v)
 
 	get_avenrun(avnrun, FIXED_1/200, 0);
 
-	seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
+	seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %u/%d %d\n",
 		LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
 		LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
 		LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
--- a/fs/proc/stat.c
+++ b/fs/proc/stat.c
@@ -197,7 +197,7 @@ static int show_stat(struct seq_file *p, void *v)
 		"\nctxt %llu\n"
 		"btime %llu\n"
 		"processes %lu\n"
-		"procs_running %lu\n"
+		"procs_running %u\n"
 		"procs_blocked %lu\n",
 		nr_context_switches(),
 		(unsigned long long)boottime.tv_sec,
--- a/include/linux/sched/stat.h
+++ b/include/linux/sched/stat.h
@@ -16,7 +16,7 @@ extern unsigned long total_forks;
 extern int nr_threads;
 DECLARE_PER_CPU(unsigned long, process_counts);
 extern int nr_processes(void);
-extern unsigned long nr_running(void);
+unsigned int nr_running(void);
 extern bool single_task_running(void);
 extern unsigned long nr_iowait(void);
 extern unsigned long nr_iowait_cpu(int cpu);
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3389,9 +3389,9 @@ context_switch(struct rq *rq, struct task_struct *prev,
  * externally visible scheduler statistics: current number of runnable
  * threads, total number of context switches performed since bootup.
  */
-unsigned long nr_running(void)
+unsigned int nr_running(void)
 {
-	unsigned long i, sum = 0;
+	unsigned int i, sum = 0;
 
 	for_each_online_cpu(i)
 		sum += cpu_rq(i)->nr_running;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] sched: make nr_iowait_cpu() return "unsigned int"
  2020-03-11 21:06 [PATCH 1/2] sched: make nr_running() return "unsigned int" Alexey Dobriyan
@ 2020-03-11 21:08 ` Alexey Dobriyan
  2020-03-12 10:44 ` [PATCH 1/2] sched: make nr_running() " Peter Zijlstra
  1 sibling, 0 replies; 4+ messages in thread
From: Alexey Dobriyan @ 2020-03-11 21:08 UTC (permalink / raw)
  To: mingo, peterz; +Cc: linux-kernel

Same logic: 2^32 threads stuck waiting in runqueue implies
2^32+ processes total which is absurd.

Per-runqueue ->nr_iowait member being 32-bit hints that it is
correct change!

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 fs/proc/stat.c             |    2 +-
 include/linux/sched/stat.h |    4 ++--
 kernel/sched/core.c        |    6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)

--- a/fs/proc/stat.c
+++ b/fs/proc/stat.c
@@ -198,7 +198,7 @@ static int show_stat(struct seq_file *p, void *v)
 		"btime %llu\n"
 		"processes %lu\n"
 		"procs_running %u\n"
-		"procs_blocked %lu\n",
+		"procs_blocked %u\n",
 		nr_context_switches(),
 		(unsigned long long)boottime.tv_sec,
 		total_forks,
--- a/include/linux/sched/stat.h
+++ b/include/linux/sched/stat.h
@@ -18,8 +18,8 @@ DECLARE_PER_CPU(unsigned long, process_counts);
 extern int nr_processes(void);
 unsigned int nr_running(void);
 extern bool single_task_running(void);
-extern unsigned long nr_iowait(void);
-extern unsigned long nr_iowait_cpu(int cpu);
+unsigned int nr_iowait(void);
+unsigned int nr_iowait_cpu(int cpu);
 
 static inline int sched_info_on(void)
 {
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3436,7 +3436,7 @@ unsigned long long nr_context_switches(void)
  * it does become runnable.
  */
 
-unsigned long nr_iowait_cpu(int cpu)
+unsigned int nr_iowait_cpu(int cpu)
 {
 	return atomic_read(&cpu_rq(cpu)->nr_iowait);
 }
@@ -3471,9 +3471,9 @@ unsigned long nr_iowait_cpu(int cpu)
  * Task CPU affinities can make all that even more 'interesting'.
  */
 
-unsigned long nr_iowait(void)
+unsigned int nr_iowait(void)
 {
-	unsigned long i, sum = 0;
+	unsigned int i, sum = 0;
 
 	for_each_possible_cpu(i)
 		sum += nr_iowait_cpu(i);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] sched: make nr_running() return "unsigned int"
  2020-03-11 21:06 [PATCH 1/2] sched: make nr_running() return "unsigned int" Alexey Dobriyan
  2020-03-11 21:08 ` [PATCH 2/2] sched: make nr_iowait_cpu() " Alexey Dobriyan
@ 2020-03-12 10:44 ` Peter Zijlstra
  2020-03-12 17:09   ` Alexey Dobriyan
  1 sibling, 1 reply; 4+ messages in thread
From: Peter Zijlstra @ 2020-03-12 10:44 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: mingo, linux-kernel

On Thu, Mar 12, 2020 at 12:06:08AM +0300, Alexey Dobriyan wrote:
> I don't anyone have been crazy enough to spawn 2^32 threads.
> It'd require absurd amounts of physical memory.

And we're going to 5 level page-tables because 48 bits physical isn't
enough. 57 bits of physical is plenty space to spawn that many tasks and
still have some left over.

Now 32 bit tasks is indeed insane, but memory isn't the problem. The
actual limit is the pid-space, which is 30 bits.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] sched: make nr_running() return "unsigned int"
  2020-03-12 10:44 ` [PATCH 1/2] sched: make nr_running() " Peter Zijlstra
@ 2020-03-12 17:09   ` Alexey Dobriyan
  0 siblings, 0 replies; 4+ messages in thread
From: Alexey Dobriyan @ 2020-03-12 17:09 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: mingo, linux-kernel

On Thu, Mar 12, 2020 at 11:44:27AM +0100, Peter Zijlstra wrote:
> On Thu, Mar 12, 2020 at 12:06:08AM +0300, Alexey Dobriyan wrote:
> > I don't anyone have been crazy enough to spawn 2^32 threads.
> > It'd require absurd amounts of physical memory.
> 
> And we're going to 5 level page-tables because 48 bits physical isn't
> enough. 57 bits of physical is plenty space to spawn that many tasks and
> still have some left over.
> 
> Now 32 bit tasks is indeed insane, but memory isn't the problem. The
> actual limit is the pid-space, which is 30 bits.

Indeed, pid space limit is even better!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-03-12 17:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-11 21:06 [PATCH 1/2] sched: make nr_running() return "unsigned int" Alexey Dobriyan
2020-03-11 21:08 ` [PATCH 2/2] sched: make nr_iowait_cpu() " Alexey Dobriyan
2020-03-12 10:44 ` [PATCH 1/2] sched: make nr_running() " Peter Zijlstra
2020-03-12 17:09   ` Alexey Dobriyan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).