Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp19140pxf; Tue, 16 Mar 2021 20:42:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3u4+q5BetSn7hBKq6SDFgPlE0aE3xGYYAIPP2NGqecMxMfKyinVHtYKE72c5+TyfKsxny X-Received: by 2002:a17:906:524f:: with SMTP id y15mr17893572ejm.65.1615952533353; Tue, 16 Mar 2021 20:42:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615952533; cv=none; d=google.com; s=arc-20160816; b=BrSdgeif1IEnJBpLYM2N66BTsz9g4oOIzeDI4UlT4ecBLhObwBzT+n0xUWxEy2/SIi XDND4egk2hwIBA7ghzzeHSEo3Q6t1up8GPQvEqdyS9U4fyuABEwnYyY6Kn2aoef08NdV BavbFT/IbHpnOOzhK2xQDomargGjctikUQ96y4nGEZeAr6R7CLYDFyKRKrAMZyzen1Bz q1l+lTsOtRgGNVcxhECvT/RJi+cPPtmukZneWNB0rJ0eIobhv3zDEtpFv5nZp5bEFW1g GP4oGUZhioci+qiy4Uvp28OM20o99Gd9NcC/yDRi/fi6WGX23vwmWeQSVtqhV/2nOVRu Dd/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:ironport-sdr:ironport-sdr; bh=l8P4sl7mkw3Wk8cgje+U0wtMDUhwB4c4EzjW/m4wcF8=; b=V41Zfi3a6JOu+8Olzn24ANdA/kFFDlwmnNptMevgj3PFaoYIU3FgzZnEb5OlQcLSuN 8bXaD5AuZcHBZuSuCtdURAp9W7G42GH5FR8zks+Pp6OVXa19/EZ/M6UMWBH0SMPjUvbW zUVzQ4zqCry0McOl7z3P5MYblJcnl2QVA62J4Gx1QbFci7HjsvHXR02fk/F/xEtXs0Ut oTGkqjERCj2lH9YfNNREHZy31vADxAItgFEkRaZ9SbtgPPjUvTig6sYfYHVLMRSwIVdp fxXwRw82euxQCvmvvdNbcU9+URySmvm+WlaX0GVQktCofWFRGVTaZFa0zlIh3mw2X9al NZEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l15si12132895edb.89.2021.03.16.20.41.51; Tue, 16 Mar 2021 20:42:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230108AbhCQDkk (ORCPT + 99 others); Tue, 16 Mar 2021 23:40:40 -0400 Received: from mga11.intel.com ([192.55.52.93]:48803 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229772AbhCQDk3 (ORCPT ); Tue, 16 Mar 2021 23:40:29 -0400 IronPort-SDR: wAxdAh91Ld+r8WMaCvihhpquDFAQwD73oIL02V+fOY+0Kn5e/zEAfvChjIg0L8FQO1gKnE68yu 8WfVJww3BKdg== X-IronPort-AV: E=McAfee;i="6000,8403,9925"; a="186021874" X-IronPort-AV: E=Sophos;i="5.81,254,1610438400"; d="scan'208";a="186021874" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2021 20:40:29 -0700 IronPort-SDR: FWYdN3v3llNgOFFVw6CiHQ3538glVa3UZQYIZag70dAV0FJQEAlnlBXxGGAd/CC6cPwEokQcoX cB/E5ylJvIgA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,254,1610438400"; d="scan'208";a="602075847" Received: from shbuild999.sh.intel.com ([10.239.147.94]) by fmsmga006.fm.intel.com with ESMTP; 16 Mar 2021 20:40:25 -0700 From: Feng Tang To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: Michal Hocko , Andrea Arcangeli , David Rientjes , Mel Gorman , Mike Kravetz , Randy Dunlap , Vlastimil Babka , Dave Hansen , Ben Widawsky , Andi Kleen , Dan Williams , Dave Hansen , Feng Tang Subject: [PATCH v4 04/13] mm/mempolicy: allow preferred code to take a nodemask Date: Wed, 17 Mar 2021 11:40:01 +0800 Message-Id: <1615952410-36895-5-git-send-email-feng.tang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1615952410-36895-1-git-send-email-feng.tang@intel.com> References: <1615952410-36895-1-git-send-email-feng.tang@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Hansen Create a helper function (mpol_new_preferred_many()) which is usable both by the old, single-node MPOL_PREFERRED and the new MPOL_PREFERRED_MANY. Enforce the old single-node MPOL_PREFERRED behavior in the "new" version of mpol_new_preferred() which calls mpol_new_preferred_many(). v3: * fix a stack overflow caused by emty nodemask (Feng) Link: https://lore.kernel.org/r/20200630212517.308045-5-ben.widawsky@intel.com Signed-off-by: Dave Hansen Signed-off-by: Ben Widawsky Signed-off-by: Feng Tang --- mm/mempolicy.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 1228d8e..6fb2cab 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -203,17 +203,34 @@ static int mpol_new_interleave(struct mempolicy *pol, const nodemask_t *nodes) return 0; } -static int mpol_new_preferred(struct mempolicy *pol, const nodemask_t *nodes) +static int mpol_new_preferred_many(struct mempolicy *pol, + const nodemask_t *nodes) { if (!nodes) pol->flags |= MPOL_F_LOCAL; /* local allocation */ else if (nodes_empty(*nodes)) return -EINVAL; /* no allowed nodes */ else - pol->v.preferred_nodes = nodemask_of_node(first_node(*nodes)); + pol->v.preferred_nodes = *nodes; return 0; } +static int mpol_new_preferred(struct mempolicy *pol, const nodemask_t *nodes) +{ + if (nodes) { + /* MPOL_PREFERRED can only take a single node: */ + nodemask_t tmp; + + if (nodes_empty(*nodes)) + return -EINVAL; + + tmp = nodemask_of_node(first_node(*nodes)); + return mpol_new_preferred_many(pol, &tmp); + } + + return mpol_new_preferred_many(pol, NULL); +} + static int mpol_new_bind(struct mempolicy *pol, const nodemask_t *nodes) { if (nodes_empty(*nodes)) -- 2.7.4