On Mon, Sep 27, 2021 at 03:31:21AM -0700, Nadav Amit wrote: > > > > On Sep 27, 2021, at 2:31 AM, Kirill A. Shutemov <kirill@xxxxxxxxxxxxx> wrote: > > > > On Sun, Sep 26, 2021 at 09:12:55AM -0700, Nadav Amit wrote: > >> From: Nadav Amit <namit@xxxxxxxxxx> > >> > >> The different behaviors of madvise are different in several ways, which > >> are distributed across several functions. Use the design pattern from > >> iouring in order to define the actions that are required for each > >> behavior. > >> > >> The next patches will get rid of old helper functions that are modified > >> in this patch and the redundant use of array_index_nospec(). The next > >> patches will add more actions for each leaf into the new struct. > >> > >> No functional change is intended. > >> > >> Cc: Andrea Arcangeli <aarcange@xxxxxxxxxx> > >> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> > >> Cc: Minchan Kim <minchan@xxxxxxxxxx> > >> Cc: Colin Cross <ccross@xxxxxxxxxx> > >> Cc: Suren Baghdasarya <surenb@xxxxxxxxxx> > >> Cc: Mike Rapoport <rppt@xxxxxxxxxxxxxxxxxx> > >> Signed-off-by: Nadav Amit <namit@xxxxxxxxxx> > >> --- > >> mm/madvise.c | 168 +++++++++++++++++++++++++++++++++------------------ > >> 1 file changed, 109 insertions(+), 59 deletions(-) > >> > >> diff --git a/mm/madvise.c b/mm/madvise.c > >> index 17e39c70704b..127507c71ba9 100644 > >> --- a/mm/madvise.c > >> +++ b/mm/madvise.c > >> @@ -29,6 +29,7 @@ > >> #include <linux/swapops.h> > >> #include <linux/shmem_fs.h> > >> #include <linux/mmu_notifier.h> > >> +#include <linux/nospec.h> > >> > >> #include <asm/tlb.h> > >> > >> @@ -39,6 +40,101 @@ struct madvise_walk_private { > >> bool pageout; > >> }; > >> > >> +struct madvise_info { > >> + u8 behavior_valid: 1; > >> + u8 process_behavior_valid: 1; > >> + u8 need_mmap_read_only: 1; > >> +}; > >> + > >> +static const struct madvise_info madvise_info[MADV_SOFT_OFFLINE+1] = { > > > > MADV_SOFT_OFFLINE+1 smells bad. > > I can set another constant instead and let the compiler shout if anything > outside the array is initialized. I would rather introduce a function that would return struct madvise_info for a given behavior. The function would have a switch inside. The default: may have BUILD_BUG() or something. -- Kirill A. Shutemov