Message ID | 20220720140603.1958773-2-zokeefe@google.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | mm: fixes for userspace hugepage collapse, v7 | expand |
On Wed, Jul 20, 2022 at 7:06 AM Zach O'Keefe <zokeefe@google.com> wrote: > > Minimally, node_load[] entries just need to be able to hold the maximum > value of HPAGE_PMD_NR, which is compile-time defined per-arch based on > PMD_SHIFT and PAGE_SHIFT. node_load[] is only written either via memset(), > or with via post-increment. struct collapse_control may be allocated > via kmalloc() in other collapse contexts, and MAX_NUMNODES may be > arbitrarily large. #define the underlying type of node_load[] based off > HPAGE_PMD_NR to avoid excessive memory allocated for this struct. > > Fixes: 3b07f3bb225a ("mm/khugepaged: add struct collapse_control") > Link: https://lore.kernel.org/linux-mm/Ys2CeIm%2FQmQwWh9a@google.com/ > Signed-off-by: Zach O'Keefe <zokeefe@google.com> Reviewed-by: Yang Shi <shy828301@gmail.com> > --- > mm/khugepaged.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 69990dacde14..ecd28bfeab60 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -92,8 +92,11 @@ struct collapse_control { > bool is_khugepaged; > > /* Num pages scanned per node */ > - int node_load[MAX_NUMNODES]; > - > +#if HPAGE_PMD_ORDER < 16 > + u16 node_load[MAX_NUMNODES]; > +#else > + u32 node_load[MAX_NUMNODES]; > +#endif > /* Last target selected in hpage_collapse_find_target_node() */ > int last_target_node; > }; > -- > 2.37.0.170.g444d1eabd0-goog >
On Wed, 20 Jul 2022, Zach O'Keefe wrote: > Minimally, node_load[] entries just need to be able to hold the maximum > value of HPAGE_PMD_NR, which is compile-time defined per-arch based on > PMD_SHIFT and PAGE_SHIFT. node_load[] is only written either via memset(), > or with via post-increment. struct collapse_control may be allocated > via kmalloc() in other collapse contexts, and MAX_NUMNODES may be > arbitrarily large. #define the underlying type of node_load[] based off > HPAGE_PMD_NR to avoid excessive memory allocated for this struct. > > Fixes: 3b07f3bb225a ("mm/khugepaged: add struct collapse_control") > Link: https://lore.kernel.org/linux-mm/Ys2CeIm%2FQmQwWh9a@google.com/ > Signed-off-by: Zach O'Keefe <zokeefe@google.com> Acked-by: David Rientjes <rientjes@google.com>
diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 69990dacde14..ecd28bfeab60 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -92,8 +92,11 @@ struct collapse_control { bool is_khugepaged; /* Num pages scanned per node */ - int node_load[MAX_NUMNODES]; - +#if HPAGE_PMD_ORDER < 16 + u16 node_load[MAX_NUMNODES]; +#else + u32 node_load[MAX_NUMNODES]; +#endif /* Last target selected in hpage_collapse_find_target_node() */ int last_target_node; };
Minimally, node_load[] entries just need to be able to hold the maximum value of HPAGE_PMD_NR, which is compile-time defined per-arch based on PMD_SHIFT and PAGE_SHIFT. node_load[] is only written either via memset(), or with via post-increment. struct collapse_control may be allocated via kmalloc() in other collapse contexts, and MAX_NUMNODES may be arbitrarily large. #define the underlying type of node_load[] based off HPAGE_PMD_NR to avoid excessive memory allocated for this struct. Fixes: 3b07f3bb225a ("mm/khugepaged: add struct collapse_control") Link: https://lore.kernel.org/linux-mm/Ys2CeIm%2FQmQwWh9a@google.com/ Signed-off-by: Zach O'Keefe <zokeefe@google.com> --- mm/khugepaged.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)