--- x/mm/filemap.c +++ y/mm/filemap.c @@ -3514,8 +3514,9 @@ skip: page += count; vmf->pte += count; addr += count * PAGE_SIZE; + nr_pages -= count; count = 0; - } while (--nr_pages > 0); + } while (nr_pages > 0); if (count) { set_pte_range(vmf, folio, page, count, addr);