Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1701986

Re: [PATCH 3/3] IPI: Avoid to use 2 cache lines for one call_single_data

From Eric Dumazet <eric.dumazet@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH 3/3] IPI: Avoid to use 2 cache lines for one call_single_data
Date 2017-08-02 12:20 +0200
Message-ID <u9YUX-7q-29@gated-at.bofh.it> (permalink)
References <u9XFv-7As-5@gated-at.bofh.it> <u9XFv-7As-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Wed, 2017-08-02 at 16:52 +0800, Huang, Ying wrote:
> From: Huang Ying <ying.huang@intel.com>
> 
> struct call_single_data is used in IPI to transfer information between
> CPUs.  Its size is bigger than sizeof(unsigned long) and less than
> cache line size.  Now, it is allocated with no any alignment
> requirement.  This makes it possible for allocated call_single_data to
> cross 2 cache lines.  So that double the number of the cache lines
> that need to be transferred among CPUs.  This is resolved by aligning
> the allocated call_single_data with cache line size.
> 
> To test the effect of the patch, we use the vm-scalability multiple
> thread swap test case (swap-w-seq-mt).  The test will create multiple
> threads and each thread will eat memory until all RAM and part of swap
> is used, so that huge number of IPI will be triggered when unmapping
> memory.  In the test, the throughput of memory writing improves ~5%
> compared with misaligned call_single_data because of faster IPI.
> 
> Signed-off-by: "Huang, Ying" <ying.huang@intel.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: Borislav Petkov <bp@suse.de>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Juergen Gross <jgross@suse.com>
> Cc: Aaron Lu <aaron.lu@intel.com>
> ---
>  kernel/smp.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/smp.c b/kernel/smp.c
> index 3061483cb3ad..81d9ae08eb6e 100644
> --- a/kernel/smp.c
> +++ b/kernel/smp.c
> @@ -51,7 +51,7 @@ int smpcfd_prepare_cpu(unsigned int cpu)
>  		free_cpumask_var(cfd->cpumask);
>  		return -ENOMEM;
>  	}
> -	cfd->csd = alloc_percpu(struct call_single_data);
> +	cfd->csd = alloc_percpu_aligned(struct call_single_data);

I do not believe allocating 64 bytes (per cpu) for this structure is
needed. That would be an increase of cache lines.

What we can do instead is to force an alignment on 4*sizeof(void *).
(32 bytes on 64bit, 16 bytes on 32bit arches)

Maybe something like this :

diff --git a/include/linux/smp.h b/include/linux/smp.h
index 68123c1fe54918c051292eb5ba3427df09f31c2f..f7072bf173c5456e38e958d6af85a4793bced96e 100644
--- a/include/linux/smp.h
+++ b/include/linux/smp.h
@@ -19,7 +19,7 @@ struct call_single_data {
 	smp_call_func_t func;
 	void *info;
 	unsigned int flags;
-};
+} __attribute__((aligned(4 * sizeof(void *))));
 
 /* total number of cpus in this system (may exceed NR_CPUS) */
 extern unsigned int total_cpus;

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 3/3] IPI: Avoid to use 2 cache lines for one call_single_data "Huang, Ying" <ying.huang@intel.com> - 2017-08-02 11:00 +0200
  Re: [PATCH 3/3] IPI: Avoid to use 2 cache lines for one  call_single_data Eric Dumazet <eric.dumazet@gmail.com> - 2017-08-02 12:20 +0200
    Re: [PATCH 3/3] IPI: Avoid to use 2 cache lines for one  call_single_data Peter Zijlstra <peterz@infradead.org> - 2017-08-02 13:00 +0200
    Re: [PATCH 3/3] IPI: Avoid to use 2 cache lines for one call_single_data "Huang\, Ying" <ying.huang@intel.com> - 2017-08-03 10:40 +0200
      Re: [PATCH 3/3] IPI: Avoid to use 2 cache lines for one  call_single_data Peter Zijlstra <peterz@infradead.org> - 2017-08-03 11:00 +0200
        Re: [PATCH 3/3] IPI: Avoid to use 2 cache lines for one call_single_data "Huang\, Ying" <ying.huang@intel.com> - 2017-08-04 03:30 +0200
          Re: [PATCH 3/3] IPI: Avoid to use 2 cache lines for one call_single_data "Huang\, Ying" <ying.huang@intel.com> - 2017-08-04 04:10 +0200
            Re: [PATCH 3/3] IPI: Avoid to use 2 cache lines for one  call_single_data Peter Zijlstra <peterz@infradead.org> - 2017-08-04 11:30 +0200
              Re: [PATCH 3/3] IPI: Avoid to use 2 cache lines for one call_single_data "Huang\, Ying" <ying.huang@intel.com> - 2017-08-05 02:50 +0200
                Re: [PATCH 3/3] IPI: Avoid to use 2 cache lines for one  call_single_data Peter Zijlstra <peterz@infradead.org> - 2017-08-07 10:30 +0200
                Re: [PATCH 3/3] IPI: Avoid to use 2 cache lines for one call_single_data "Huang\, Ying" <ying.huang@intel.com> - 2017-08-08 06:40 +0200
          Re: [PATCH 3/3] IPI: Avoid to use 2 cache lines for one  call_single_data Peter Zijlstra <peterz@infradead.org> - 2017-08-04 11:30 +0200

csiph-web