Re: [PATCH -v4 7/9] migrate_pages: share more code between _unmap and _move
From: Huang, Ying
Date: Fri Feb 10 2023 - 02:10:21 EST
Zi Yan <ziy@xxxxxxxxxx> writes:
> On 8 Feb 2023, at 7:02, Huang, Ying wrote:
>
>> Zi Yan <ziy@xxxxxxxxxx> writes:
>>
>>> On 6 Feb 2023, at 1:33, Huang Ying wrote:
>>>
>>>> This is a code cleanup patch to reduce the duplicated code between the
>>>> _unmap and _move stages of migrate_pages(). No functionality change
>>>> is expected.
>>>>
>>>> Signed-off-by: "Huang, Ying" <ying.huang@xxxxxxxxx>
>>>> Cc: Zi Yan <ziy@xxxxxxxxxx>
>>>> Cc: Yang Shi <shy828301@xxxxxxxxx>
>>>> Cc: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>
>>>> Cc: Oscar Salvador <osalvador@xxxxxxx>
>>>> Cc: Matthew Wilcox <willy@xxxxxxxxxxxxx>
>>>> Cc: Bharata B Rao <bharata@xxxxxxx>
>>>> Cc: Alistair Popple <apopple@xxxxxxxxxx>
>>>> Cc: haoxin <xhao@xxxxxxxxxxxxxxxxx>
>>>> Cc: Minchan Kim <minchan@xxxxxxxxxx>
>>>> Cc: Mike Kravetz <mike.kravetz@xxxxxxxxxx>
>>>> Cc: Hyeonggon Yoo <42.hyeyoo@xxxxxxxxx>
>>>> ---
>>>> mm/migrate.c | 203 ++++++++++++++++++++-------------------------------
>>>> 1 file changed, 81 insertions(+), 122 deletions(-)
>>>>
>>>> diff --git a/mm/migrate.c b/mm/migrate.c
>>>> index 23eb01cfae4c..9378fa2ad4a5 100644
>>>> --- a/mm/migrate.c
>>>> +++ b/mm/migrate.c
>>>> @@ -1037,6 +1037,7 @@ static void __migrate_folio_extract(struct folio *dst,
>>>> static void migrate_folio_undo_src(struct folio *src,
>>>> int page_was_mapped,
>>>> struct anon_vma *anon_vma,
>>>> + bool locked,
>>>> struct list_head *ret)
>>>> {
>>>> if (page_was_mapped)
>>>> @@ -1044,16 +1045,20 @@ static void migrate_folio_undo_src(struct folio *src,
>>>> /* Drop an anon_vma reference if we took one */
>>>> if (anon_vma)
>>>> put_anon_vma(anon_vma);
>>>> - folio_unlock(src);
>>>> - list_move_tail(&src->lru, ret);
>>>> + if (locked)
>>>> + folio_unlock(src);
>>>
>>> Having a comment would be better.
>>> /* A page that has not been migrated, move it to a list for later restoration */
>>
>> Emm... the page state has been restored in the previous operations of
>> the function. This is the last step and the page will be moved to
>> "return" list, then the caller of migrate_pages() will call
>> putback_movable_pages().
>
> But if (rc == -EAGAIN || rc == -EDEADLOCK) then ret will be NULL, thus the page
> will not be put back, right?
Yes. That is a special case.
> And for both cases, the src page state is not
> changed at all.
Their state should be restored to the original state too for being
processed again. That is done in the previous operations too. For
example, if the folio has been locked, before return with -EAGAIN, we
need to unlock the folio, otherwise, we will run into double lock.
> So probably only call migrate_folio_undo_src() when
> (rc != -EAGAIN && rc != -EDEADLOCK)? And still require ret to be non NULL.
>
>>
>> We have some comments for the function (migrate_folio_undo_src()) as
>> follows,
>>
>> /* Restore the source folio to the original state upon failure */
>>
>>>> + if (ret)
>>>> + list_move_tail(&src->lru, ret);
>>>> }
>>>>
[snip]
Best Regards,
Huang, Ying