linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/smaps: add Pss_Dirty
@ 2022-06-15  7:12 Vincent Whitchurch
  2022-06-15 20:57 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: Vincent Whitchurch @ 2022-06-15  7:12 UTC (permalink / raw)
  To: akpm; +Cc: kernel, linux-mm, Vincent Whitchurch, linux-kernel, linux-fsdevel

Pss is the sum of the sizes of clean and dirty private pages, and the
proportional sizes of clean and dirty shared pages:

 Private = Private_Dirty + Private_Clean
 Shared_Proportional = Shared_Dirty_Proportional + Shared_Clean_Proportional
 Pss = Private + Shared_Proportional

The Shared*Proportional fields are not present in smaps, so it is not
possible to determine how much of the Pss is from dirty pages and how
much is from clean pages.  This information can be useful for measuring
memory usage for the purpose of optimisation, since clean pages can
usually be discarded by the kernel immediately while dirty pages cannot.

The smaps routines in the kernel already have access to this data, so
add a Pss_Dirty to show it to userspace.  Pss_Clean is not added since
it can be calculated from Pss and Pss_Dirty.

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---
 fs/proc/task_mmu.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 2d04e3470d4c..696bb546ea06 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -406,6 +406,7 @@ struct mem_size_stats {
 	u64 pss_anon;
 	u64 pss_file;
 	u64 pss_shmem;
+	u64 pss_dirty;
 	u64 pss_locked;
 	u64 swap_pss;
 };
@@ -427,6 +428,7 @@ static void smaps_page_accumulate(struct mem_size_stats *mss,
 		mss->pss_locked += pss;
 
 	if (dirty || PageDirty(page)) {
+		mss->pss_dirty += pss;
 		if (private)
 			mss->private_dirty += size;
 		else
@@ -820,6 +822,7 @@ static void __show_smap(struct seq_file *m, const struct mem_size_stats *mss,
 		SEQ_PUT_DEC(" kB\nPss_Shmem:      ",
 			mss->pss_shmem >> PSS_SHIFT);
 	}
+	SEQ_PUT_DEC(" kB\nPss_Dirty:      ", mss->pss_dirty >> PSS_SHIFT);
 	SEQ_PUT_DEC(" kB\nShared_Clean:   ", mss->shared_clean);
 	SEQ_PUT_DEC(" kB\nShared_Dirty:   ", mss->shared_dirty);
 	SEQ_PUT_DEC(" kB\nPrivate_Clean:  ", mss->private_clean);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mm/smaps: add Pss_Dirty
  2022-06-15  7:12 [PATCH] mm/smaps: add Pss_Dirty Vincent Whitchurch
@ 2022-06-15 20:57 ` Andrew Morton
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2022-06-15 20:57 UTC (permalink / raw)
  To: Vincent Whitchurch; +Cc: kernel, linux-mm, linux-kernel, linux-fsdevel

On Wed, 15 Jun 2022 09:12:52 +0200 Vincent Whitchurch <vincent.whitchurch@axis.com> wrote:

> Pss is the sum of the sizes of clean and dirty private pages, and the
> proportional sizes of clean and dirty shared pages:
> 
>  Private = Private_Dirty + Private_Clean
>  Shared_Proportional = Shared_Dirty_Proportional + Shared_Clean_Proportional
>  Pss = Private + Shared_Proportional
> 
> The Shared*Proportional fields are not present in smaps, so it is not
> possible to determine how much of the Pss is from dirty pages and how
> much is from clean pages.  This information can be useful for measuring
> memory usage for the purpose of optimisation, since clean pages can
> usually be discarded by the kernel immediately while dirty pages cannot.
> 
> The smaps routines in the kernel already have access to this data, so
> add a Pss_Dirty to show it to userspace.  Pss_Clean is not added since
> it can be calculated from Pss and Pss_Dirty.
> 
> ...
>
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -406,6 +406,7 @@ struct mem_size_stats {
>  	u64 pss_anon;
>  	u64 pss_file;
>  	u64 pss_shmem;
> +	u64 pss_dirty;
>  	u64 pss_locked;
>  	u64 swap_pss;
>  };
> @@ -427,6 +428,7 @@ static void smaps_page_accumulate(struct mem_size_stats *mss,
>  		mss->pss_locked += pss;
>  
>  	if (dirty || PageDirty(page)) {
> +		mss->pss_dirty += pss;
>  		if (private)
>  			mss->private_dirty += size;
>  		else
> @@ -820,6 +822,7 @@ static void __show_smap(struct seq_file *m, const struct mem_size_stats *mss,
>  		SEQ_PUT_DEC(" kB\nPss_Shmem:      ",
>  			mss->pss_shmem >> PSS_SHIFT);
>  	}
> +	SEQ_PUT_DEC(" kB\nPss_Dirty:      ", mss->pss_dirty >> PSS_SHIFT);
>  	SEQ_PUT_DEC(" kB\nShared_Clean:   ", mss->shared_clean);
>  	SEQ_PUT_DEC(" kB\nShared_Dirty:   ", mss->shared_dirty);
>  	SEQ_PUT_DEC(" kB\nPrivate_Clean:  ", mss->private_clean);

Well it's certainly simple.

Can you please update Documentation/ABI/testing/procfs-smaps_rollup and
Documentation/filesystems/proc.rst, resend?



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-15 20:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-15  7:12 [PATCH] mm/smaps: add Pss_Dirty Vincent Whitchurch
2022-06-15 20:57 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).