Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp19847pxf; Tue, 16 Mar 2021 20:44:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMF97PtfQsQl9s8M5D7EpSx2yQXrVDtJ+ntXgmK5Qu/8inf74cHljqTm+XoQKahlMVirAm X-Received: by 2002:a17:907:7799:: with SMTP id ky25mr33060272ejc.217.1615952657160; Tue, 16 Mar 2021 20:44:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615952657; cv=none; d=google.com; s=arc-20160816; b=ez5db5ou4MZPs5yoShWs5d4wxc1v33x2dWLdSTBCqX7CeLOvvJUAH+8+rECfiXn2Fm 4GDIUGTftoDaDRAmRkGCBe6NqAHKQqlSWkwvWXsIDhk0rZZouaY3ForxdJBKf+QpnzvY X9s42L1MMBK0H7EWw0Gtl509ai+vaUxmnTw1StVzBzKDZsM5l3fvy9mTptomxW2Xh4e6 opAyofkfy+l4Z3mR/UQoqklMJIs12enGU4dFFogoNH+EflHO8ISY2373/YLEHaVBLTEo DDqevozhlUB3c9AalOFjAR0rl1W7YCKUKlqOvYEyAVTYrwH6kqOdI0kEdUdXtmnzYDe6 JX3A== 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=XhRWwBCkY27ULbttJ64jxc7MALm+CYwatCJ4DKIlujo=; b=HWJR/pTBYHKrktwzZi02PGwhC5Z4A7WzLnGP9agiCzRBQg1zMYu/FiRzDTLCRP32U/ /CgQQwlPbHIUVr24d/wHTtk1hhymhLCJBsHdGR/JfK31jbfPVs3k0Y8KzNdXVAMmw+UA BFl2SjXTZ9fOrJUpwZu9Y5OxxoT0gjbfwqJfCYy5YDL8e+RHY35Xhf4h9vYEyoX0a9tB XflqFa9MaKMDNLylcEjzgr1ooLhYOGiSwQeVecTAx3ZYB2uzDRefuolPWepC7ONtQSMX CHvEQagkyC42HHAdnrORqfzR/v9u2lMXBmw+VrW7MymEd+zXVOo56BzVTYgMUEnrLwBp sT+A== 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 h16si7054413ede.206.2021.03.16.20.43.55; Tue, 16 Mar 2021 20:44:17 -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 S230125AbhCQDkl (ORCPT + 99 others); Tue, 16 Mar 2021 23:40:41 -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 S229791AbhCQDkd (ORCPT ); Tue, 16 Mar 2021 23:40:33 -0400 IronPort-SDR: FvQyFpx9gnSRIa/hBDIttpaUNzs7GrH6EF6N8MX9rhw4hGQe5fI862rV55eeafPqaiM8c7FADi 7aUDL66zZJ2g== X-IronPort-AV: E=McAfee;i="6000,8403,9925"; a="186021879" X-IronPort-AV: E=Sophos;i="5.81,254,1610438400"; d="scan'208";a="186021879" 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:33 -0700 IronPort-SDR: zP/HjD10FnwmMD+ndEPUAOg91e0ixxYOw9OEEe8d5HvLhAsnygyWEZHYTC93zes0HGDimZrWzy b8z/MMIL4UwA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,254,1610438400"; d="scan'208";a="602075874" Received: from shbuild999.sh.intel.com ([10.239.147.94]) by fmsmga006.fm.intel.com with ESMTP; 16 Mar 2021 20:40:29 -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 05/13] mm/mempolicy: refactor rebind code for PREFERRED_MANY Date: Wed, 17 Mar 2021 11:40:02 +0800 Message-Id: <1615952410-36895-6-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 Again, this extracts the "only one node must be set" behavior of MPOL_PREFERRED. It retains virtually all of the existing code so it can be used by MPOL_PREFERRED_MANY as well. v2: Fixed typos in commit message. (Ben) Merged bits from other patches. (Ben) annotate mpol_rebind_preferred_many as unused (Ben) Link: https://lore.kernel.org/r/20200630212517.308045-6-ben.widawsky@intel.com Signed-off-by: Dave Hansen Signed-off-by: Ben Widawsky Signed-off-by: Feng Tang --- mm/mempolicy.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 6fb2cab..fbfa3ce 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -363,14 +363,11 @@ static void mpol_rebind_nodemask(struct mempolicy *pol, const nodemask_t *nodes) pol->v.nodes = tmp; } -static void mpol_rebind_preferred(struct mempolicy *pol, - const nodemask_t *nodes) +static void mpol_rebind_preferred_common(struct mempolicy *pol, + const nodemask_t *preferred_nodes, + const nodemask_t *nodes) { nodemask_t tmp; - nodemask_t preferred_node; - - /* MPOL_PREFERRED uses only the first node in the mask */ - preferred_node = nodemask_of_node(first_node(*nodes)); if (pol->flags & MPOL_F_STATIC_NODES) { int node = first_node(pol->w.user_nodemask); @@ -385,12 +382,30 @@ static void mpol_rebind_preferred(struct mempolicy *pol, pol->v.preferred_nodes = tmp; } else if (!(pol->flags & MPOL_F_LOCAL)) { nodes_remap(tmp, pol->v.preferred_nodes, - pol->w.cpuset_mems_allowed, preferred_node); + pol->w.cpuset_mems_allowed, *preferred_nodes); pol->v.preferred_nodes = tmp; pol->w.cpuset_mems_allowed = *nodes; } } +/* MPOL_PREFERRED_MANY allows multiple nodes to be set in 'nodes' */ +static void __maybe_unused mpol_rebind_preferred_many(struct mempolicy *pol, + const nodemask_t *nodes) +{ + mpol_rebind_preferred_common(pol, nodes, nodes); +} + +static void mpol_rebind_preferred(struct mempolicy *pol, + const nodemask_t *nodes) +{ + nodemask_t preferred_node; + + /* MPOL_PREFERRED uses only the first node in 'nodes' */ + preferred_node = nodemask_of_node(first_node(*nodes)); + + mpol_rebind_preferred_common(pol, &preferred_node, nodes); +} + /* * mpol_rebind_policy - Migrate a policy to a different set of nodes * -- 2.7.4