Skip to content

Commit f154795

Browse files
tehcastertorvalds
authored andcommitted
mm: /proc/pid/smaps: factor out common stats printing
To prepare for handling /proc/pid/smaps_rollup differently from /proc/pid/smaps factor out from show_smap() printing the parts of output that are common for both variants, which is the bulk of the gathered memory stats. [[email protected]: add const, per Alexey] Link: http://lkml.kernel.org/r/[email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Vlastimil Babka <[email protected]> Reviewed-by: Alexey Dobriyan <[email protected]> Cc: Daniel Colascione <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 8e68d68 commit f154795

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

fs/proc/task_mmu.c

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,32 @@ static void smap_gather_stats(struct vm_area_struct *vma,
747747

748748
#define SEQ_PUT_DEC(str, val) \
749749
seq_put_decimal_ull_width(m, str, (val) >> 10, 8)
750+
751+
/* Show the contents common for smaps and smaps_rollup */
752+
static void __show_smap(struct seq_file *m, const struct mem_size_stats *mss)
753+
{
754+
SEQ_PUT_DEC("Rss: ", mss->resident);
755+
SEQ_PUT_DEC(" kB\nPss: ", mss->pss >> PSS_SHIFT);
756+
SEQ_PUT_DEC(" kB\nShared_Clean: ", mss->shared_clean);
757+
SEQ_PUT_DEC(" kB\nShared_Dirty: ", mss->shared_dirty);
758+
SEQ_PUT_DEC(" kB\nPrivate_Clean: ", mss->private_clean);
759+
SEQ_PUT_DEC(" kB\nPrivate_Dirty: ", mss->private_dirty);
760+
SEQ_PUT_DEC(" kB\nReferenced: ", mss->referenced);
761+
SEQ_PUT_DEC(" kB\nAnonymous: ", mss->anonymous);
762+
SEQ_PUT_DEC(" kB\nLazyFree: ", mss->lazyfree);
763+
SEQ_PUT_DEC(" kB\nAnonHugePages: ", mss->anonymous_thp);
764+
SEQ_PUT_DEC(" kB\nShmemPmdMapped: ", mss->shmem_thp);
765+
SEQ_PUT_DEC(" kB\nShared_Hugetlb: ", mss->shared_hugetlb);
766+
seq_put_decimal_ull_width(m, " kB\nPrivate_Hugetlb: ",
767+
mss->private_hugetlb >> 10, 7);
768+
SEQ_PUT_DEC(" kB\nSwap: ", mss->swap);
769+
SEQ_PUT_DEC(" kB\nSwapPss: ",
770+
mss->swap_pss >> PSS_SHIFT);
771+
SEQ_PUT_DEC(" kB\nLocked: ",
772+
mss->pss_locked >> PSS_SHIFT);
773+
seq_puts(m, " kB\n");
774+
}
775+
750776
static int show_smap(struct seq_file *m, void *v)
751777
{
752778
struct proc_maps_private *priv = m->private;
@@ -791,28 +817,9 @@ static int show_smap(struct seq_file *m, void *v)
791817
seq_puts(m, " kB\n");
792818
}
793819

794-
if (!rollup_mode || last_vma) {
795-
SEQ_PUT_DEC("Rss: ", mss->resident);
796-
SEQ_PUT_DEC(" kB\nPss: ", mss->pss >> PSS_SHIFT);
797-
SEQ_PUT_DEC(" kB\nShared_Clean: ", mss->shared_clean);
798-
SEQ_PUT_DEC(" kB\nShared_Dirty: ", mss->shared_dirty);
799-
SEQ_PUT_DEC(" kB\nPrivate_Clean: ", mss->private_clean);
800-
SEQ_PUT_DEC(" kB\nPrivate_Dirty: ", mss->private_dirty);
801-
SEQ_PUT_DEC(" kB\nReferenced: ", mss->referenced);
802-
SEQ_PUT_DEC(" kB\nAnonymous: ", mss->anonymous);
803-
SEQ_PUT_DEC(" kB\nLazyFree: ", mss->lazyfree);
804-
SEQ_PUT_DEC(" kB\nAnonHugePages: ", mss->anonymous_thp);
805-
SEQ_PUT_DEC(" kB\nShmemPmdMapped: ", mss->shmem_thp);
806-
SEQ_PUT_DEC(" kB\nShared_Hugetlb: ", mss->shared_hugetlb);
807-
seq_put_decimal_ull_width(m, " kB\nPrivate_Hugetlb: ",
808-
mss->private_hugetlb >> 10, 7);
809-
SEQ_PUT_DEC(" kB\nSwap: ", mss->swap);
810-
SEQ_PUT_DEC(" kB\nSwapPss: ",
811-
mss->swap_pss >> PSS_SHIFT);
812-
SEQ_PUT_DEC(" kB\nLocked: ",
813-
mss->pss_locked >> PSS_SHIFT);
814-
seq_puts(m, " kB\n");
815-
}
820+
if (!rollup_mode || last_vma)
821+
__show_smap(m, mss);
822+
816823
if (!rollup_mode) {
817824
if (arch_pkeys_enabled())
818825
seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma));

0 commit comments

Comments
 (0)