Skip to contentSkip to conversation

mm,thp: stop leaking unreleased file pages

PATCH In review Hugh Dickins 6 participants 8 messages May 24, 2020 – Jun 3, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm,thp: stop leaking unreleased file pages

When collapse_file() calls try_to_release_page(), it has already isolated the page: so if releasing buffers happens to fail (as it sometimes does), remember to putback_lru_page(): otherwise that page is left unreclaimable and unfreeable, and the file extent uncollapsible.

Fixes 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")

---

 mm/khugepaged.c |    1 +
 1 file changed, 1 insertion(+)
mm/khugepaged.c +1 -0
@@ -1692,6 +1692,7 @@ static void collapse_file(struct mm_stru
 		if (page_has_private(page) &&
 		    !try_to_release_page(page, GFP_KERNEL)) {
 			result = SCAN_PAGE_HAS_PRIVATE;
+			putback_lru_page(page);
 			goto out_unlock;
 		}
 
Acked-by on v1 1/1
#1 lore raw
Quoted 12 lines · Hugh Dickins

When collapse_file() calls try_to_release_page(), it has already isolated the page: so if releasing buffers happens to fail (as it sometimes does), remember to putback_lru_page(): otherwise that page is left unreclaimable and unfreeable, and the file extent uncollapsible.

Fixes 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")

Thanks for the fix!

Quoted 15 lines

---

mm/khugepaged.c | 1 +

1 file changed, 1 insertion(+)
mm/khugepaged.c +1 -0
@@ -1692,6 +1692,7 @@ static void collapse_file(struct mm_stru
 		if (page_has_private(page) &&
 		    !try_to_release_page(page, GFP_KERNEL)) {
 			result = SCAN_PAGE_HAS_PRIVATE;
+			putback_lru_page(page);
 			goto out_unlock;
 		}
 
Acked-by on v1 1/1
#2 lore raw
In reply to Hugh Dickins
Quoted 8 lines · Hugh Dickins

When collapse_file() calls try_to_release_page(), it has already isolated the page: so if releasing buffers happens to fail (as it sometimes does), remember to putback_lru_page(): otherwise that page is left unreclaimable and unfreeable, and the file extent uncollapsible.

Fixes 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")
Signature · 1 line
 Kirill A. Shutemov
Acked-by on v1 1/1
#3 lore raw
In reply to Hugh Dickins
Quoted 4 lines · Hugh Dickins

When collapse_file() calls try_to_release_page(), it has already isolated the page: so if releasing buffers happens to fail (as it sometimes does), remember to putback_lru_page(): otherwise that page is left unreclaimable and unfreeable, and the file extent uncollapsible.

Oof, I could imagine that was painful to debug (unless you already suspected file THP due to a targeted test or similar). Kudos.

Quoted 3 lines
Fixes 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")
#4 lore raw
Quoted 8 lines · Johannes Weiner
Quoted 4 lines · Hugh Dickins

When collapse_file() calls try_to_release_page(), it has already isolated the page: so if releasing buffers happens to fail (as it sometimes does), remember to putback_lru_page(): otherwise that page is left unreclaimable and unfreeable, and the file extent uncollapsible.

Oof, I could imagine that was painful to debug (unless you already suspected file THP due to a targeted test or similar). Kudos.

Thanks, but I have to refuse both your admiration and sympathy:
mercifully, it was just something I noticed by source inspection when working there.

I did then put in a debug count to see if it ever got hit in practice, and checked after big multi-testing runs: it was sometimes hit, but certainly not often, and I don't know what it was racing with when it happened - would depend on filesystem anyway (ext4 in our case).

Saying "source inspection" reminds me: there is another funny in there, but I don't think it matters very much in practice, and might need rather a lot of testing to justify any particular patch: where page_cache_sync_readahead() asks for PAGE_SIZE pages!

"end - index" seems a more reasonable number to me: but then we might find that reading ahead into the next huge extent had actually been a useful optimization (and those readahead functions impose their own caps, so PAGE_SIZE shouldn't work out too outrageously).

Hugh

Quoted 6 lines
Quoted 4 lines
Fixes 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")
#5 lore raw
Quoted 25 lines · Hugh Dickins
Quoted 8 lines · Johannes Weiner
Quoted 4 lines · Hugh Dickins

When collapse_file() calls try_to_release_page(), it has already isolated the page: so if releasing buffers happens to fail (as it sometimes does), remember to putback_lru_page(): otherwise that page is left unreclaimable and unfreeable, and the file extent uncollapsible.

Oof, I could imagine that was painful to debug (unless you already suspected file THP due to a targeted test or similar). Kudos.

Thanks, but I have to refuse both your admiration and sympathy:
mercifully, it was just something I noticed by source inspection when working there.

I did then put in a debug count to see if it ever got hit in practice, and checked after big multi-testing runs: it was sometimes hit, but certainly not often, and I don't know what it was racing with when it happened - would depend on filesystem anyway (ext4 in our case).

Saying "source inspection" reminds me: there is another funny in there, but I don't think it matters very much in practice, and might need rather a lot of testing to justify any particular patch: where page_cache_sync_readahead() asks for PAGE_SIZE pages!

Quoted 4 lines

"end - index" seems a more reasonable number to me: but then we might find that reading ahead into the next huge extent had actually been a useful optimization (and those readahead functions impose their own caps, so PAGE_SIZE shouldn't work out too outrageously).

My two cents,
Do you have a test case / test steps to validate this patch ?

- Naresh

#6 lore raw
In reply to Hugh Dickins
Quoted 9 lines · Hugh Dickins

Saying "source inspection" reminds me: there is another funny in there, but I don't think it matters very much in practice, and might need rather a lot of testing to justify any particular patch: where page_cache_sync_readahead() asks for PAGE_SIZE pages!

"end - index" seems a more reasonable number to me: but then we might find that reading ahead into the next huge extent had actually been a useful optimization (and those readahead functions impose their own caps, so PAGE_SIZE shouldn't work out too outrageously).

That readahead was only added in 99cb0dbd47a15d395bf3faa78dc122bc5efe3fc0 so it probably hasn't really been performance tested yet.

#7 lore raw
Quoted 6 lines · Matthew Wilcox
Quoted 5 lines · Hugh Dickins

Saying "source inspection" reminds me: there is another funny in there, but I don't think it matters very much in practice, and might need rather a lot of testing to justify any particular patch: where page_cache_sync_readahead() asks for PAGE_SIZE pages!

Quoted 7 lines
Quoted 4 lines

"end - index" seems a more reasonable number to me: but then we might find that reading ahead into the next huge extent had actually been a useful optimization (and those readahead functions impose their own caps, so PAGE_SIZE shouldn't work out too outrageously).

That readahead was only added in 99cb0dbd47a15d395bf3faa78dc122bc5efe3fc0 so it probably hasn't really been performance tested yet.

I can well imagine that an entirely new body of code, exercised in the background by khugepaged, will not be a leading candidate for performance comparisons - rightly so; but arguing that by the commit being in the tree for only eight months seems... odd :)

Hugh