Skip to content

Commit 701270f

Browse files
Hugh Dickinstorvalds
authored andcommitted
mm/khugepaged: collapse_shmem() stop if punched or truncated
Huge tmpfs testing showed that although collapse_shmem() recognizes a concurrently truncated or hole-punched page correctly, its handling of holes was liable to refill an emptied extent. Add check to stop that. Link: http://lkml.kernel.org/r/alpine.LSU.2.11.1811261522040.2275@eggly.anvils Fixes: f3f0e1d ("khugepaged: add support of collapse for tmpfs/shmem pages") Signed-off-by: Hugh Dickins <hughd@google.com> Reviewed-by: Matthew Wilcox <willy@infradead.org> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Jerome Glisse <jglisse@redhat.com> Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> Cc: <stable@vger.kernel.org> [4.8+] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 006d3ff commit 701270f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

mm/khugepaged.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,17 @@ static void collapse_shmem(struct mm_struct *mm,
13591359

13601360
VM_BUG_ON(index != xas.xa_index);
13611361
if (!page) {
1362+
/*
1363+
* Stop if extent has been truncated or hole-punched,
1364+
* and is now completely empty.
1365+
*/
1366+
if (index == start) {
1367+
if (!xas_next_entry(&xas, end - 1)) {
1368+
result = SCAN_TRUNCATED;
1369+
break;
1370+
}
1371+
xas_set(&xas, index);
1372+
}
13621373
if (!shmem_charge(mapping->host, 1)) {
13631374
result = SCAN_FAIL;
13641375
break;

0 commit comments

Comments
 (0)