Skip to contentSkip to conversation

mm: migrate.c: migrate PG_readahead flag

PATCH Applied Yang Shi 5 participants 6 messages Feb 14, 2020

Subsystems (2)
lore
Share & tools
lore

Yang Shi

author
#0 lore raw

PATCH 1/1 mm: migrate.c: migrate PG_readahead flag

Currently migration code doesn't migrate PG_readahead flag. Theoretically this would incur slight performance loss as the application might have to ramp its readahead back up again. Even though such problem happens, it might be hidden by something else since migration is typically triggered by compaction and NUMA balancing, any of which should be more noticeable.

Migrate the flag after end_page_writeback() since it may clear PG_reclaim flag, which is the same bit as PG_readahead, for the new page.

Cc Matthew Wilcox <[email protected]>
Cc Michal Hocko <[email protected]>

---
I didn't experience any real problem, found by visual inspection. And, this was
discussed in thread: https://lore.kernel.org/linux-mm/[email protected]/T/#m1977ce1de513401b7d09d6fa14fcffe849580aae

 mm/migrate.c | 8 ++++++++
 1 file changed, 8 insertions(+)
mm/migrate.c +8 -0
index edf42ed..f3c492d 100644
@@ -647,6 +647,14 @@ void migrate_page_states(struct page *newpage, struct page *page)
 	if (PageWriteback(newpage))
 		end_page_writeback(newpage);
 
+	/*
+	 * PG_readahead share the same bit with PG_reclaim, the above
+	 * end_page_writeback() may clear PG_readahead mistakenly, so set
+	 * the bit after that.
+	 */
+	if (PageReadahead(page))
+		SetPageReadahead(newpage);
+
 	copy_page_owner(page, newpage);
 
 	mem_cgroup_migrate(page, newpage);
Signature · 1 line
1.8.3.1
maintainer
#1 lore raw
Quoted 17 lines · On Fri, 14 Feb 2020 08:29:45 +0800 Yang Shi <[email protected]> wrote:

Currently migration code doesn't migrate PG_readahead flag. Theoretically this would incur slight performance loss as the application might have to ramp its readahead back up again. Even though such problem happens, it might be hidden by something else since migration is typically triggered by compaction and NUMA balancing, any of which should be more noticeable.

Migrate the flag after end_page_writeback() since it may clear PG_reclaim flag, which is the same bit as PG_readahead, for the new page.

mm/migrate.c +0 -0
@@ -647,6 +647,14 @@ void migrate_page_states(struct page *newpage, struct page *page)
 	if (PageWriteback(newpage))
 		end_page_writeback(newpage);
 

mm/migrate.c void migrate_page_states(struct page *newpage, struct page *page) · line 659

Quoted 10 lines
mm/migrate.c +8 -0
+	/*
+	 * PG_readahead share the same bit with PG_reclaim, the above
+	 * end_page_writeback() may clear PG_readahead mistakenly, so set
+	 * the bit after that.
+	 */
+	if (PageReadahead(page))
+		SetPageReadahead(newpage);
+
 	copy_page_owner(page, newpage);
 

Why not

if (PageWriteback(newpage)) {

  		end_page_writeback(newpage);
		/*
		 * PG_readahead share the same bit with PG_reclaim, the above
		 * end_page_writeback() may clear PG_readahead mistakenly, so
		 * set the bit after that.
		 */
		if (PageReadahead(page))
			SetPageReadahead(newpage);
	}

?

author
#2 lore raw
Quoted 19 lines · Andrew Morton
Quoted 17 lines · On Fri, 14 Feb 2020 08:29:45 +0800 Yang Shi <[email protected]> wrote:

Currently migration code doesn't migrate PG_readahead flag. Theoretically this would incur slight performance loss as the application might have to ramp its readahead back up again. Even though such problem happens, it might be hidden by something else since migration is typically triggered by compaction and NUMA balancing, any of which should be more noticeable.

Migrate the flag after end_page_writeback() since it may clear PG_reclaim flag, which is the same bit as PG_readahead, for the new page.

mm/migrate.c +0 -0
@@ -647,6 +647,14 @@ void migrate_page_states(struct page *newpage, struct page *page)
  	if (PageWriteback(newpage))
  		end_page_writeback(newpage);
 
Quoted 11 lines

mm/migrate.c void migrate_page_states(struct page *newpage, struct page *page) · line 659

Quoted 10 lines
mm/migrate.c +8 -0
+	/*
+	 * PG_readahead share the same bit with PG_reclaim, the above
+	 * end_page_writeback() may clear PG_readahead mistakenly, so set
+	 * the bit after that.
+	 */
+	if (PageReadahead(page))
+		SetPageReadahead(newpage);
+
  	copy_page_owner(page, newpage);
 

Why not

The newpage may not have writeback set, migrating readahead flag should not depend on it.

Quoted 13 lines
   	if (PageWriteback(newpage)) {
   		end_page_writeback(newpage);
		/*
		 * PG_readahead share the same bit with PG_reclaim, the above
		 * end_page_writeback() may clear PG_readahead mistakenly, so
		 * set the bit after that.
		 */
		if (PageReadahead(page))
			SetPageReadahead(newpage);
	}

?

#3 lore raw
Quoted 29 lines · Yang Shi
Quoted 12 lines · Andrew Morton
Quoted 11 lines · On Fri, 14 Feb 2020 08:29:45 +0800 Yang Shi <[email protected]> wrote:

Currently migration code doesn't migrate PG_readahead flag. Theoretically this would incur slight performance loss as the application might have to ramp its readahead back up again. Even though such problem happens, it might be hidden by something else since migration is typically triggered by compaction and NUMA balancing, any of which should be more noticeable.

Migrate the flag after end_page_writeback() since it may clear PG_reclaim flag, which is the same bit as PG_readahead, for the new page.

Quoted 15 lines
Quoted 4 lines
mm/migrate.c +0 -0
@@ -647,6 +647,14 @@ void migrate_page_states(struct page *newpage, struct page *page)
  	if (PageWriteback(newpage))

mm/migrate.c void migrate_page_states(struct page *newpage, struct page *page) · line 657

Quoted 10 lines
mm/migrate.c +8 -0
  		end_page_writeback(newpage);
+	/*
+	 * PG_readahead share the same bit with PG_reclaim, the above
+	 * end_page_writeback() may clear PG_readahead mistakenly, so set
+	 * the bit after that.
+	 */
+	if (PageReadahead(page))
+		SetPageReadahead(newpage);
+
  	copy_page_owner(page, newpage);

Why not

Quoted 2 lines

The newpage may not have writeback set, migrating readahead flag should not depend on it.

Indeed, if the page has writeback set, then the page does not have the readahead flag set; it has the reclaim flag set. The original patch is correct, afaict.

Quoted 13 lines
Quoted 12 lines
   	if (PageWriteback(newpage)) {
   		end_page_writeback(newpage);
		/*
		 * PG_readahead share the same bit with PG_reclaim, the above
		 * end_page_writeback() may clear PG_readahead mistakenly, so
		 * set the bit after that.
		 */
		if (PageReadahead(page))
			SetPageReadahead(newpage);
	}

?

Acked-by on v1 1/1
#4 lore raw
In reply to Yang Shi
Quoted 10 lines · Yang Shi

Currently migration code doesn't migrate PG_readahead flag. Theoretically this would incur slight performance loss as the application might have to ramp its readahead back up again. Even though such problem happens, it might be hidden by something else since migration is typically triggered by compaction and NUMA balancing, any of which should be more noticeable.

Migrate the flag after end_page_writeback() since it may clear PG_reclaim flag, which is the same bit as PG_readahead, for the new page.

Looks like an omission. The readahead flag has been added later (2.6.23) while the migration predates 2.6.17.

Quoted 3 lines
Cc Matthew Wilcox <[email protected]>
Cc Michal Hocko <[email protected]>
Quoted 28 lines

---
I didn't experience any real problem, found by visual inspection. And, this was
discussed in thread: https://lore.kernel.org/linux-mm/[email protected]/T/#m1977ce1de513401b7d09d6fa14fcffe849580aae

 mm/migrate.c | 8 ++++++++
 1 file changed, 8 insertions(+)
mm/migrate.c +8 -0
index edf42ed..f3c492d 100644
@@ -647,6 +647,14 @@ void migrate_page_states(struct page *newpage, struct page *page)
 	if (PageWriteback(newpage))
 		end_page_writeback(newpage);
 
+	/*
+	 * PG_readahead share the same bit with PG_reclaim, the above
+	 * end_page_writeback() may clear PG_readahead mistakenly, so set
+	 * the bit after that.
+	 */
+	if (PageReadahead(page))
+		SetPageReadahead(newpage);
+
 	copy_page_owner(page, newpage);
 
 	mem_cgroup_migrate(page, newpage);
Signature · 1 line
1.8.3.1
Signature · 2 lines
Michal Hocko
SUSE Labs
Reviewed-by on v1 1/1
#5 lore raw
In reply to Yang Shi
Quoted 31 lines · Yang Shi

Currently migration code doesn't migrate PG_readahead flag. Theoretically this would incur slight performance loss as the application might have to ramp its readahead back up again. Even though such problem happens, it might be hidden by something else since migration is typically triggered by compaction and NUMA balancing, any of which should be more noticeable.

Migrate the flag after end_page_writeback() since it may clear PG_reclaim flag, which is the same bit as PG_readahead, for the new page.

Cc Matthew Wilcox <[email protected]>
Cc Michal Hocko <[email protected]>

---
I didn't experience any real problem, found by visual inspection. And, this was
discussed in thread: https://lore.kernel.org/linux-mm/[email protected]/T/#m1977ce1de513401b7d09d6fa14fcffe849580aae

 mm/migrate.c | 8 ++++++++
 1 file changed, 8 insertions(+)
mm/migrate.c +1 -0
index edf42ed..f3c492d 100644
@@ -647,6 +647,14 @@ void migrate_page_states(struct page *newpage, struct page *page)
 	if (PageWriteback(newpage))
 		end_page_writeback(newpage);
 
+	/*

mm/migrate.c void migrate_page_states(struct page *newpage, struct page *page) · line 660

Quoted 10 lines
mm/migrate.c +7 -0
+	 * PG_readahead share the same bit with PG_reclaim, the above
+	 * end_page_writeback() may clear PG_readahead mistakenly, so set
+	 * the bit after that.
+	 */
+	if (PageReadahead(page))
+		SetPageReadahead(newpage);
+
 	copy_page_owner(page, newpage);
 
 	mem_cgroup_migrate(page, newpage);

Looks good to me!

Signature · 3 lines
Thanks,

David / dhildenb