From: "Huang, Ying" <ying.huang@intel.com>
To: Zi Yan <ziy@nvidia.com>
Cc: <linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Yang Shi <shy828301@gmail.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Oscar Salvador <osalvador@suse.de>,
"Matthew Wilcox" <willy@infradead.org>
Subject: Re: [RFC 3/6] mm/migrate_pages: restrict number of pages to migrate in batch
Date: Thu, 22 Sep 2022 09:15:44 +0800 [thread overview]
Message-ID: <87edw4ky4f.fsf@yhuang6-desk2.ccr.corp.intel.com> (raw)
In-Reply-To: <46D92605-FED0-4473-9CBD-C3CB7DD46655@nvidia.com> (Zi Yan's message of "Wed, 21 Sep 2022 12:10:37 -0400")
Zi Yan <ziy@nvidia.com> writes:
> On 21 Sep 2022, at 2:06, Huang Ying wrote:
>
>> This is a preparation patch to batch the page unmapping and moving
>> for the normal pages and THP.
>>
>> If we had batched the page unmapping, all pages to be migrated would
>> be unmapped before copying the contents and flags of the pages. If
>> the number of pages that were passed to migrate_pages() was too large,
>> too many pages would be unmapped. Then, the execution of their
>> processes would be stopped for too long time. For example,
>> migrate_pages() syscall will call migrate_pages() with all pages of a
>> process. To avoid this possible issue, in this patch, we restrict the
>> number of pages to be migrated to be no more than HPAGE_PMD_NR. That
>> is, the influence is at the same level of THP migration.
>>
>> Signed-off-by: "Huang, Ying" <ying.huang@intel.com>
>> Cc: Zi Yan <ziy@nvidia.com>
>> Cc: Yang Shi <shy828301@gmail.com>
>> Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
>> Cc: Oscar Salvador <osalvador@suse.de>
>> Cc: Matthew Wilcox <willy@infradead.org>
>> ---
>> mm/migrate.c | 93 +++++++++++++++++++++++++++++++++++++---------------
>> 1 file changed, 67 insertions(+), 26 deletions(-)
>>
>> diff --git a/mm/migrate.c b/mm/migrate.c
>> index 4a81e0bfdbcd..1077af858e36 100644
>> --- a/mm/migrate.c
>> +++ b/mm/migrate.c
>> @@ -1439,32 +1439,7 @@ static inline int try_split_thp(struct page *page, struct list_head *split_pages
>> return rc;
>> }
>>
>> -/*
>> - * migrate_pages - migrate the pages specified in a list, to the free pages
>> - * supplied as the target for the page migration
>> - *
>> - * @from: The list of pages to be migrated.
>> - * @get_new_page: The function used to allocate free pages to be used
>> - * as the target of the page migration.
>> - * @put_new_page: The function used to free target pages if migration
>> - * fails, or NULL if no special handling is necessary.
>> - * @private: Private data to be passed on to get_new_page()
>> - * @mode: The migration mode that specifies the constraints for
>> - * page migration, if any.
>> - * @reason: The reason for page migration.
>> - * @ret_succeeded: Set to the number of normal pages migrated successfully if
>> - * the caller passes a non-NULL pointer.
>> - *
>> - * The function returns after 10 attempts or if no pages are movable any more
>> - * because the list has become empty or no retryable pages exist any more.
>> - * It is caller's responsibility to call putback_movable_pages() to return pages
>> - * to the LRU or free list only if ret != 0.
>> - *
>> - * Returns the number of {normal page, THP, hugetlb} that were not migrated, or
>> - * an error code. The number of THP splits will be considered as the number of
>> - * non-migrated THP, no matter how many subpages of the THP are migrated successfully.
>> - */
>> -int migrate_pages(struct list_head *from, new_page_t get_new_page,
>> +static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page,
>> free_page_t put_new_page, unsigned long private,
>> enum migrate_mode mode, int reason, unsigned int *ret_succeeded)
>> {
>> @@ -1709,6 +1684,72 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page,
>> return rc;
>> }
>>
>> +/*
>> + * migrate_pages - migrate the pages specified in a list, to the free pages
>> + * supplied as the target for the page migration
>> + *
>> + * @from: The list of pages to be migrated.
>> + * @get_new_page: The function used to allocate free pages to be used
>> + * as the target of the page migration.
>> + * @put_new_page: The function used to free target pages if migration
>> + * fails, or NULL if no special handling is necessary.
>> + * @private: Private data to be passed on to get_new_page()
>> + * @mode: The migration mode that specifies the constraints for
>> + * page migration, if any.
>> + * @reason: The reason for page migration.
>> + * @ret_succeeded: Set to the number of normal pages migrated successfully if
>> + * the caller passes a non-NULL pointer.
>> + *
>> + * The function returns after 10 attempts or if no pages are movable any more
>> + * because the list has become empty or no retryable pages exist any more.
>> + * It is caller's responsibility to call putback_movable_pages() to return pages
>> + * to the LRU or free list only if ret != 0.
>> + *
>> + * Returns the number of {normal page, THP, hugetlb} that were not migrated, or
>> + * an error code. The number of THP splits will be considered as the number of
>> + * non-migrated THP, no matter how many subpages of the THP are migrated successfully.
>> + */
>> +int migrate_pages(struct list_head *from, new_page_t get_new_page,
>> + free_page_t put_new_page, unsigned long private,
>> + enum migrate_mode mode, int reason, unsigned int *pret_succeeded)
>> +{
>> + int rc, rc_gether = 0;
>> + int ret_succeeded, ret_succeeded_gether = 0;
>> + int nr_pages;
>> + struct page *page;
>> + LIST_HEAD(pagelist);
>> + LIST_HEAD(ret_pages);
>> +
>> +again:
>> + nr_pages = 0;
>> + list_for_each_entry(page, from, lru) {
>> + nr_pages += compound_nr(page);
>> + if (nr_pages > HPAGE_PMD_NR)
>
> It is better to define a new MACRO like NR_MAX_BATCHED_MIGRATION to be
> HPAGE_PMD_NR. It makes code easier to understand and change.
OK. Will do that.
Best Regards,
Huang, Ying
>> + break;
>> + }
>> + if (nr_pages > HPAGE_PMD_NR)
>> + list_cut_before(&pagelist, from, &page->lru);
>> + else
>> + list_splice_init(from, &pagelist);
>> + rc = migrate_pages_batch(&pagelist, get_new_page, put_new_page, private,
>> + mode, reason, &ret_succeeded);
>> + ret_succeeded_gether += ret_succeeded;
>> + list_splice_tail_init(&pagelist, &ret_pages);
>> + if (rc == -ENOMEM) {
>> + rc_gether = rc;
>> + goto out;
>> + }
>> + rc_gether += rc;
>> + if (!list_empty(from))
>> + goto again;
>> +out:
>> + if (pret_succeeded)
>> + *pret_succeeded = ret_succeeded_gether;
>> + list_splice(&ret_pages, from);
>> +
>> + return rc_gether;
>> +}
>> +
>> struct page *alloc_migration_target(struct page *page, unsigned long private)
>> {
>> struct folio *folio = page_folio(page);
>> --
>> 2.35.1
>
>
> --
> Best Regards,
> Yan, Zi
next prev parent reply other threads:[~2022-09-22 1:15 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-21 6:06 [RFC 0/6] migrate_pages(): batch TLB flushing Huang Ying
2022-09-21 6:06 ` [RFC 1/6] mm/migrate_pages: separate huge page and normal pages migration Huang Ying
2022-09-21 15:55 ` Zi Yan
2022-09-22 1:14 ` Huang, Ying
2022-09-22 6:03 ` Baolin Wang
2022-09-22 6:22 ` Huang, Ying
2022-09-21 6:06 ` [RFC 2/6] mm/migrate_pages: split unmap_and_move() to _unmap() and _move() Huang Ying
2022-09-21 16:08 ` Zi Yan
2022-09-22 1:15 ` Huang, Ying
2022-09-22 6:36 ` Baolin Wang
2022-09-26 9:28 ` Alistair Popple
2022-09-26 18:06 ` Yang Shi
2022-09-27 0:02 ` Alistair Popple
2022-09-27 1:51 ` Huang, Ying
2022-09-27 20:34 ` John Hubbard
2022-09-27 20:57 ` Yang Shi
2022-09-28 0:59 ` Alistair Popple
2022-09-28 1:41 ` Huang, Ying
2022-09-28 1:44 ` John Hubbard
2022-09-28 1:49 ` Yang Shi
2022-09-28 1:56 ` John Hubbard
2022-09-28 2:14 ` Yang Shi
2022-09-28 2:57 ` John Hubbard
2022-09-28 3:25 ` Yang Shi
2022-09-28 3:39 ` Yang Shi
2022-09-27 20:56 ` Yang Shi
2022-09-27 20:54 ` Yang Shi
2022-09-21 6:06 ` [RFC 3/6] mm/migrate_pages: restrict number of pages to migrate in batch Huang Ying
2022-09-21 16:10 ` Zi Yan
2022-09-21 16:15 ` Zi Yan
2022-09-22 1:15 ` Huang, Ying [this message]
2022-09-21 6:06 ` [RFC 4/6] mm/migrate_pages: batch _unmap and _move Huang Ying
2022-09-21 6:06 ` [RFC 5/6] mm/migrate_pages: share more code between " Huang Ying
2022-09-21 6:06 ` [RFC 6/6] mm/migrate_pages: batch flushing TLB Huang Ying
2022-09-21 15:47 ` [RFC 0/6] migrate_pages(): batch TLB flushing Zi Yan
2022-09-22 1:45 ` Huang, Ying
2022-09-22 3:47 ` haoxin
2022-09-22 4:36 ` Huang, Ying
2022-09-22 12:50 ` Bharata B Rao
2022-09-23 7:52 ` Huang, Ying
2022-09-27 10:46 ` Bharata B Rao
2022-09-28 1:46 ` Huang, Ying
2022-09-26 9:11 ` Alistair Popple
2022-09-27 11:21 ` haoxin
2022-09-28 2:01 ` Huang, Ying
2022-09-28 3:33 ` haoxin
2022-09-28 4:53 ` Huang, Ying
2022-11-01 14:49 ` Hesham Almatary
2022-11-02 3:14 ` Huang, Ying
2022-11-02 14:13 ` Hesham Almatary
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87edw4ky4f.fsf@yhuang6-desk2.ccr.corp.intel.com \
--to=ying.huang@intel.com \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=osalvador@suse.de \
--cc=shy828301@gmail.com \
--cc=willy@infradead.org \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).