diff mbox series

[2/3] mm/util.c: make vm_memory_committed() more accurate

Message ID 1588922717-63697-3-git-send-email-feng.tang@intel.com (mailing list archive)
State New, archived
Headers show
Series make vm_committed_as_batch aware of vm overcommit policy | expand

Commit Message

Feng Tang May 8, 2020, 7:25 a.m. UTC
percpu_counter_sum_positive() will provide more accurate info.

Its time cost is about 800 nanoseconds on a 2C/4T platform and
2~3 microseconds on a 2S/36C/72T server in normal case, and in
worst case where vm_committed_as's spinlock is under severe
contention, it costs 30~40 microseconds for the 2S/36C/72T sever,
which should be fine for its two users: /proc/meminfo and HV ballon
driver's status trace per second.

Signed-off-by: Feng Tang <feng.tang@intel.com>
---
 mm/util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Michal Hocko May 15, 2020, 7:23 a.m. UTC | #1
On Fri 08-05-20 15:25:16, Feng Tang wrote:
> percpu_counter_sum_positive() will provide more accurate info.

Why do we need that?

> Its time cost is about 800 nanoseconds on a 2C/4T platform and
> 2~3 microseconds on a 2S/36C/72T server in normal case, and in
> worst case where vm_committed_as's spinlock is under severe
> contention, it costs 30~40 microseconds for the 2S/36C/72T sever,
> which should be fine for its two users: /proc/meminfo and HV ballon
> driver's status trace per second.

OK, this explains that the additional overhead is not terrible but there
is no actual information on why the imprecision is a problem.

> Signed-off-by: Feng Tang <feng.tang@intel.com>
> ---
>  mm/util.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/util.c b/mm/util.c
> index 988d11e..3de78e9 100644
> --- a/mm/util.c
> +++ b/mm/util.c
> @@ -774,7 +774,7 @@ struct percpu_counter vm_committed_as ____cacheline_aligned_in_smp;
>   */
>  unsigned long vm_memory_committed(void)
>  {
> -	return percpu_counter_read_positive(&vm_committed_as);
> +	return percpu_counter_sum_positive(&vm_committed_as);
>  }
>  EXPORT_SYMBOL_GPL(vm_memory_committed);
>  
> -- 
> 2.7.4
Feng Tang May 15, 2020, 8:11 a.m. UTC | #2
On Fri, May 15, 2020 at 03:23:07PM +0800, Michal Hocko wrote:
> On Fri 08-05-20 15:25:16, Feng Tang wrote:
> > percpu_counter_sum_positive() will provide more accurate info.
> 
> Why do we need that?

This is a preparation for patch 3/3, which will enlarge the batch size
of percpu-counter 'vm_committed_as'. Andi Kleen concerned that may
hurt the accuracy for those readers (currently only /proc/meminfo
and hyperV balloon drivers for status check)

As in worst case, the deviation could be 'batch * nr_cpus', and
with patch 3/3, that could be totalram_pages/16.

Thanks,
Feng

> > Its time cost is about 800 nanoseconds on a 2C/4T platform and
> > 2~3 microseconds on a 2S/36C/72T server in normal case, and in
> > worst case where vm_committed_as's spinlock is under severe
> > contention, it costs 30~40 microseconds for the 2S/36C/72T sever,
> > which should be fine for its two users: /proc/meminfo and HV ballon
> > driver's status trace per second.
> 
> OK, this explains that the additional overhead is not terrible but there
> is no actual information on why the imprecision is a problem.
> 
> > Signed-off-by: Feng Tang <feng.tang@intel.com>
> > ---
> >  mm/util.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/mm/util.c b/mm/util.c
> > index 988d11e..3de78e9 100644
> > --- a/mm/util.c
> > +++ b/mm/util.c
> > @@ -774,7 +774,7 @@ struct percpu_counter vm_committed_as ____cacheline_aligned_in_smp;
> >   */
> >  unsigned long vm_memory_committed(void)
> >  {
> > -	return percpu_counter_read_positive(&vm_committed_as);
> > +	return percpu_counter_sum_positive(&vm_committed_as);
> >  }
> >  EXPORT_SYMBOL_GPL(vm_memory_committed);
> >  
> > -- 
> > 2.7.4
> 
> -- 
> Michal Hocko
> SUSE Labs
Michal Hocko May 15, 2020, 9:04 a.m. UTC | #3
On Fri 15-05-20 16:11:09, Feng Tang wrote:
> On Fri, May 15, 2020 at 03:23:07PM +0800, Michal Hocko wrote:
> > On Fri 08-05-20 15:25:16, Feng Tang wrote:
> > > percpu_counter_sum_positive() will provide more accurate info.
> > 
> > Why do we need that?
> 
> This is a preparation for patch 3/3, which will enlarge the batch size
> of percpu-counter 'vm_committed_as'. Andi Kleen concerned that may
> hurt the accuracy for those readers (currently only /proc/meminfo
> and hyperV balloon drivers for status check)
> 
> As in worst case, the deviation could be 'batch * nr_cpus', and
> with patch 3/3, that could be totalram_pages/16.

This information belongs to the changelog.
Feng Tang May 15, 2020, 1:01 p.m. UTC | #4
On Fri, May 15, 2020 at 05:04:40PM +0800, Michal Hocko wrote:
> On Fri 15-05-20 16:11:09, Feng Tang wrote:
> > On Fri, May 15, 2020 at 03:23:07PM +0800, Michal Hocko wrote:
> > > On Fri 08-05-20 15:25:16, Feng Tang wrote:
> > > > percpu_counter_sum_positive() will provide more accurate info.
> > > 
> > > Why do we need that?
> > 
> > This is a preparation for patch 3/3, which will enlarge the batch size
> > of percpu-counter 'vm_committed_as'. Andi Kleen concerned that may
> > hurt the accuracy for those readers (currently only /proc/meminfo
> > and hyperV balloon drivers for status check)
> > 
> > As in worst case, the deviation could be 'batch * nr_cpus', and
> > with patch 3/3, that could be totalram_pages/16.
> 
> This information belongs to the changelog.

Will add it in v3, thanks

- Feng
diff mbox series

Patch

diff --git a/mm/util.c b/mm/util.c
index 988d11e..3de78e9 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -774,7 +774,7 @@  struct percpu_counter vm_committed_as ____cacheline_aligned_in_smp;
  */
 unsigned long vm_memory_committed(void)
 {
-	return percpu_counter_read_positive(&vm_committed_as);
+	return percpu_counter_sum_positive(&vm_committed_as);
 }
 EXPORT_SYMBOL_GPL(vm_memory_committed);