Skip to content

Commit 95feeab

Browse files
Hugh Dickinstorvalds
authored andcommitted
mm/khugepaged: fix the xas_create_range() error path
collapse_shmem()'s xas_nomem() is very unlikely to fail, but it is rightly given a failure path, so move the whole xas_create_range() block up before __SetPageLocked(new_page): so that it does not need to remember to unlock_page(new_page). Add the missing mem_cgroup_cancel_charge(), and set (currently unused) result to SCAN_FAIL rather than SCAN_SUCCEED. Link: http://lkml.kernel.org/r/alpine.LSU.2.11.1811261531200.2275@eggly.anvils Fixes: 77da938 ("mm: Convert collapse_shmem to XArray") Signed-off-by: Hugh Dickins <hughd@kernel.org> Cc: 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> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 06a5e12 commit 95feeab

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

mm/khugepaged.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,20 @@ static void collapse_shmem(struct mm_struct *mm,
13291329
goto out;
13301330
}
13311331

1332+
/* This will be less messy when we use multi-index entries */
1333+
do {
1334+
xas_lock_irq(&xas);
1335+
xas_create_range(&xas);
1336+
if (!xas_error(&xas))
1337+
break;
1338+
xas_unlock_irq(&xas);
1339+
if (!xas_nomem(&xas, GFP_KERNEL)) {
1340+
mem_cgroup_cancel_charge(new_page, memcg, true);
1341+
result = SCAN_FAIL;
1342+
goto out;
1343+
}
1344+
} while (1);
1345+
13321346
__SetPageLocked(new_page);
13331347
__SetPageSwapBacked(new_page);
13341348
new_page->index = start;
@@ -1340,17 +1354,6 @@ static void collapse_shmem(struct mm_struct *mm,
13401354
* be able to map it or use it in another way until we unlock it.
13411355
*/
13421356

1343-
/* This will be less messy when we use multi-index entries */
1344-
do {
1345-
xas_lock_irq(&xas);
1346-
xas_create_range(&xas);
1347-
if (!xas_error(&xas))
1348-
break;
1349-
xas_unlock_irq(&xas);
1350-
if (!xas_nomem(&xas, GFP_KERNEL))
1351-
goto out;
1352-
} while (1);
1353-
13541357
xas_set(&xas, start);
13551358
for (index = start; index < end; index++) {
13561359
struct page *page = xas_next(&xas);

0 commit comments

Comments
 (0)