Re: [PATCH v4 4/8] hugetlb: perform vmemmap restoration on a list of pages
From: Mike Kravetz
Date: Thu Sep 21 2023 - 18:12:38 EST
On 09/21/23 17:31, Muchun Song wrote:
>
>
> On 2023/9/21 09:12, Mike Kravetz wrote:
> > On 09/20/23 11:03, Muchun Song wrote:
> > > > On Sep 20, 2023, at 10:56, Muchun Song <muchun.song@xxxxxxxxx> wrote:
> > > > > On Sep 20, 2023, at 04:57, Mike Kravetz <mike.kravetz@xxxxxxxxxx> wrote:
> > > > > On 09/19/23 17:52, Muchun Song wrote:
> > > > > > On 2023/9/19 07:01, Mike Kravetz wrote:
> > +/**
> > + * hugetlb_vmemmap_restore_folios - restore vmemmap for every folio on the list.
> > + * @h: struct hstate.
> > + * @folio_list: list of folios.
> > + * @restored: Set to number of folios for which vmemmap was restored
> > + * successfully if caller passes a non-NULL pointer.
> > + *
> > + * Return: %0 if vmemmap exists for all folios on the list. If an error is
> > + * encountered restoring vmemmap for ANY folio, an error code
> > + * will be returned to the caller. It is then the responsibility
> > + * of the caller to check the hugetlb vmemmap optimized flag of
> > + * each folio to determine if vmemmap was actually restored.
> > + * Note that processing is stopped when first error is encountered.
> > + */
> > +int hugetlb_vmemmap_restore_folios(const struct hstate *h,
> > + struct list_head *folio_list,
> > + unsigned long *restored)
>
> How about changing parameter of @restored to a list_head type which
> returns the non-optimized (previously) or vmemmap-restored-sucessful huge
> pages?
> In which case, the caller could traverse this returned list to free
> them first like you have implemented in bulk_vmemmap_restore_enomem(),
> it will be more efficient. The meaning of returned value should also
> be changed accordingly since update_and_free_pages_bulk() wants to
> whether there is a vmemmap-optimized huge page being restored sucessfully
> to determine if it should clear hugetlb flag. So
> hugetlb_vmemmap_restore_folios()
> could return how many huge pages being restored successful, if a negative
> number is returned meaning there is some error in the process of restoring
> of vmemmap.
>
I had similar thoughts. An updated patch based on this approach is below.
When creating the patch, I discovered that using the function return code
for both number of vmemmap restored pages as well as error code was
unnecessary. Just checking !list_empty() of non-optimized pages tells us
if any were restored or could be freed.