public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: kernel test robot <xiaolong.ye@intel.com>,
	Ingo Molnar <mingo@kernel.org>, Juergen Gross <jgross@suse.com>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Andy Lutomirski <luto@amacapital.net>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Jork Loeser <Jork.Loeser@microsoft.com>,
	KY Srinivasan <kys@microsoft.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Stephen Hemminger <sthemmin@microsoft.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Peter Zijlstra <peterz@infradead.org>,
	lkp@01.org, kemi <kemi.wang@intel.com>
Subject: Re: [lkp-robot] [x86/mm]  9e52fc2b50:  will-it-scale.per_thread_ops -16% regression
Date: Mon, 20 Nov 2017 17:58:17 +0100	[thread overview]
Message-ID: <87a7zgc2fq.fsf@vitty.brq.redhat.com> (raw)
In-Reply-To: <874lrlzjpo.fsf@vitty.brq.redhat.com> (Vitaly Kuznetsov's message of "Fri, 29 Sep 2017 16:02:27 +0200")

Vitaly Kuznetsov <vkuznets@redhat.com> writes:

> But adding such complexity to the code would require a good
> justification, of course.

Sorry for necroposting, I got distracted :-(

I think I was able to reproduce the reported regression. The reproducer
is dead simple, just several threads doing malloc(128Mb)/free().

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>

#define nthreads 16
#define nrounds 10000
#define alloc_size 128*1024*1024 /*128Mb*/

void *threadf(void *ptr)
{
	void *addr;
	int i;

	for (i = 0; i < nrounds; i++) {
		addr = malloc(alloc_size);
		if (!addr) {
			fprintf(stderr, "malloc failed\n");
			exit(1);
		}
		free(addr);
	}
}

int main(int argc, char *argv[]) {
	pthread_t thr[nthreads];
	int i;

	for (i = 0; i < nthreads; i++) {
		if (pthread_create(&thr[i], NULL, threadf, NULL)) {
			fprintf(stderr, "pthread_create failed\n");
			exit(1);
		}
	}

	for (i = 0; i < nthreads; i++) {
		if (pthread_join(thr[i], NULL)) {
			fprintf(stderr, "pthread_join failed\n");
			exit(1);
		}
	}

	return 0;
}

The average result on a 16 core host for me is:

With HAVE_RCU_TABLE_FREE (what we have now):
real	0m10.571s
user	0m0.678s
sys	0m12.813s

Without HAVE_RCU_TABLE_FREE (what we had pre-patch):
real	0m9.976s
user	0m0.824s
sys	0m10.960s

I did some investigation and I *think* this is what's going on. We have
the following call chain:

do_munmap()
  unmap_region()
    free_pgtables()
    tlb_finish_mmu()
      arch_tlb_finish_mmu()
        tlb_flush_mmu()
          tlb_flush_mmu_tlbonly()
            tlb_flush() <- IPIs on bare metal
            tlb_table_flush() <- this is added when CONFIG_HAVE_RCU_TABLE_FREE

tlb_table_flush() does call_rcu_sched() to free the batch but the
problem is that the batch is almost empty -- usually it has just one
entry in it (for the above example).

The following dirty hack:

--- a/mm/memory.c
+++ b/mm/memory.c
@@ -367,7 +367,10 @@ void tlb_table_flush(struct mmu_gather *tlb)
        struct mmu_table_batch **batch = &tlb->batch;
 
        if (*batch) {
-               call_rcu_sched(&(*batch)->rcu, tlb_remove_table_rcu);
+               if (pv_mmu_ops.flush_tlb_others != native_flush_tlb_others)
+                   call_rcu_sched(&(*batch)->rcu, tlb_remove_table_rcu);
+               else
+                   tlb_remove_table_rcu(&(*batch)->rcu);
                *batch = NULL;
        }
 }

seems to solve the issue. However, I'm having troubles trying to
understand what would be the best move here. In case we think this
use-case needs addressing I can suggest we employ static_keys and switch
between rcu/non-rcu table free mechanisms for x86 on boot.

I'd be grateful for any thoughts/suggestions on this. Thanks!

-- 
  Vitaly

      reply	other threads:[~2017-11-20 16:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-27  5:59 [lkp-robot] [x86/mm] 9e52fc2b50: will-it-scale.per_thread_ops -16% regression kernel test robot
2017-09-29 12:24 ` Vitaly Kuznetsov
2017-09-29 13:13   ` Peter Zijlstra
2017-09-29 13:16     ` Peter Zijlstra
2017-09-29 14:02       ` Vitaly Kuznetsov
2017-11-20 16:58         ` Vitaly Kuznetsov [this message]

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=87a7zgc2fq.fsf@vitty.brq.redhat.com \
    --to=vkuznets@redhat.com \
    --cc=Jork.Loeser@microsoft.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=jgross@suse.com \
    --cc=kemi.wang@intel.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=kys@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@01.org \
    --cc=luto@amacapital.net \
    --cc=mingo@kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=sthemmin@microsoft.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=xiaolong.ye@intel.com \
    /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