Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755219AbcJULfE (ORCPT ); Fri, 21 Oct 2016 07:35:04 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:53279 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754833AbcJULfB (ORCPT ); Fri, 21 Oct 2016 07:35:01 -0400 From: "Aneesh Kumar K.V" To: Michal Hocko , Andrew Morton Cc: Mel Gorman , David Rientjes , Anshuman Khandual , linux-mm@kvack.org, LKML , Michal Hocko Subject: Re: [PATCH] mm, mempolicy: clean up __GFP_THISNODE confusion in policy_zonelist In-Reply-To: <20161013125958.32155-1-mhocko@kernel.org> References: <20161013125958.32155-1-mhocko@kernel.org> Date: Fri, 21 Oct 2016 17:04:50 +0530 MIME-Version: 1.0 Content-Type: text/plain X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16102111-0028-0000-0000-000005DC015F X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00005951; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000187; SDB=6.00771007; UDB=6.00369690; IPR=6.00547567; BA=6.00004823; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00013064; XFM=3.00000011; UTC=2016-10-21 11:34:59 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16102111-0029-0000-0000-000030362544 Message-Id: <877f92ue91.fsf@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-10-21_08:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1610210212 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3352 Lines: 83 Michal Hocko writes: > From: Michal Hocko > > __GFP_THISNODE is documented to enforce the allocation to be satisified > from the requested node with no fallbacks or placement policy > enforcements. policy_zonelist seemingly breaks this semantic if the > current policy is MPOL_MBIND and instead of taking the node it will > fallback to the first node in the mask if the requested one is not in > the mask. This is confusing to say the least because it fact we > shouldn't ever go that path. First tasks shouldn't be scheduled on CPUs > with nodes outside of their mempolicy binding. And secondly > policy_zonelist is called only from 3 places: > - huge_zonelist - never should do __GFP_THISNODE when going this path > - alloc_pages_vma - which shouldn't depend on __GFP_THISNODE either > - alloc_pages_current - which uses default_policy id __GFP_THISNODE is > used > > So we shouldn't even need to care about this possibility and can drop > the confusing code. Let's keep a WARN_ON_ONCE in place to catch > potential users and fix them up properly (aka use a different allocation > function which ignores mempolicy). > > Signed-off-by: Michal Hocko > --- > > Hi, > I have noticed this while discussing this code [1]. The code as is > quite confusing and I think it is worth cleaning up. I decided to be > conservative and keep at least WARN_ON_ONCE if we have some caller which > relies on __GFP_THISNODE in a mempolicy context so that we can fix it up. > > [1] http://lkml.kernel.org/r/57FE0184.6030008@linux.vnet.ibm.com > > mm/mempolicy.c | 24 ++++++++---------------- > 1 file changed, 8 insertions(+), 16 deletions(-) > > diff --git a/mm/mempolicy.c b/mm/mempolicy.c > index ad1c96ac313c..33a305397bd4 100644 > --- a/mm/mempolicy.c > +++ b/mm/mempolicy.c > @@ -1679,25 +1679,17 @@ static nodemask_t *policy_nodemask(gfp_t gfp, struct mempolicy *policy) > static struct zonelist *policy_zonelist(gfp_t gfp, struct mempolicy *policy, > int nd) > { > - switch (policy->mode) { > - case MPOL_PREFERRED: > - if (!(policy->flags & MPOL_F_LOCAL)) > - nd = policy->v.preferred_node; > - break; > - case MPOL_BIND: > + if (policy->mode == MPOL_PREFERRED && !(policy->flags & MPOL_F_LOCAL)) > + nd = policy->v.preferred_node; > + else { > /* > - * Normally, MPOL_BIND allocations are node-local within the > - * allowed nodemask. However, if __GFP_THISNODE is set and the > - * current node isn't part of the mask, we use the zonelist for > - * the first node in the mask instead. > + * __GFP_THISNODE shouldn't even be used with the bind policy because > + * we might easily break the expectation to stay on the requested node > + * and not break the policy. > */ > - if (unlikely(gfp & __GFP_THISNODE) && > - unlikely(!node_isset(nd, policy->v.nodes))) > - nd = first_node(policy->v.nodes); > - break; > - default: > - BUG(); > + WARN_ON_ONCE(policy->mode == MPOL_BIND && (gfp & __GFP_THISNODE)); > } > + > return node_zonelist(nd, gfp); > } > For both MPOL_PREFERED and MPOL_INTERLEAVE we pick the zone list from the node other than the current running node. Why don't we do that for MPOL_BIND ?ie, if the current node is not part of the policy node mask why are we not picking the first node from the policy node mask for MPOL_BIND ? -aneesh