Skip to content

Commit 7b49514

Browse files
MiaoheLinakpm00
authored andcommitted
mm/madvise: free hwpoison and swapin error entry in madvise_free_pte_range
Once the MADV_FREE operation has succeeded, callers can expect they might get zero-fill pages if accessing the memory again. Therefore it should be safe to delete the hwpoison entry and swapin error entry. There is no reason to kill the process if it has called MADV_FREE on the range. Link: https://lkml.kernel.org/r/20220519125030.21486-4-linmiaohe@huawei.com Signed-off-by: Miaohe Lin <linmiaohe@huawei.com> Suggested-by: Alistair Popple <apopple@nvidia.com> Acked-by: David Hildenbrand <david@redhat.com> Reviewed-by: Naoya Horiguchi <naoya.horiguchi@nec.com> Cc: David Howells <dhowells@redhat.com> Cc: Hugh Dickins <hughd@google.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: NeilBrown <neilb@suse.de> Cc: Peter Xu <peterx@redhat.com> Cc: Ralph Campbell <rcampbell@nvidia.com> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 14a762d commit 7b49514

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

mm/madvise.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -624,11 +624,14 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr,
624624
swp_entry_t entry;
625625

626626
entry = pte_to_swp_entry(ptent);
627-
if (non_swap_entry(entry))
628-
continue;
629-
nr_swap--;
630-
free_swap_and_cache(entry);
631-
pte_clear_not_present_full(mm, addr, pte, tlb->fullmm);
627+
if (!non_swap_entry(entry)) {
628+
nr_swap--;
629+
free_swap_and_cache(entry);
630+
pte_clear_not_present_full(mm, addr, pte, tlb->fullmm);
631+
} else if (is_hwpoison_entry(entry) ||
632+
is_swapin_error_entry(entry)) {
633+
pte_clear_not_present_full(mm, addr, pte, tlb->fullmm);
634+
}
632635
continue;
633636
}
634637

0 commit comments

Comments
 (0)