Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp20206pxf; Tue, 16 Mar 2021 20:45:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwicDk51k2WBQ3fu1ZvdBa5rQcFuAc7BUV9OH6UK6xKFGAatGqwRR/QghPTpDc9MnXVjtWd X-Received: by 2002:a17:907:2062:: with SMTP id qp2mr33208054ejb.397.1615952707930; Tue, 16 Mar 2021 20:45:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615952707; cv=none; d=google.com; s=arc-20160816; b=ixzWeyzfHpNPZUhJEGVxye/ePmENhF5lk1Ohp/yaU7KMopd9dVOK6phwPcnf3uCw1m tptYKyLyP8TajhIU4HJ4fPZZn+sSuEii5rF0yK2cJBhWpW18PSBdASTUsXNw2clL0xur 2wIaTrikn385Nc+i6r6eIM3xO1/XFwzxaQgJMkR952VdZks58OSrHt0rrd8Ye96jcWMc +Vek3uzFUU8k/woc8cI89q+3Kg2wrv2hyjuTr+HpeNPjuys21D+iqyJStFd4x8NgnUTY 3t+KebT3362WRVr5b+MRWm/RLgsxSVUMKkCEcQZvfuRhVKESEL3yzihnBlHbZPK3q0W1 39KQ== 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=86XTrjQh0zEEebDRaCgNpv+I0wOXLC3AZH+5dBK97jk=; b=H8OAsb6cI2yE++Hqtu6TMSLPvw02VB9yvShn2E5DVXUDLB7+trjJLTtL0aiXc6/Uby OlqVICe4q5qXNpIy+gGmaqqI9eGZB4iJnKlwyS3Kem3ngFE+J3siykVznVMA1Aadu0G2 nLkzZg9XyC5lIfgbmrxXQr9ibUbtv1taMjV6rfceXVSJOlS88VFJQgiFy0Kp5OTaoXTd /zoDIDoGD0gYYJr1M+n/YsEyRyi/dDqQh58v6ODlDQEuNqC2vwLwuVtVRwCHOwo1Cqhn gHEimBkLaDgLVF3Ha2ntfKMXGr7XkIDCydxwEGQDjhEmZ1g2V0a+NP1gkkUW6HckRc64 gNvQ== 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 a26si13884968edx.539.2021.03.16.20.44.45; Tue, 16 Mar 2021 20:45:07 -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 S230389AbhCQDlV (ORCPT + 99 others); Tue, 16 Mar 2021 23:41:21 -0400 Received: from mga05.intel.com ([192.55.52.43]:57774 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230147AbhCQDlD (ORCPT ); Tue, 16 Mar 2021 23:41:03 -0400 IronPort-SDR: uj87DGqwH5JDDqP75B0vJ3vwarrW+I2+8DzvnOZuArmInbvMw2Pmy4LQnn5+rSluf0uaW87iwI JhjJlA86w71Q== X-IronPort-AV: E=McAfee;i="6000,8403,9925"; a="274426137" X-IronPort-AV: E=Sophos;i="5.81,254,1610438400"; d="scan'208";a="274426137" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2021 20:41:03 -0700 IronPort-SDR: 0QhJdy7QGydoeAImcsOKM4oPxEqMCJtV7/yKuRK9ebdUYdHqIU+Xrlr22K+IVoE/z+HiATTO9U goKah0qb01Pg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,254,1610438400"; d="scan'208";a="602076101" Received: from shbuild999.sh.intel.com ([10.239.147.94]) by fmsmga006.fm.intel.com with ESMTP; 16 Mar 2021 20:41:00 -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 , Feng Tang Subject: [PATCH v4 13/13] mem/mempolicy: unify mpol_new_preferred() and mpol_new_preferred_many() Date: Wed, 17 Mar 2021 11:40:10 +0800 Message-Id: <1615952410-36895-14-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 To reduce some code duplication. Signed-off-by: Feng Tang --- mm/mempolicy.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 18aa7dc..ee99ecc 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -201,32 +201,21 @@ static int mpol_new_interleave(struct mempolicy *pol, const nodemask_t *nodes) return 0; } -static int mpol_new_preferred_many(struct mempolicy *pol, +/* cover both MPOL_PREFERRED and MPOL_PREFERRED_MANY */ +static int mpol_new_preferred(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->nodes = *nodes; - return 0; -} - -static int mpol_new_preferred(struct mempolicy *pol, const nodemask_t *nodes) -{ - if (nodes) { + else { /* MPOL_PREFERRED can only take a single node: */ - nodemask_t tmp; + nodemask_t tmp = nodemask_of_node(first_node(*nodes)); - if (nodes_empty(*nodes)) - return -EINVAL; - - tmp = nodemask_of_node(first_node(*nodes)); - return mpol_new_preferred_many(pol, &tmp); + pol->nodes = (pol->mode == MPOL_PREFERRED) ? tmp : *nodes; } - - return mpol_new_preferred_many(pol, NULL); + return 0; } static int mpol_new_bind(struct mempolicy *pol, const nodemask_t *nodes) @@ -468,7 +457,7 @@ static const struct mempolicy_operations mpol_ops[MPOL_MAX] = { }, /* [MPOL_LOCAL] - see mpol_new() */ [MPOL_PREFERRED_MANY] = { - .create = mpol_new_preferred_many, + .create = mpol_new_preferred, .rebind = mpol_rebind_preferred_many, }, }; -- 2.7.4