Skip to content

Commit

Permalink
mm/khugepaged: fix the xas_create_range() error path
Browse files Browse the repository at this point in the history
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/[email protected]
Fixes: 77da938 ("mm: Convert collapse_shmem to XArray")
Signed-off-by: Hugh Dickins <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Kirill A. Shutemov <[email protected]>
Cc: Jerome Glisse <[email protected]>
Cc: Konstantin Khlebnikov <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Hugh Dickins authored and torvalds committed Nov 30, 2018
1 parent 06a5e12 commit 95feeab
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions mm/khugepaged.c
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,20 @@ static void collapse_shmem(struct mm_struct *mm,
goto out;
}

/* This will be less messy when we use multi-index entries */
do {
xas_lock_irq(&xas);
xas_create_range(&xas);
if (!xas_error(&xas))
break;
xas_unlock_irq(&xas);
if (!xas_nomem(&xas, GFP_KERNEL)) {
mem_cgroup_cancel_charge(new_page, memcg, true);
result = SCAN_FAIL;
goto out;
}
} while (1);

__SetPageLocked(new_page);
__SetPageSwapBacked(new_page);
new_page->index = start;
Expand All @@ -1340,17 +1354,6 @@ static void collapse_shmem(struct mm_struct *mm,
* be able to map it or use it in another way until we unlock it.
*/

/* This will be less messy when we use multi-index entries */
do {
xas_lock_irq(&xas);
xas_create_range(&xas);
if (!xas_error(&xas))
break;
xas_unlock_irq(&xas);
if (!xas_nomem(&xas, GFP_KERNEL))
goto out;
} while (1);

xas_set(&xas, start);
for (index = start; index < end; index++) {
struct page *page = xas_next(&xas);
Expand Down

0 comments on commit 95feeab

Please sign in to comment.