Re: [PATCH 2/3] delayacct: convert task->delays to a object

From: brookxu
Date: Sun Oct 08 2023 - 07:10:11 EST



在 2023/10/8 18:58, Peter Zijlstra 写道:
On Sun, Oct 08, 2023 at 06:49:37PM +0800, brookxu.cn wrote:
From: Chunguang Xu <chunguang.xu@xxxxxxxxxx>

Since in some scenarios we still want to get the task delayacct
through taskstats, so commit <0cd7c741f01de> introduces a sysctl to
This is not the canonical way to reference a commit.

enable it dynamically. However, since task->delays is allocated
during fork(), task->delays will not be reallocated when delayacct
is enabled later. This will make we cannot get the delayacct of old
tasks, but the new tasks cans. This can easily lead to confusion.
Therefore, try to workaround this issue by convert task->delays to
an object.
And grow task_struct for no reason? I think not.

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 77f01ac385f7..5cc78184a31f 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -37,6 +37,7 @@
#include <linux/kcsan.h>
#include <linux/rv.h>
#include <linux/livepatch_sched.h>
+#include <linux/delayacct.h>
#include <asm/kmap_size.h>
/* task_struct member predeclarations (sorted alphabetically): */
@@ -1331,7 +1332,7 @@ struct task_struct {
struct page_frag task_frag;
#ifdef CONFIG_TASK_DELAY_ACCT
- struct task_delay_info *delays;
+ struct task_delay_info delays;
#endif
Yeah, no.
Yes, this way will increase about 80 bytes for task_struct, about 0.85% of size of task_struct, I think this just like sched_statistics, so that can better support dynamically enable through sysctl.