Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751714AbbEAA2U (ORCPT ); Thu, 30 Apr 2015 20:28:20 -0400 Received: from g4t3426.houston.hp.com ([15.201.208.54]:35424 "EHLO g4t3426.houston.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751179AbbEAA2S (ORCPT ); Thu, 30 Apr 2015 20:28:18 -0400 Message-ID: <1430440094.2475.61.camel@j-VirtualBox> Subject: [PATCH v3 2/5] sched, numa: Document usages of mm->numa_scan_seq From: Jason Low To: Waiman Long Cc: Peter Zijlstra , Ingo Molnar , Thomas Gleixner , linux-kernel@vger.kernel.org, "Paul E. McKenney" , Andrew Morton , Oleg Nesterov , Frederic Weisbecker , Mel Gorman , Rik van Riel , Steven Rostedt , Preeti U Murthy , Mike Galbraith , Davidlohr Bueso , Aswin Chandramouleeswaran , Scott J Norton , jason.low2@hp.com Date: Thu, 30 Apr 2015 17:28:14 -0700 In-Reply-To: <1430428387.2475.47.camel@j-VirtualBox> References: <1430251224-5764-1-git-send-email-jason.low2@hp.com> <1430251224-5764-3-git-send-email-jason.low2@hp.com> <55411F91.6050101@hp.com> <1430333101.8722.32.camel@j-VirtualBox> <55427794.30808@hp.com> <1430428387.2475.47.camel@j-VirtualBox> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit Mime-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2975 Lines: 74 On Thu, 2015-04-30 at 14:13 -0700, Jason Low wrote: > On Thu, 2015-04-30 at 14:42 -0400, Waiman Long wrote: > > > I do have a question of what kind of tearing you are talking about. Do > > you mean the tearing due to mm being changed in the middle of the > > access? The reason why I don't like this kind of construct is that I am > > not sure if > > the address translation p->mm->numa_scan_seq is being done once or > > twice. I looked at the compiled code and the translation is done only once. > > > > Anyway, the purpose of READ_ONCE and WRITE_ONCE is not for eliminating > > data tearing. They are to make sure that the compiler won't compile away > > data access and they are done in the order they appear in the program. I > > don't think it is a good idea to associate tearing elimination with > > those macros. So I would suggest removing the last sentence in your comment. > > Yes, I can remove the last sentence in the comment since the main goal > was to document that we're access this field without exclusive access. --- Subject: [PATCH v3 2/5] sched, numa: Document usages of mm->numa_scan_seq The p->mm->numa_scan_seq is accessed using READ_ONCE/WRITE_ONCE and modified without exclusive access. It is not clear why it is accessed this way. This patch provides some documentation on that. Signed-off-by: Jason Low Suggested-by: Ingo Molnar Acked-by: Rik van Riel --- kernel/sched/fair.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 5a44371..65a9a1dc 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -1794,6 +1794,11 @@ static void task_numa_placement(struct task_struct *p) u64 runtime, period; spinlock_t *group_lock = NULL; + /* + * The p->mm->numa_scan_seq gets updated without + * exclusive access. Use READ_ONCE() here to ensure + * that the field is read in a single access. + */ seq = READ_ONCE(p->mm->numa_scan_seq); if (p->numa_scan_seq == seq) return; @@ -2107,6 +2112,14 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags) static void reset_ptenuma_scan(struct task_struct *p) { + /* + * We only did a read acquisition of the mmap sem, so + * p->mm->numa_scan_seq is written to without exclusive access + * and the update is not guaranteed to be atomic. That's not + * much of an issue though, since this is just used for + * statistical sampling. Use READ_ONCE/WRITE_ONCE, which are not + * expensive, to avoid any form of compiler optimizations. + */ WRITE_ONCE(p->mm->numa_scan_seq, READ_ONCE(p->mm->numa_scan_seq) + 1); p->mm->numa_scan_offset = 0; } -- 1.7.2.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/