Skip to content

Commit 03b4b11

Browse files
C-W-Changtorvalds
authored andcommitted
mm: smaps*: extend smap_gather_stats to support specified beginning
Extend smap_gather_stats to support indicated beginning address at which it should start gathering. To achieve the goal, we add a new parameter @start assigned by the caller and try to refactor it for simplicity. If @start is 0, it will use the range of @vma for gathering. Signed-off-by: Chinwen Chang <chinwen.chang@mediatek.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Steven Price <steven.price@arm.com> Cc: Michel Lespinasse <walken@google.com> Cc: Alexey Dobriyan <adobriyan@gmail.com> Cc: Daniel Jordan <daniel.m.jordan@oracle.com> Cc: Daniel Kiss <daniel.kiss@arm.com> Cc: Davidlohr Bueso <dbueso@suse.de> Cc: Huang Ying <ying.huang@intel.com> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: Jimmy Assarsson <jimmyassarsson@gmail.com> Cc: Laurent Dufour <ldufour@linux.ibm.com> Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org> Cc: Matthias Brugger <matthias.bgg@gmail.com> Cc: Song Liu <songliubraving@fb.com> Cc: Vlastimil Babka <vbabka@suse.cz> Link: http://lkml.kernel.org/r/1597715898-3854-3-git-send-email-chinwen.chang@mediatek.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 07e5bfe commit 03b4b11

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

‎fs/proc/task_mmu.c‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -721,9 +721,21 @@ static const struct mm_walk_ops smaps_shmem_walk_ops = {
721721
.pte_hole = smaps_pte_hole,
722722
};
723723

724+
/*
725+
* Gather mem stats from @vma with the indicated beginning
726+
* address @start, and keep them in @mss.
727+
*
728+
* Use vm_start of @vma as the beginning address if @start is 0.
729+
*/
724730
static void smap_gather_stats(struct vm_area_struct *vma,
725-
struct mem_size_stats *mss)
731+
struct mem_size_stats *mss, unsigned long start)
726732
{
733+
const struct mm_walk_ops *ops = &smaps_walk_ops;
734+
735+
/* Invalid start */
736+
if (start >= vma->vm_end)
737+
return;
738+
727739
#ifdef CONFIG_SHMEM
728740
/* In case of smaps_rollup, reset the value from previous vma */
729741
mss->check_shmem_swap = false;
@@ -740,18 +752,20 @@ static void smap_gather_stats(struct vm_area_struct *vma,
740752
*/
741753
unsigned long shmem_swapped = shmem_swap_usage(vma);
742754

743-
if (!shmem_swapped || (vma->vm_flags & VM_SHARED) ||
744-
!(vma->vm_flags & VM_WRITE)) {
755+
if (!start && (!shmem_swapped || (vma->vm_flags & VM_SHARED) ||
756+
!(vma->vm_flags & VM_WRITE))) {
745757
mss->swap += shmem_swapped;
746758
} else {
747759
mss->check_shmem_swap = true;
748-
walk_page_vma(vma, &smaps_shmem_walk_ops, mss);
749-
return;
760+
ops = &smaps_shmem_walk_ops;
750761
}
751762
}
752763
#endif
753764
/* mmap_lock is held in m_start */
754-
walk_page_vma(vma, &smaps_walk_ops, mss);
765+
if (!start)
766+
walk_page_vma(vma, ops, mss);
767+
else
768+
walk_page_range(vma->vm_mm, start, vma->vm_end, ops, mss);
755769
}
756770

757771
#define SEQ_PUT_DEC(str, val) \
@@ -803,7 +817,7 @@ static int show_smap(struct seq_file *m, void *v)
803817

804818
memset(&mss, 0, sizeof(mss));
805819

806-
smap_gather_stats(vma, &mss);
820+
smap_gather_stats(vma, &mss, 0);
807821

808822
show_map_vma(m, vma);
809823

@@ -852,7 +866,7 @@ static int show_smaps_rollup(struct seq_file *m, void *v)
852866
hold_task_mempolicy(priv);
853867

854868
for (vma = priv->mm->mmap; vma; vma = vma->vm_next) {
855-
smap_gather_stats(vma, &mss);
869+
smap_gather_stats(vma, &mss, 0);
856870
last_vma_end = vma->vm_end;
857871
}
858872

0 commit comments

Comments
 (0)