Skip to content

Commit 2301003

Browse files
xzpetertorvalds
authored andcommitted
mm/smaps: simplify shmem handling of pte holes
Firstly, check_shmem_swap variable is actually not necessary, because it's always set with pte_hole hook; checking each would work. Meanwhile, the check within smaps_pte_entry is not easy to follow. E.g., pte_none() check is not needed as "!pte_present && !is_swap_pte" is the same. Since at it, use the pte_hole() helper rather than dup the page cache lookup. Still keep the CONFIG_SHMEM part so the code can be optimized to nop for !SHMEM. There will be a very slight functional change in smaps_pte_entry(), that for !SHMEM we'll return early for pte_none (before checking page==NULL), but that's even nicer. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Peter Xu <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Andrea Arcangeli <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 02399c8 commit 2301003

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

fs/proc/task_mmu.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ struct mem_size_stats {
397397
u64 pss_shmem;
398398
u64 pss_locked;
399399
u64 swap_pss;
400-
bool check_shmem_swap;
401400
};
402401

403402
static void smaps_page_accumulate(struct mem_size_stats *mss,
@@ -490,6 +489,16 @@ static int smaps_pte_hole(unsigned long addr, unsigned long end,
490489
#define smaps_pte_hole NULL
491490
#endif /* CONFIG_SHMEM */
492491

492+
static void smaps_pte_hole_lookup(unsigned long addr, struct mm_walk *walk)
493+
{
494+
#ifdef CONFIG_SHMEM
495+
if (walk->ops->pte_hole) {
496+
/* depth is not used */
497+
smaps_pte_hole(addr, addr + PAGE_SIZE, 0, walk);
498+
}
499+
#endif
500+
}
501+
493502
static void smaps_pte_entry(pte_t *pte, unsigned long addr,
494503
struct mm_walk *walk)
495504
{
@@ -518,12 +527,8 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr,
518527
}
519528
} else if (is_pfn_swap_entry(swpent))
520529
page = pfn_swap_entry_to_page(swpent);
521-
} else if (unlikely(IS_ENABLED(CONFIG_SHMEM) && mss->check_shmem_swap
522-
&& pte_none(*pte))) {
523-
page = xa_load(&vma->vm_file->f_mapping->i_pages,
524-
linear_page_index(vma, addr));
525-
if (xa_is_value(page))
526-
mss->swap += PAGE_SIZE;
530+
} else {
531+
smaps_pte_hole_lookup(addr, walk);
527532
return;
528533
}
529534

@@ -737,8 +742,6 @@ static void smap_gather_stats(struct vm_area_struct *vma,
737742
return;
738743

739744
#ifdef CONFIG_SHMEM
740-
/* In case of smaps_rollup, reset the value from previous vma */
741-
mss->check_shmem_swap = false;
742745
if (vma->vm_file && shmem_mapping(vma->vm_file->f_mapping)) {
743746
/*
744747
* For shared or readonly shmem mappings we know that all
@@ -756,7 +759,6 @@ static void smap_gather_stats(struct vm_area_struct *vma,
756759
!(vma->vm_flags & VM_WRITE))) {
757760
mss->swap += shmem_swapped;
758761
} else {
759-
mss->check_shmem_swap = true;
760762
ops = &smaps_shmem_walk_ops;
761763
}
762764
}

0 commit comments

Comments
 (0)