linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Ric Mason <ric.masonn@gmail.com>
To: Tim Chen <tim.c.chen@linux.intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Tejun Heo <tj@kernel.org>,
	Christoph Lameter <cl@linux-foundation.org>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Dave Hansen <dave.hansen@intel.com>,
	Andi Kleen <ak@linux.intel.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	linux-mm <linux-mm@kvack.org>
Subject: Re: [PATCH 2/2] Make batch size for memory accounting configured according to size of memory
Date: Wed, 01 May 2013 13:09:18 +0800	[thread overview]
Message-ID: <5180A37E.8010701@gmail.com> (raw)
In-Reply-To: <8c9bc7d4646d48154604820a3ec5952ba8949de4.1367254913.git.tim.c.chen@linux.intel.com>

Hi Tim,
On 04/30/2013 01:12 AM, Tim Chen wrote:
> Currently the per cpu counter's batch size for memory accounting is
> configured as twice the number of cpus in the system.  However,
> for system with very large memory, it is more appropriate to make it
> proportional to the memory size per cpu in the system.
>
> For example, for a x86_64 system with 64 cpus and 128 GB of memory,
> the batch size is only 2*64 pages (0.5 MB).  So any memory accounting
> changes of more than 0.5MB will overflow the per cpu counter into
> the global counter.  Instead, for the new scheme, the batch size
> is configured to be 0.4% of the memory/cpu = 8MB (128 GB/64 /256),

If large batch size will lead to global counter more inaccurate?

> which is more inline with the memory size.
>
> Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com>
> ---
>   mm/mmap.c  | 13 ++++++++++++-
>   mm/nommu.c | 13 ++++++++++++-
>   2 files changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 0db0de1..082836e 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -89,6 +89,7 @@ int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
>    * other variables. It can be updated by several CPUs frequently.
>    */
>   struct percpu_counter vm_committed_as ____cacheline_aligned_in_smp;
> +int vm_committed_batchsz ____cacheline_aligned_in_smp;
>   
>   /*
>    * The global memory commitment made in the system can be a metric
> @@ -3090,10 +3091,20 @@ void mm_drop_all_locks(struct mm_struct *mm)
>   /*
>    * initialise the VMA slab
>    */
> +static inline int mm_compute_batch(void)
> +{
> +	int nr = num_present_cpus();
> +
> +	/* batch size set to 0.4% of (total memory/#cpus) */
> +	return (int) (totalram_pages/nr) / 256;
> +}
> +
>   void __init mmap_init(void)
>   {
>   	int ret;
>   
> -	ret = percpu_counter_init(&vm_committed_as, 0);
> +	vm_committed_batchsz = mm_compute_batch();
> +	ret = percpu_counter_and_batch_init(&vm_committed_as, 0,
> +						&vm_committed_batchsz);
>   	VM_BUG_ON(ret);
>   }
> diff --git a/mm/nommu.c b/mm/nommu.c
> index 2f3ea74..a87a99c 100644
> --- a/mm/nommu.c
> +++ b/mm/nommu.c
> @@ -59,6 +59,7 @@ unsigned long max_mapnr;
>   unsigned long num_physpages;
>   unsigned long highest_memmap_pfn;
>   struct percpu_counter vm_committed_as;
> +int vm_committed_batchsz;
>   int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
>   int sysctl_overcommit_ratio = 50; /* default is 50% */
>   int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
> @@ -526,11 +527,21 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
>   /*
>    * initialise the VMA and region record slabs
>    */
> +static inline int mm_compute_batch(void)
> +{
> +	int nr = num_present_cpus();
> +
> +	/* batch size set to 0.4% of (total memory/#cpus) */
> +	return (int) (totalram_pages/nr) / 256;
> +}
> +
>   void __init mmap_init(void)
>   {
>   	int ret;
>   
> -	ret = percpu_counter_init(&vm_committed_as, 0);
> +	vm_committed_batchsz = mm_compute_batch();
> +	ret = percpu_counter_and_batch_init(&vm_committed_as, 0,
> +			&vm_committed_batchsz);
>   	VM_BUG_ON(ret);
>   	vm_region_jar = KMEM_CACHE(vm_region, SLAB_PANIC);
>   }

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2013-05-01  5:09 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-29 17:12 [PATCH 1/2] Make the batch size of the percpu_counter configurable Tim Chen
2013-04-29 17:12 ` [PATCH 2/2] Make batch size for memory accounting configured according to size of memory Tim Chen
2013-05-01  5:09   ` Ric Mason [this message]
2013-05-01 16:07     ` Tim Chen
2013-04-30 13:32 ` [PATCH 1/2] Make the batch size of the percpu_counter configurable Christoph Lameter
2013-04-30 16:23   ` Tim Chen
2013-04-30 17:28     ` Christoph Lameter
2013-04-30 17:48       ` Tim Chen
2013-04-30 17:53         ` Christoph Lameter
2013-04-30 17:55           ` Tim Chen
2013-04-30 18:27             ` Christoph Lameter
2013-04-30 19:00               ` Tim Chen
2013-04-30 19:04                 ` Tejun Heo
2013-04-30 20:50                 ` Christoph Lameter
2013-04-30 17:34     ` Andi Kleen
2013-04-30 18:10     ` Eric Dumazet
2013-04-30 18:28       ` Tim Chen
2013-05-01  4:52 ` Simon Jeons
2013-05-01 15:53   ` Tim Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5180A37E.8010701@gmail.com \
    --to=ric.masonn@gmail.com \
    --cc=ak@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux-foundation.org \
    --cc=dave.hansen@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=tim.c.chen@linux.intel.com \
    --cc=tj@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox