Skip to content

Commit c8be038

Browse files
fyin1akpm00
authored andcommitted
filemap: add filemap_map_order0_folio() to handle order0 folio
Kernel test robot reported regressions for several benchmarks [1]. The regression are related with commit: de74976 ("filemap: add filemap_map_folio_range()") It turned out that function filemap_map_folio_range() brings these regressions when handle folio with order0. Add filemap_map_order0_folio() to handle order0 folio. The benefit come from two perspectives: - the code size is smaller (around 126 bytes) - no loop Testing showed the regressions reported by 0day [1] all are fixed: commit 9f1f5b6: parent commit of de74976 commit fbdf926: latest mm-unstable commit commit 7fbfe2003f84686d: this fixing patch 9f1f5b6 fbdf926 7fbfe2003f84686d ---------------- --------------------------- --------------------------- 3843810 -21.4% 3020268 +4.6% 4018708 stress-ng.bad-altstack.ops 64061 -21.4% 50336 +4.6% 66977 stress-ng.bad-altstack.ops_per_sec 1709026 -14.4% 1462102 +2.4% 1750757 stress-ng.fork.ops 28483 -14.4% 24368 +2.4% 29179 stress-ng.fork.ops_per_sec 3685088 -53.6% 1710976 +0.5% 3702454 stress-ng.zombie.ops 56732 -65.3% 19667 +0.7% 57107 stress-ng.zombie.ops_per_sec 61874 -12.1% 54416 +0.4% 62136 vm-scalability.median 13527663 -11.7% 11942117 -0.1% 13513946 vm-scalability.throughput 4.066e+09 -11.7% 3.59e+09 -0.1% 4.061e+09 vm-scalability.workload [1]: https://lore.kernel.org/oe-lkp/72e017b9-deb6-44fa-91d6-716ee2c39cbc@intel.com/T/#m7d2bba30f75a9cee8eab07e5809abd9b3b206c84 Link: https://lkml.kernel.org/r/20230914134741.1937654-1-fengwei.yin@intel.com Fixes: de74976 ("filemap: add filemap_map_folio_range()") Signed-off-by: Yin Fengwei <fengwei.yin@intel.com> Reported-by: kernel test robot <oliver.sang@intel.com> Closes: https://lore.kernel.org/oe-lkp/202309111556.b2aa3d7a-oliver.sang@intel.com Cc: Feng Tang <feng.tang@intel.com> Cc: Huang Ying <ying.huang@intel.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 578d769 commit c8be038

File tree

1 file changed

+48
-21
lines changed

1 file changed

+48
-21
lines changed

mm/filemap.c

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3475,22 +3475,19 @@ static struct folio *next_uptodate_folio(struct xa_state *xas,
34753475
*/
34763476
static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf,
34773477
struct folio *folio, unsigned long start,
3478-
unsigned long addr, unsigned int nr_pages)
3478+
unsigned long addr, unsigned int nr_pages,
3479+
unsigned int *mmap_miss)
34793480
{
34803481
vm_fault_t ret = 0;
3481-
struct vm_area_struct *vma = vmf->vma;
3482-
struct file *file = vma->vm_file;
34833482
struct page *page = folio_page(folio, start);
3484-
unsigned int mmap_miss = READ_ONCE(file->f_ra.mmap_miss);
34853483
unsigned int count = 0;
34863484
pte_t *old_ptep = vmf->pte;
34873485

34883486
do {
34893487
if (PageHWPoison(page + count))
34903488
goto skip;
34913489

3492-
if (mmap_miss > 0)
3493-
mmap_miss--;
3490+
(*mmap_miss)++;
34943491

34953492
/*
34963493
* NOTE: If there're PTE markers, we'll leave them to be
@@ -3525,7 +3522,35 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf,
35253522
}
35263523

35273524
vmf->pte = old_ptep;
3528-
WRITE_ONCE(file->f_ra.mmap_miss, mmap_miss);
3525+
3526+
return ret;
3527+
}
3528+
3529+
static vm_fault_t filemap_map_order0_folio(struct vm_fault *vmf,
3530+
struct folio *folio, unsigned long addr,
3531+
unsigned int *mmap_miss)
3532+
{
3533+
vm_fault_t ret = 0;
3534+
struct page *page = &folio->page;
3535+
3536+
if (PageHWPoison(page))
3537+
return ret;
3538+
3539+
(*mmap_miss)++;
3540+
3541+
/*
3542+
* NOTE: If there're PTE markers, we'll leave them to be
3543+
* handled in the specific fault path, and it'll prohibit
3544+
* the fault-around logic.
3545+
*/
3546+
if (!pte_none(ptep_get(vmf->pte)))
3547+
return ret;
3548+
3549+
if (vmf->address == addr)
3550+
ret = VM_FAULT_NOPAGE;
3551+
3552+
set_pte_range(vmf, folio, page, 1, addr);
3553+
folio_ref_inc(folio);
35293554

35303555
return ret;
35313556
}
@@ -3541,7 +3566,7 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf,
35413566
XA_STATE(xas, &mapping->i_pages, start_pgoff);
35423567
struct folio *folio;
35433568
vm_fault_t ret = 0;
3544-
int nr_pages = 0;
3569+
unsigned int nr_pages = 0, mmap_miss = 0, mmap_miss_saved;
35453570

35463571
rcu_read_lock();
35473572
folio = next_uptodate_folio(&xas, mapping, end_pgoff);
@@ -3569,25 +3594,27 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf,
35693594
end = folio->index + folio_nr_pages(folio) - 1;
35703595
nr_pages = min(end, end_pgoff) - xas.xa_index + 1;
35713596

3572-
/*
3573-
* NOTE: If there're PTE markers, we'll leave them to be
3574-
* handled in the specific fault path, and it'll prohibit the
3575-
* fault-around logic.
3576-
*/
3577-
if (!pte_none(ptep_get(vmf->pte)))
3578-
goto unlock;
3579-
3580-
ret |= filemap_map_folio_range(vmf, folio,
3581-
xas.xa_index - folio->index, addr, nr_pages);
3597+
if (!folio_test_large(folio))
3598+
ret |= filemap_map_order0_folio(vmf,
3599+
folio, addr, &mmap_miss);
3600+
else
3601+
ret |= filemap_map_folio_range(vmf, folio,
3602+
xas.xa_index - folio->index, addr,
3603+
nr_pages, &mmap_miss);
35823604

3583-
unlock:
35843605
folio_unlock(folio);
35853606
folio_put(folio);
3586-
folio = next_uptodate_folio(&xas, mapping, end_pgoff);
3587-
} while (folio);
3607+
} while ((folio = next_uptodate_folio(&xas, mapping, end_pgoff)) != NULL);
35883608
pte_unmap_unlock(vmf->pte, vmf->ptl);
35893609
out:
35903610
rcu_read_unlock();
3611+
3612+
mmap_miss_saved = READ_ONCE(file->f_ra.mmap_miss);
3613+
if (mmap_miss >= mmap_miss_saved)
3614+
WRITE_ONCE(file->f_ra.mmap_miss, 0);
3615+
else
3616+
WRITE_ONCE(file->f_ra.mmap_miss, mmap_miss_saved - mmap_miss);
3617+
35913618
return ret;
35923619
}
35933620
EXPORT_SYMBOL(filemap_map_pages);

0 commit comments

Comments
 (0)