Skip to contentSkip to conversation

ubifs: fix page_count in ->ubifs_migrate_page()

PATCH In review zhangjun 3 participants 4 messages Dec 13, 2018

Subsystems (3)
lore
Share & tools
lore

zhangjun

author
#0 lore raw

PATCH v2 1/1 ubifs: fix page_count in ->ubifs_migrate_page()

Because the PagePrivate() in UBIFS is different meanings, alloc_cma() will fail when one dirty page cache located in the type of MIGRATE_CMA

If not adjust the 'extra_count' for dirty page, ubifs_migrate_page() -> migrate_page_move_mapping() will always return -EAGAIN for:

	expected_count += page_has_private(page)

This causes the migration to fail until the page cache is cleaned

In general, PagePrivate() indicates that buff_head is already bound to this page, and at the same time page_count() will also increase. But UBIFS set private flag when the cache is dirty, and page_count() not increase.
Therefore, the expected_count of UBIFS is different from the general case.

---
 fs/ubifs/file.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
fs/ubifs/file.c +10 -1
index 1b78f2e..890dfce 100644
@@ -1480,8 +1480,17 @@ static int ubifs_migrate_page(struct address_space *mapping,
 		struct page *newpage, struct page *page, enum migrate_mode mode)
 {
 	int rc;
+	int extra_count = 0;
 
-	rc = migrate_page_move_mapping(mapping, newpage, page, NULL, mode, 0);
+	/*
+	 * UBIFS uses PG_private as marker and does not raise the page counter.
+	 * migrate_page_move_mapping() expects a incremented counter if
+	 * PG_private is set. Therefore pass -1 as extra_count for this case.
+	 */
+	if (page_has_private(page))
+		extra_count = -1;
+	rc = migrate_page_move_mapping(mapping, newpage, page,
+			NULL, mode, extra_count);
 	if (rc != MIGRATEPAGE_SUCCESS)
 		return rc;
 
Signature · 1 line
2.7.4
#1 lore raw

Am Donnerstag, 13. Dezember 2018, 20:20:17 CET schrieb zhangjun:

Quoted 1 line

Because the PagePrivate() in UBIFS is different meanings,

...has different meanings...

I'll fix up that myself after applying your patch. No need to send a v3.

Quoted 9 lines

alloc_cma() will fail when one dirty page cache located in the type of MIGRATE_CMA

If not adjust the 'extra_count' for dirty page, ubifs_migrate_page() -> migrate_page_move_mapping() will always return -EAGAIN for:

	expected_count += page_has_private(page)

This causes the migration to fail until the page cache is cleaned

Quoted 8 lines

In general, PagePrivate() indicates that buff_head is already bound to this page, and at the same time page_count() will also increase. But UBIFS set private flag when the cache is dirty, and page_count() not increase.
Therefore, the expected_count of UBIFS is different from the general case.

Fixes 4ac1c17b2044 ("UBIFS: Implement ->migratepage()")
Quoted 17 lines
---
 fs/ubifs/file.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
fs/ubifs/file.c +3 -1
index 1b78f2e..890dfce 100644
@@ -1480,8 +1480,17 @@ static int ubifs_migrate_page(struct address_space *mapping,
 		struct page *newpage, struct page *page, enum migrate_mode mode)
 {
 	int rc;
+	int extra_count = 0;
 
-	rc = migrate_page_move_mapping(mapping, newpage, page, NULL, mode, 0);
+	/*
+	 * UBIFS uses PG_private as marker and does not raise the page counter.

fs/ubifs/file.c static int ubifs_migrate_page(struct address_space *mapping, · line 1496

Quoted 10 lines
fs/ubifs/file.c +7 -0
+	 * migrate_page_move_mapping() expects a incremented counter if
+	 * PG_private is set. Therefore pass -1 as extra_count for this case.
+	 */
+	if (page_has_private(page))
+		extra_count = -1;
+	rc = migrate_page_move_mapping(mapping, newpage, page,
+			NULL, mode, extra_count);
 	if (rc != MIGRATEPAGE_SUCCESS)
 		return rc;
 

Let's wait a few days to give Kirill a chance to review, then I'll apply the patch.

Thanks,
//richard

#2 lore raw
Quoted 41 lines · Richard Weinberger

Am Donnerstag, 13. Dezember 2018, 20:20:17 CET schrieb zhangjun:

Quoted 1 line

Because the PagePrivate() in UBIFS is different meanings,

...has different meanings...

I'll fix up that myself after applying your patch. No need to send a v3.

Quoted 9 lines

alloc_cma() will fail when one dirty page cache located in the type of MIGRATE_CMA

If not adjust the 'extra_count' for dirty page, ubifs_migrate_page() -> migrate_page_move_mapping() will always return -EAGAIN for:

	expected_count += page_has_private(page)

This causes the migration to fail until the page cache is cleaned

Quoted 8 lines

In general, PagePrivate() indicates that buff_head is already bound to this page, and at the same time page_count() will also increase. But UBIFS set private flag when the cache is dirty, and page_count() not increase.
Therefore, the expected_count of UBIFS is different from the general case.

Fixes 4ac1c17b2044 ("UBIFS: Implement ->migratepage()")
Quoted 14 lines
---
 fs/ubifs/file.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
fs/ubifs/file.c +1 -0
index 1b78f2e..890dfce 100644
@@ -1480,8 +1480,17 @@ static int ubifs_migrate_page(struct address_space *mapping,
 		struct page *newpage, struct page *page, enum migrate_mode mode)
 {
 	int rc;
+	int extra_count = 0;
 
Quoted 15 lines

fs/ubifs/file.c static int ubifs_migrate_page(struct address_space *mapping, · line 1496

Quoted 13 lines
fs/ubifs/file.c +9 -1
-	rc = migrate_page_move_mapping(mapping, newpage, page, NULL, mode, 0);
+	/*
+	 * UBIFS uses PG_private as marker and does not raise the page counter.
+	 * migrate_page_move_mapping() expects a incremented counter if
+	 * PG_private is set. Therefore pass -1 as extra_count for this case.
+	 */
+	if (page_has_private(page))
+		extra_count = -1;
+	rc = migrate_page_move_mapping(mapping, newpage, page,
+			NULL, mode, extra_count);
 	if (rc != MIGRATEPAGE_SUCCESS)
 		return rc;
 

Let's wait a few days to give Kirill a chance to review, then I'll apply the patch.

I don't remmeber much context now...

Could you remind me why ubifs doesn't take additional pin when sets PG_private?

Migration is not the only place where the additional pin is implied. See all users of page_has_private() helper. Notably reclaim path.

Signature · 1 line
 Kirill A. Shutemov
#3 lore raw

Am Donnerstag, 13. Dezember 2018, 23:00:00 CET schrieb Kirill A. Shutemov:

Quoted 6 lines
Quoted 1 line

Let's wait a few days to give Kirill a chance to review, then I'll apply the patch.

I don't remmeber much context now...

Could you remind me why ubifs doesn't take additional pin when sets PG_private?

Because it does not use set_page_private(), it just sets the flag for internal accounting purposes.

Quoted 1 line

From UBIFS docs:

* UBIFS uses 2 page flags: @PG_private and @PG_checked. @PG_private is set if
* the page is dirty and is used for optimization purposes - dirty pages are
* not budgeted so the flag shows that 'ubifs_write_end()' should not release
* the budget for this page. The @PG_checked flag is set if full budgeting is
* required for the page e.g., when it corresponds to a file hole or it is
* beyond the file size. The budgeting is done in 'ubifs_write_begin()', because
* it is OK to fail in this function, and the budget is released in
* 'ubifs_write_end()'. So the @PG_private and @PG_checked flags carry
* information about how the page was budgeted, to make it possible to release
* the budget properly.

Quoted 2 lines

Migration is not the only place where the additional pin is implied. See all users of page_has_private() helper. Notably reclaim path.

Hmmm, I need to dig into that.
I this is a problem then f2fs suffers from it too.
At least from what I can tell from reading f2fs_migrate_page().

Thanks,
//richard