On Tue, Dec 01, 2020 at 07:54:13PM +0800, Yafang Shao wrote: > If we want to use schedstats facility, we should move out of > struct sched_statistics from the struct sched_entity or add it into other > sctructs of sched entity as well. Obviously the latter one is bad because > that requires more spaces. So we should move it into a common struct which > can be used by all sched classes. > > The struct sched_statistics is the schedular statistics of a task_struct > or a task_group. So we can move it into struct task_struct and > struct task_group to achieve the goal. > > Below is the detailed explaination of the change in the structs. > > - Before this patch > > struct task_struct { |-> struct sched_entity { > ... | ... > struct sched_entity *se; ---| struct sched_statistics statistics; > struct sched_rt_entity *rt; ... > ... ... > }; }; > > struct task_group { |--> se[0]->statistics : schedstats of CPU0 > ... | > #ifdef CONFIG_FAIR_GROUP_SCHED | > struct sched_entity **se; --|--> se[1]->statistics : schedstats of CPU1 > | > #endif | > |--> se[N]->statistics : schedstats of CPUn > > #ifdef CONFIG_FAIR_GROUP_SCHED > struct sched_rt_entity **rt_se; (N/A) > #endif > ... > }; > > The '**se' in task_group is allocated in the fair sched class, which is > hard to be reused by other sched class. > > - After this patch > > struct task_struct { > ... > struct sched_statistics statistics; > ... > struct sched_entity *se; > struct sched_rt_entity *rt; > ... > }; > > struct task_group { |---> stats[0] : of CPU0 > ... | > struct sched_statistics **stats; --|---> stats[1] : of CPU1 > ... | > |---> stats[n] : of CPUn > #ifdef CONFIG_FAIR_GROUP_SCHED > struct sched_entity **se; > #endif > #ifdef CONFIG_RT_GROUP_SCHED > struct sched_rt_entity **rt_se; > #endif > ... > }; > > After the patch it is clearly that both of se or rt_se can easily get the > sched_statistics by a task_struct or a task_group. > > Signed-off-by: Yafang Shao <laoar.shao@xxxxxxxxx> I didn't see anything wrong as such, it's mostly a mechanical conversion. The one slight caveat is the potential change in cache location for the statistics but it's not necessarily negative. The stats potentially move to a different cache line but it's less obvious whether that even matters given the location is very similar. There is increased overhead now when schedstats are *enabled* because _schedstat_from_sched_entity() has to be called but it appears that it is protected by a schedstat_enabled() check. So ok, schedstats when enabled are now a bit more expensive but they were expensive in the first place so does it matter? I'd have been happied if there was a comparison with schedstats enabled just in case the overhead is too high but it could also do with a second set of eyeballs. It's somewhat tentative but Acked-by: Mel Gorman <mgorman@xxxxxxx> -- Mel Gorman SUSE Labs