[PATCH] per_task: Remove the PER_TASK_BYTES hard-coded constant

From: Ingo Molnar
Date: Tue Jan 04 2022 - 09:10:58 EST



* Ingo Molnar <mingo@xxxxxxxxxx> wrote:

> There's one thing ugly about it, the fixed PER_TASK_BYTES limit, I plan
> to make ->per_task_array[] the last field of task_struct, i.e. change it
> to:
>
> u8 per_task_area[];
>
> This actually became possible through the fixing of the x86 FPU code in the
> following fast-headers commit:
>
> 4ae0f28bc1c8 headers/deps: x86/fpu: Make task_struct::thread constant size

So I implemented this approach - the patch below removes the PER_TASK_BYTES
hard-coded limit.

( Didn't make it variable size via per_task_area[] though - we *do* know
its size after all at build time already, and known-size structures are
better in general than tail-variable-array solutions:

- They work better with static checkers,
- and we actually want the offsets into thread_info to be small on embedded platforms

etc. )

Thanks,

Ingo

============================>
From: Ingo Molnar <mingo@xxxxxxxxxx>
Date: Tue, 4 Jan 2022 13:48:05 +0100
Subject: [PATCH] per_task: Remove the PER_TASK_BYTES hard-coded constant

- Also remove the unnecessary <linux/sched/per_task_types.h> header.

Not-Signed-off-by-yet: Ingo Molnar <mingo@xxxxxxxxxx>
---
include/linux/sched/per_task.h | 3 ++-
include/linux/sched/per_task_types.h | 7 -------
kernel/sched/core.c | 4 ++++
3 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/include/linux/sched/per_task.h b/include/linux/sched/per_task.h
index e20837e82681..a10538713a26 100644
--- a/include/linux/sched/per_task.h
+++ b/include/linux/sched/per_task.h
@@ -37,7 +37,6 @@
* A build-time check ensures that we haven't run out of available space.
*/

-#include <linux/sched/per_task_types.h>
#include <linux/compiler.h>

#ifndef __PER_TASK_GEN
@@ -61,4 +60,6 @@

#define per_task_container_of(var, name) container_of((void *)(var) - per_task_offset(name), struct task_struct, per_task_area[0])

+#define PER_TASK_BYTES (per_task_offset(_end))
+
#endif /* _LINUX_SCHED_PER_TASK_H */
diff --git a/include/linux/sched/per_task_types.h b/include/linux/sched/per_task_types.h
deleted file mode 100644
index 8af8c10f8dae..000000000000
--- a/include/linux/sched/per_task_types.h
+++ /dev/null
@@ -1,7 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _LINUX_SCHED_PER_TASK_TYPES_H
-#define _LINUX_SCHED_PER_TASK_TYPES_H
-
-#define PER_TASK_BYTES 8192
-
-#endif /* _LINUX_SCHED_PER_TASK_TYPES_H */
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index bc38b19f6398..fdb5b99ae6e0 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -89,6 +89,8 @@
#include "../../fs/io-wq.h"
#include "../smpboot.h"

+#include "../../../kernel/sched/per_task_area_struct.h"
+
DEFINE_PER_TASK(unsigned int, flags);

#ifdef CONFIG_THREAD_INFO_IN_TASK
@@ -9481,6 +9483,8 @@ void __init per_task_init(void)
{
unsigned long per_task_bytes = per_task_offset(_end);

+ printk("per_task: sizeof(struct task_struct): %ld bytes\n", sizeof(struct task_struct));
+ printk("per_task: sizeof(struct task_struct_per_task): %ld bytes\n", sizeof(struct task_struct_per_task));
printk("per_task: Using %ld per_task bytes, %ld bytes available\n", per_task_bytes, (long)PER_TASK_BYTES);

BUG_ON(per_task_offset(_end) > PER_TASK_BYTES);