On Sat, 13 Aug 2022 07:41:09 +0000 cgel.zte@xxxxxxxxx wrote: > From: Yang Yang <yang.yang29@xxxxxxxxxx> > > Once upon a time, we only support accounting thrashing of page cache. > Then Joonsoo introduced workingset detection for anonymous pages and > we gained the ability to account thrashing of them[1]. > > For page cache thrashing accounting, there is no suitable place to do > it in fs level likes swap_readpage(). So we have to do it in > folio_wait_bit_common(). > > Then for anonymous pages thrashing accounting, we have to do it in > both swap_readpage() and folio_wait_bit_common(). This likes PSI, > so we should let thrashing accounting supports re-entrance detection. > > This patch is to prepare complete thrashing accounting, and is based > on patch "filemap: make the accounting of thrashing more consistent". > > -static inline void delayacct_thrashing_start(void) > +static inline void delayacct_thrashing_start(unsigned long *flags) I don't think that `flags' is a very descriptive name. It might be anything. > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -943,6 +943,10 @@ struct task_struct { > #ifdef CONFIG_CPU_SUP_INTEL > unsigned reported_split_lock:1; > #endif > +#ifdef CONFIG_TASK_DELAY_ACCT > + /* delay due to memory thrashing */ > + unsigned in_thrashing:1; > +#endif OK, saving space in the task_struct is good. > unsigned long atomic_flags; /* Flags requiring atomic access. */ > > diff --git a/kernel/delayacct.c b/kernel/delayacct.c > index 164ed9ef77a3..a5916196022f 100644 > --- a/kernel/delayacct.c > +++ b/kernel/delayacct.c > @@ -214,13 +214,22 @@ void __delayacct_freepages_end(void) > ¤t->delays->freepages_count); > } > > -void __delayacct_thrashing_start(void) > +void __delayacct_thrashing_start(unsigned long *flags) > { > + *flags = current->in_thrashing; > + if (*flags) > + return; Can't we rename `flags' to `in_thrashing' throughout? And may as well give it type `bool'. And convert that bool to/from the bitfield when moving it in and out of the task_struct with *in_thrashing = !!current->in_thrashing; current->in_thrashing = (in_thrashing != 0);