Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751222Ab2JREPB (ORCPT ); Thu, 18 Oct 2012 00:15:01 -0400 Received: from mail-we0-f174.google.com ([74.125.82.174]:45574 "EHLO mail-we0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750790Ab2JREPA (ORCPT ); Thu, 18 Oct 2012 00:15:00 -0400 MIME-Version: 1.0 In-Reply-To: <507F803A.8000900@jp.fujitsu.com> References: <20121017040515.GA13505@redhat.com> <20121017181413.GA16805@redhat.com> <20121017193229.GC16805@redhat.com> <20121017194501.GA24400@redhat.com> <507F803A.8000900@jp.fujitsu.com> From: Linus Torvalds Date: Wed, 17 Oct 2012 21:14:38 -0700 X-Google-Sender-Auth: XRoJry7vVSV5A3QVZbUwy5BerkM Message-ID: Subject: Re: [patch for-3.7 v2] mm, mempolicy: avoid taking mutex inside spinlock when reading numa_maps To: Kamezawa Hiroyuki Cc: David Rientjes , Andrew Morton , Dave Jones , KOSAKI Motohiro , bhutchings@solarflare.com, Konstantin Khlebnikov , Naoya Horiguchi , Hugh Dickins , linux-kernel@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset=ISO-8859-1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1944 Lines: 61 On Wed, Oct 17, 2012 at 9:06 PM, Kamezawa Hiroyuki wrote: > if (vma && vma != priv->tail_vma) { > struct mm_struct *mm = vma->vm_mm; > +#ifdef CONFIG_NUMA > + task_lock(priv->task); > + __mpol_put(priv->task->mempolicy); > + task_unlock(priv->task); > +#endif > up_read(&mm->mmap_sem); > mmput(mm); Please don't put #ifdef's inside code. It makes things really ugly and hard to read. And that is *especially* true in this case, since there's a pattern to all these things: > +#ifdef CONFIG_NUMA > + task_lock(priv->task); > + mpol_get(priv->task->mempolicy); > + task_unlock(priv->task); > +#endif > +#ifdef CONFIG_NUMA > + task_lock(priv->task); > + __mpol_put(priv->task->mempolicy); > + task_unlock(priv->task); > +#endif it really sounds like what you want to do is to just abstract a "numa_policy_get/put(priv)" operation. So you could make it be something like #ifdef CONFIG_NUMA static inline numa_policy_get(struct proc_maps_private *priv) { task_lock(priv->task); mpol_get(priv->task->mempolicy); task_unlock(priv->task); } .. same for the "put" function .. #else #define numa_policy_get(priv) do { } while (0) #define numa_policy_put(priv) do { } while (0) #endif and then you wouldn't have to have the #ifdef's in the middle of code, and I think it will be more readable in general. Sure, it is going to be a few more actual lines of patch, but there's no duplicated code sequence, and the added lines are just the syntax that makes it look better. Linus -- 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/