Linux-Doc Archive on lore.kernel.org
 help / color / Atom feed
From: Zi Yan <ziy@nvidia.com>
To: Randy Dunlap <rdunlap@infradead.org>,
	Anshuman Khandual <anshuman.khandual@arm.com>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: <linux-mm@kvack.org>, Jonathan Corbet <corbet@lwn.net>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@redhat.com>,
	Daniel Jordan <daniel.m.jordan@oracle.com>,
	Hugh Dickins <hughd@google.com>,
	Matthew Wilcox <willy@infradead.org>,
	John Hubbard <jhubbard@nvidia.com>,
	Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>,
	<linux-doc@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH V4] mm/vmstat: Add events for THP migration without split
Date: Thu, 9 Jul 2020 13:42:07 -0400
Message-ID: <C5E3C65C-8253-4638-9D3C-71A61858BB8B@nvidia.com> (raw)
In-Reply-To: <97219d3b-96e1-4371-59ea-d038f37a672a@infradead.org>


[-- Attachment #1: Type: text/plain, Size: 14705 bytes --]

On 9 Jul 2020, at 12:39, Randy Dunlap wrote:

> On 7/9/20 9:34 AM, Zi Yan wrote:
>> On 9 Jul 2020, at 11:34, Randy Dunlap wrote:
>>
>>> Hi,
>>>
>>> I have a few comments on this.
>>>
>>> a. I reported it very early and should have been Cc-ed.
>>>
>>> b. A patch that applies to mmotm or linux-next would have been better
>>> than a full replacement patch.
>>>
>>> c. I tried replacing what I believe is the correct/same patch file in mmotm
>>> and still have build errors.
>>>
>>> (more below)
>>>
>>> On 7/9/20 2:39 AM, Anshuman Khandual wrote:
>>>
>>>> ---
>>>> Applies on 5.8-rc4.
>>>>
>>>> Changes in V4:
>>>>
>>>> - Changed THP_MIGRATION_FAILURE as THP_MIGRATION_FAIL per John
>>>> - Dropped all conditional 'if' blocks in migrate_pages() per Andrew and John
>>>> - Updated migration events documentation per John
>>>> - Updated thp_nr_pages variable as nr_subpages for an expected merge conflict
>>>> - Moved all new THP vmstat events into CONFIG_MIGRATION
>>>> - Updated Cc list with Documentation/ and tracing related addresses
>>>>
>>>> Changes in V3: (https://patchwork.kernel.org/patch/11647237/)
>>>>
>>>> - Formatted new events documentation with 'fmt' tool per Matthew
>>>> - Made events universally available i.e dropped ARCH_ENABLE_THP_MIGRATION
>>>> - Added THP_MIGRATION_SPLIT
>>>> - Updated trace_mm_migrate_pages() with THP events
>>>> - Made THP events update normal page migration events as well
>>>>
>>>> Changes in V2: (https://patchwork.kernel.org/patch/11586893/)
>>>>
>>>> - Dropped PMD reference both from code and commit message per Matthew
>>>> - Added documentation and updated the commit message per Daniel
>>>>
>>>> Changes in V1: (https://patchwork.kernel.org/patch/11564497/)
>>>>
>>>> - Changed function name as thp_pmd_migration_success() per John
>>>> - Folded in a fix (https://patchwork.kernel.org/patch/11563009/) from Hugh
>>>>
>>>> Changes in RFC V2: (https://patchwork.kernel.org/patch/11554861/)
>>>>
>>>> - Decopupled and renamed VM events from their implementation per Zi and John
>>>> - Added THP_PMD_MIGRATION_FAILURE VM event upon allocation failure and split
>>>>
>>>> Changes in RFC V1: (https://patchwork.kernel.org/patch/11542055/)
>>>>
>>>>  Documentation/vm/page_migration.rst | 27 +++++++++++++++
>>>>  include/linux/vm_event_item.h       |  3 ++
>>>>  include/trace/events/migrate.h      | 17 ++++++++--
>>>>  mm/migrate.c                        | 52 ++++++++++++++++++++++++-----
>>>>  mm/vmstat.c                         |  3 ++
>>>>  5 files changed, 91 insertions(+), 11 deletions(-)
>>>>
>>>
>>>> diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
>>>> index 24fc7c3ae7d6..2e6ca53b9bbd 100644
>>>> --- a/include/linux/vm_event_item.h
>>>> +++ b/include/linux/vm_event_item.h
>>>> @@ -56,6 +56,9 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
>>>>  #endif
>>>>  #ifdef CONFIG_MIGRATION
>>>>  		PGMIGRATE_SUCCESS, PGMIGRATE_FAIL,
>>>> +		THP_MIGRATION_SUCCESS,
>>>> +		THP_MIGRATION_FAIL,
>>>> +		THP_MIGRATION_SPLIT,
>>>
>>> These 3 new symbols are still only present if CONFIG_MIGRATION=y, but the build errors
>>> are using these symbols even when CONFIG_MIGRATION is not set.
>>>
>>>>  #endif
>>>>  #ifdef CONFIG_COMPACTION
>>>>  		COMPACTMIGRATE_SCANNED, COMPACTFREE_SCANNED,
>>>
>>>> diff --git a/mm/migrate.c b/mm/migrate.c
>>>> index f37729673558..c706e3576cfc 100644
>>>> --- a/mm/migrate.c
>>>> +++ b/mm/migrate.c
>>>> @@ -1429,22 +1429,35 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page,
>>>>  		enum migrate_mode mode, int reason)
>>>>  {
>>>>  	int retry = 1;
>>>> +	int thp_retry = 1;
>>>>  	int nr_failed = 0;
>>>>  	int nr_succeeded = 0;
>>>> +	int nr_thp_succeeded = 0;
>>>> +	int nr_thp_failed = 0;
>>>> +	int nr_thp_split = 0;
>>>>  	int pass = 0;
>>>> +	bool is_thp = false;
>>>>  	struct page *page;
>>>>  	struct page *page2;
>>>>  	int swapwrite = current->flags & PF_SWAPWRITE;
>>>> -	int rc;
>>>> +	int rc, nr_subpages;
>>>>
>>>>  	if (!swapwrite)
>>>>  		current->flags |= PF_SWAPWRITE;
>>>>
>>>> -	for(pass = 0; pass < 10 && retry; pass++) {
>>>> +	for (pass = 0; pass < 10 && (retry || thp_retry); pass++) {
>>>>  		retry = 0;
>>>> +		thp_retry = 0;
>>>>
>>>>  		list_for_each_entry_safe(page, page2, from, lru) {
>>>>  retry:
>>>> +			/*
>>>> +			 * THP statistics is based on the source huge page.
>>>> +			 * Capture required information that might get lost
>>>> +			 * during migration.
>>>> +			 */
>>>> +			is_thp = PageTransHuge(page);
>>>> +			nr_subpages = hpage_nr_pages(page);
>>>>  			cond_resched();
>>>>
>>>>  			if (PageHuge(page))
>>>> @@ -1475,15 +1488,30 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page,
>>>>  					unlock_page(page);
>>>>  					if (!rc) {
>>>>  						list_safe_reset_next(page, page2, lru);
>>>> +						nr_thp_split++;
>>>>  						goto retry;
>>>>  					}
>>>>  				}
>>>> +				if (is_thp) {
>>>> +					nr_thp_failed++;
>>>> +					nr_failed += nr_subpages;
>>>> +					goto out;
>>>> +				}
>>>>  				nr_failed++;
>>>>  				goto out;
>>>>  			case -EAGAIN:
>>>> +				if (is_thp) {
>>>> +					thp_retry++;
>>>> +					break;
>>>> +				}
>>>>  				retry++;
>>>>  				break;
>>>>  			case MIGRATEPAGE_SUCCESS:
>>>> +				if (is_thp) {
>>>> +					nr_thp_succeeded++;
>>>> +					nr_succeeded += nr_subpages;
>>>> +					break;
>>>> +				}
>>>>  				nr_succeeded++;
>>>>  				break;
>>>>  			default:
>>>> @@ -1493,19 +1521,27 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page,
>>>>  				 * removed from migration page list and not
>>>>  				 * retried in the next outer loop.
>>>>  				 */
>>>> +				if (is_thp) {
>>>> +					nr_thp_failed++;
>>>> +					nr_failed += nr_subpages;
>>>> +					break;
>>>> +				}
>>>>  				nr_failed++;
>>>>  				break;
>>>>  			}
>>>>  		}
>>>>  	}
>>>> -	nr_failed += retry;
>>>> +	nr_failed += retry + thp_retry;
>>>> +	nr_thp_failed += thp_retry;
>>>>  	rc = nr_failed;
>>>>  out:
>>>> -	if (nr_succeeded)
>>>> -		count_vm_events(PGMIGRATE_SUCCESS, nr_succeeded);
>>>> -	if (nr_failed)
>>>> -		count_vm_events(PGMIGRATE_FAIL, nr_failed);
>>>> -	trace_mm_migrate_pages(nr_succeeded, nr_failed, mode, reason);
>>>> +	count_vm_events(PGMIGRATE_SUCCESS, nr_succeeded);
>>>> +	count_vm_events(PGMIGRATE_FAIL, nr_failed);
>>>> +	count_vm_events(THP_MIGRATION_SUCCESS, nr_thp_succeeded);
>>>> +	count_vm_events(THP_MIGRATION_FAIL, nr_thp_failed);
>>>> +	count_vm_events(THP_MIGRATION_SPLIT, nr_thp_split);
>>>
>>> These references still cause build errors.
>>>
>>>> +	trace_mm_migrate_pages(nr_succeeded, nr_failed, nr_thp_succeeded,
>>>> +			       nr_thp_failed, nr_thp_split, mode, reason);
>>>>
>>>>  	if (!swapwrite)
>>>>  		current->flags &= ~PF_SWAPWRITE;
>>>> diff --git a/mm/vmstat.c b/mm/vmstat.c
>>>> index 3fb23a21f6dd..09914a4bfee4 100644
>>>> --- a/mm/vmstat.c
>>>> +++ b/mm/vmstat.c
>>>> @@ -1234,6 +1234,9 @@ const char * const vmstat_text[] = {
>>>>  #ifdef CONFIG_MIGRATION
>>>>  	"pgmigrate_success",
>>>>  	"pgmigrate_fail",
>>>> +	"thp_migration_success",
>>>> +	"thp_migration_fail",
>>>> +	"thp_migration_split",
>>>>  #endif
>>>>  #ifdef CONFIG_COMPACTION
>>>>  	"compact_migrate_scanned",
>>>>
>>>
>>
>> Which arch are you building? I did not see any error
>> after applying this patch on mmotm (reverting the existing ones)
>> and compiling them on x86_64. I used make x86_64_defconfig and
>> unselected COMPACTION and MIGRATION.
>
> Hi,
>
> I am trying to build x86_64.
> Maybe I am just having trouble replacing the patch file.
> Like I tried to say, I would prefer to see an incremental patch
> to fix mmotm or linux-next.

I agree. The patch does not apply to mmotm. Can you try the incremental
patch below? It should apply to mmotm.


Hi Andrew and Anshuman,

Should Anshuman resend the incremental patch or Andrew can fold it along
with the two patches in mmotm into one?


diff --git a/Documentation/vm/page_migration.rst b/Documentation/vm/page_migration.rst
index e65d49f3cf86..68883ac485fa 100644
--- a/Documentation/vm/page_migration.rst
+++ b/Documentation/vm/page_migration.rst
@@ -253,24 +253,32 @@ which are function pointers of struct address_space_operations.
      PG_isolated is alias with PG_reclaim flag so driver shouldn't use the flag
      for own purpose.

-Quantifying Migration
+Monitoring Migration
 =====================
-Following events can be used to quantify page migration.
-
-1. PGMIGRATE_SUCCESS       /* Normal page migration success */
-2. PGMIGRATE_FAIL          /* Normal page migration failure */
-3. THP_MIGRATION_SUCCESS   /* Transparent huge page migration success */
-4. THP_MIGRATION_FAILURE   /* Transparent huge page migration failure */
-5. THP_MIGRATION_SPLIT     /* Transparent huge page got split, retried */
-
-THP_MIGRATION_SUCCESS is when THP is migrated successfully without getting
-split into it's subpages. THP_MIGRATION_FAILURE is when THP could neither
-be migrated nor be split. THP_MIGRATION_SPLIT is when THP could not
-just be migrated as is but instead get split into it's subpages and later
-retried as normal pages. THP events would also update normal page migration
-statistics PGMIGRATE_SUCCESS and PGMIGRATE_FAILURE. These events will help
-in quantifying and analyzing various THP migration events including both
-success and failure cases.
+
+The following events (counters) can be used to monitor page migration.
+
+1. PGMIGRATE_SUCCESS: Normal page migration success. Each count means that a
+   page was migrated. If the page was a non-THP page, then this counter is
+   increased by one. If the page was a THP, then this counter is increased by
+   the number of THP subpages. For example, migration of a single 2MB THP that
+   has 4KB-size base pages (subpages) will cause this counter to increase by
+   512.
+
+2. PGMIGRATE_FAIL: Normal page migration failure. Same counting rules as for
+   _SUCCESS, above: this will be increased by the number of subpages, if it was
+   a THP.
+
+3. THP_MIGRATION_SUCCESS: A THP was migrated without being split.
+
+4. THP_MIGRATION_FAIL: A THP could not be migrated nor it could be split.
+
+5. THP_MIGRATION_SPLIT: A THP was migrated, but not as such: first, the THP had
+   to be split. After splitting, a migration retry was used for it's sub-pages.
+
+THP_MIGRATION_* events also update the appropriate PGMIGRATE_SUCCESS or
+PGMIGRATE_FAIL events. For example, a THP migration failure will cause both
+THP_MIGRATION_FAIL and PGMIGRATE_FAIL to increase.

 Christoph Lameter, May 8, 2006.
 Minchan Kim, Mar 28, 2016.
diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
index 5e7ffa025589..2e6ca53b9bbd 100644
--- a/include/linux/vm_event_item.h
+++ b/include/linux/vm_event_item.h
@@ -56,6 +56,9 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
 #endif
 #ifdef CONFIG_MIGRATION
 		PGMIGRATE_SUCCESS, PGMIGRATE_FAIL,
+		THP_MIGRATION_SUCCESS,
+		THP_MIGRATION_FAIL,
+		THP_MIGRATION_SPLIT,
 #endif
 #ifdef CONFIG_COMPACTION
 		COMPACTMIGRATE_SCANNED, COMPACTFREE_SCANNED,
@@ -95,9 +98,6 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
 		THP_ZERO_PAGE_ALLOC_FAILED,
 		THP_SWPOUT,
 		THP_SWPOUT_FALLBACK,
-		THP_MIGRATION_SUCCESS,
-		THP_MIGRATION_FAILURE,
-		THP_MIGRATION_SPLIT,
 #endif
 #ifdef CONFIG_MEMORY_BALLOON
 		BALLOON_INFLATE,
diff --git a/mm/migrate.c b/mm/migrate.c
index b0125c082549..c6cb8e676f9d 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -1425,7 +1425,7 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page,
 	struct page *page;
 	struct page *page2;
 	int swapwrite = current->flags & PF_SWAPWRITE;
-	int rc, thp_n_pages;
+	int rc, nr_subpages;

 	if (!swapwrite)
 		current->flags |= PF_SWAPWRITE;
@@ -1442,7 +1442,7 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page,
 			 * during migration.
 			 */
 			is_thp = PageTransHuge(page);
-			thp_n_pages = thp_nr_pages(page);
+			nr_subpages = thp_nr_pages(page);
 			cond_resched();

 			if (PageHuge(page))
@@ -1479,7 +1479,7 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page,
 				}
 				if (is_thp) {
 					nr_thp_failed++;
-					nr_failed += thp_n_pages;
+					nr_failed += nr_subpages;
 					goto out;
 				}
 				nr_failed++;
@@ -1494,7 +1494,7 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page,
 			case MIGRATEPAGE_SUCCESS:
 				if (is_thp) {
 					nr_thp_succeeded++;
-					nr_succeeded += thp_n_pages;
+					nr_succeeded += nr_subpages;
 					break;
 				}
 				nr_succeeded++;
@@ -1508,7 +1508,7 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page,
 				 */
 				if (is_thp) {
 					nr_thp_failed++;
-					nr_failed += thp_n_pages;
+					nr_failed += nr_subpages;
 					break;
 				}
 				nr_failed++;
@@ -1520,16 +1520,11 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page,
 	nr_thp_failed += thp_retry;
 	rc = nr_failed;
 out:
-	if (nr_succeeded)
-		count_vm_events(PGMIGRATE_SUCCESS, nr_succeeded);
-	if (nr_failed)
-		count_vm_events(PGMIGRATE_FAIL, nr_failed);
-	if (nr_thp_succeeded)
-		count_vm_events(THP_MIGRATION_SUCCESS, nr_thp_succeeded);
-	if (nr_thp_failed)
-		count_vm_events(THP_MIGRATION_FAILURE, nr_thp_failed);
-	if (nr_thp_split)
-		count_vm_events(THP_MIGRATION_SPLIT, nr_thp_split);
+	count_vm_events(PGMIGRATE_SUCCESS, nr_succeeded);
+	count_vm_events(PGMIGRATE_FAIL, nr_failed);
+	count_vm_events(THP_MIGRATION_SUCCESS, nr_thp_succeeded);
+	count_vm_events(THP_MIGRATION_FAIL, nr_thp_failed);
+	count_vm_events(THP_MIGRATION_SPLIT, nr_thp_split);
 	trace_mm_migrate_pages(nr_succeeded, nr_failed, nr_thp_succeeded,
 			       nr_thp_failed, nr_thp_split, mode, reason);

diff --git a/mm/vmstat.c b/mm/vmstat.c
index 9892090df6a2..a21140373edb 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1274,6 +1274,9 @@ const char * const vmstat_text[] = {
 #ifdef CONFIG_MIGRATION
 	"pgmigrate_success",
 	"pgmigrate_fail",
+	"thp_migration_success",
+	"thp_migration_fail",
+	"thp_migration_split",
 #endif
 #ifdef CONFIG_COMPACTION
 	"compact_migrate_scanned",
@@ -1320,9 +1323,6 @@ const char * const vmstat_text[] = {
 	"thp_zero_page_alloc_failed",
 	"thp_swpout",
 	"thp_swpout_fallback",
-	"thp_migration_success",
-	"thp_migration_failure",
-	"thp_migration_split",
 #endif
 #ifdef CONFIG_MEMORY_BALLOON
 	"balloon_inflate",




—
Best Regards,
Yan Zi

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 854 bytes --]

  reply index

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-09  9:39 Anshuman Khandual
2020-07-09 15:34 ` Randy Dunlap
2020-07-09 16:34   ` Zi Yan
2020-07-09 16:39     ` Randy Dunlap
2020-07-09 17:42       ` Zi Yan [this message]
2020-07-09 20:15         ` John Hubbard
2020-07-09 21:24         ` Randy Dunlap
2020-07-10  3:41         ` Anshuman Khandual
2020-07-24 15:04         ` Daniel Jordan
2020-07-10  3:30   ` Anshuman Khandual
2020-07-10  3:33     ` Randy Dunlap

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=C5E3C65C-8253-4638-9D3C-71A61858BB8B@nvidia.com \
    --to=ziy@nvidia.com \
    --cc=akpm@linux-foundation.org \
    --cc=anshuman.khandual@arm.com \
    --cc=corbet@lwn.net \
    --cc=daniel.m.jordan@oracle.com \
    --cc=hughd@google.com \
    --cc=jhubbard@nvidia.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mingo@redhat.com \
    --cc=n-horiguchi@ah.jp.nec.com \
    --cc=rdunlap@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=willy@infradead.org \
    /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

Linux-Doc Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-doc/0 linux-doc/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-doc linux-doc/ https://lore.kernel.org/linux-doc \
		linux-doc@vger.kernel.org
	public-inbox-index linux-doc

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-doc


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git