From patchwork Fri Mar 8 15:15:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donet Tom X-Patchwork-Id: 13586936 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D4C9C5475B for ; Fri, 8 Mar 2024 15:17:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F30DC6B039D; Fri, 8 Mar 2024 10:17:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EE22D6B039F; Fri, 8 Mar 2024 10:17:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA8586B03A0; Fri, 8 Mar 2024 10:17:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id CC0BA6B039D for ; Fri, 8 Mar 2024 10:17:04 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9500540E05 for ; Fri, 8 Mar 2024 15:17:04 +0000 (UTC) X-FDA: 81874224768.08.A2BE2C3 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf17.hostedemail.com (Postfix) with ESMTP id 3A91340009 for ; Fri, 8 Mar 2024 15:17:01 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=XF6yIrsu; spf=pass (imf17.hostedemail.com: domain of donettom@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=donettom@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709911022; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xD4BUagKz9NF9+nwODZKIkXZMdm0V3dM0BpUskdMkng=; b=rpVVKub6C1OdRuyd0vrwpm6QAhbSgeEHt6CFBhPB4JM7YzQhchgiLExTuR/zlqDeZzU4uw rEKvKrUL3MNCiBWoT3IFm2WSC+l5VDka7n9gINtOKd47PrVIZifgngf5ytplCq+pxY08WG lkCUhetWs27SNuVfGIPzsawq9lUfD4k= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709911022; a=rsa-sha256; cv=none; b=dlAOqcpe1E23MxzMguSXxovU9A3fnm5TtHkxNBAGYaMRPfupiL8y41X9IeUMV9h8z7qd7e MlcFaKOahgTcUm0YegpIAU6utBx7DpvNCaagKuNaVbgrr/j+MNLLBG3m/AUPRHG82I1LU+ U3MaplBRoqUAqcNn1nUATX/52p8pbW4= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=XF6yIrsu; spf=pass (imf17.hostedemail.com: domain of donettom@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=donettom@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 428F22L4000388; Fri, 8 Mar 2024 15:16:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=xD4BUagKz9NF9+nwODZKIkXZMdm0V3dM0BpUskdMkng=; b=XF6yIrsuOOauiwJrDttTORqWLU1Pm7KBaaR/cpr/TCyg/DzlAhiIgwgr2sAwpdfAYaZ5 ahxw+C6pmcT+5UTdBXwWPGmIOrtJcxFirebHGBkGMSt+wzjek0YvOLmsOhDnMOsFwpSV NmSfr2ORSNYKN7eXagxp32naqzQWJjQW7h1pcAtT5S0UWOy4t+qfuBNG2LLCEkdlSlkH Ycs03HF3feLqy1seGkzPpcC5Vp3YFDDu1o56L87BKeTdvo89PFgxkiaEH6hEzjLadR55 Pn4v7eCQvEWaECeLjzndnKjQr06Tl0FkccB/HSJVv7u/KKwGChjTIwlJT1NqHZrdV9sX ZQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wr4y788gx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 08 Mar 2024 15:16:41 +0000 Received: from m0353729.ppops.net (m0353729.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 428F4Iro013691; Fri, 8 Mar 2024 15:16:40 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wr4y788ge-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 08 Mar 2024 15:16:40 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 428DJ9Us024193; Fri, 8 Mar 2024 15:16:38 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3wpjwsrd37-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 08 Mar 2024 15:16:38 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 428FGYvP21365482 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 8 Mar 2024 15:16:36 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A475C2004F; Fri, 8 Mar 2024 15:16:34 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9A4E120040; Fri, 8 Mar 2024 15:16:31 +0000 (GMT) Received: from ltczz402-lp1.aus.stglabs.ibm.com (unknown [9.53.171.174]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 8 Mar 2024 15:16:31 +0000 (GMT) From: Donet Tom To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Aneesh Kumar , Huang Ying , Michal Hocko , Dave Hansen , Mel Gorman , Feng Tang , Andrea Arcangeli , Peter Zijlstra , Ingo Molnar , Rik van Riel , Johannes Weiner , Matthew Wilcox , Vlastimil Babka , Dan Williams , Hugh Dickins , Kefeng Wang , Suren Baghdasaryan , Donet Tom Subject: [PATCH v2 2/2] mm/numa_balancing:Allow migrate on protnone reference with MPOL_PREFERRED_MANY policy Date: Fri, 8 Mar 2024 09:15:38 -0600 Message-Id: <369d6a58758396335fd1176d97bbca4e7730d75a.1709909210.git.donettom@linux.ibm.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: n2cYCcYTqRR81FJi3Lo2sRCKtpBExAl4 X-Proofpoint-ORIG-GUID: shpIrlyi5QEj0KPM72RBPFsGNGyQhM1T X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-08_08,2024-03-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 spamscore=0 impostorscore=0 mlxscore=0 lowpriorityscore=0 mlxlogscore=999 clxscore=1015 phishscore=0 adultscore=0 bulkscore=0 suspectscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2403080123 X-Stat-Signature: 77gcc5jodwxx7n7dt57owdeoc97uucnp X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 3A91340009 X-Rspam-User: X-HE-Tag: 1709911021-792643 X-HE-Meta: U2FsdGVkX19IJArT+nbyIecsB3sFa2FqEgtA8JA+BbYk6k2FB1kjnTDeBP8UDAJGqy81I3ZatzfiJ1+Shmz55l1Tg4ZyoWOa/iLbkKZuUq1stq6ZurK8hblnMS1aFdlWAQ9Er7O/ZnjeepWgP3IpPZKelZl1WiEJGjfFyY74D/tT6LhIFP6FtaX9k7B76+AN2yzOspEc6Mw9EnN+h1rx+/zTUZmOLqUMDR2qZ96ohJpJHFWK5oAyrc7EHZqPEXYPa4PipqfAKYCM6U6PJOHVSuzYx+CjYi9cOZOffEdVuHi7IGshcSswxdgozWCj7FnCUf53UzUHJ4BCb91bVMmaLCTtlfhPQA3S9NHveEVXLFUf42P7nG9gU12APFlXK0y0xImsxMgvIPMWafqsQUijHY7SCKHllYd8Rstj8KHp2nLxO5R7NCy5+LS2qKvJ2pGsWmAYGSHgUGuWtOJrZaUkCoTTTojS9SOsGW9zy4BbXgZi0x04MlM9D/HTtwJOcug5O5lKiYbN/CDsF/ceKfoLV2d8/W0s8eCmRV0SMz3Vo0XV7wn7m9o095s8J9kVfwSL4FhuCbB/9lY365JPvM3kdvI6JAaK8AoI+x5NwhY8v/1N7NZ8eGWqOSjEBDwyX9KFCBq56uqtd+I+RwAsBlzcjHbSDQf4e1HSv7JnE22HizeSfJGnOPz9A7fZPxaH1bTvKz3I+lIzMgmF1NvWXdM6R3QusDczYz4Ui7ZxAMy3jEQUdFOPpTJ4i14IDCOoS9ntYZAAqP1DNcrszS1pIgl4av4QUboV0lZP3f79L1NMUNlZK3lX71mNsIQ5y+iQ3LknqJSA1+hcVTPuUG9b/2n+B7y9ELtTTf5RMrb+hIH2uk1a4hG/Mc578cF9q8OsUwPGxuFSSyeGBkSWU8eX0XVWbDahxqYERkNE92YJFa46RZW2Rj45CsVwOJEUC5CtS/N1COvP6ZlBM80Zc637DJy DSJEh+65 vfWGzFG0rAS2mCQbZu7gbMt5xCob1nIFQPB3FZbKIzMwq4OgwJ2BZl1YeOBwVXTwCp16E2lQXPVjPzdzWEQg/eRyVoZtptNROyiz0llW1yRDdaAq834ilGdyhLWIWRbw74Al0E25RS1zun7qjlFBhZozZ/CfYk87tkrTfUyIdH2tW2XGzrFiMx93OIZC3KlY/w4dnMPHzk0ljrIyMswLXsrtpaZjM2p2BU+K8nQA/FiZVSs4ZF+G0l0Pf3av9IqdjKgBg X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: commit bda420b98505 ("numa balancing: migrate on fault among multiple bound nodes") added support for migrate on protnone reference with MPOL_BIND memory policy. This allowed numa fault migration when the executing node is part of the policy mask for MPOL_BIND. This patch extends migration support to MPOL_PREFERRED_MANY policy. Currently, we cannot specify MPOL_PREFERRED_MANY with the mempolicy flag MPOL_F_NUMA_BALANCING. This causes issues when we want to use NUMA_BALANCING_MEMORY_TIERING. To effectively use the slow memory tier, the kernel should not allocate pages from the slower memory tier via allocation control zonelist fallback. Instead, we should move cold pages from the faster memory node via memory demotion. For a page allocation, kswapd is only woken up after we try to allocate pages from all nodes in the allocation zone list. This implies that, without using memory policies, we will end up allocating hot pages in the slower memory tier. MPOL_PREFERRED_MANY was added by commit b27abaccf8e8 ("mm/mempolicy: add MPOL_PREFERRED_MANY for multiple preferred nodes") to allow better allocation control when we have memory tiers in the system. With MPOL_PREFERRED_MANY, the user can use a policy node mask consisting only of faster memory nodes. When we fail to allocate pages from the faster memory node, kswapd would be woken up, allowing demotion of cold pages to slower memory nodes. With the current kernel, such usage of memory policies implies we can't do page promotion from a slower memory tier to a faster memory tier using numa fault. This patch fixes this issue. For MPOL_PREFERRED_MANY, if the executing node is in the policy node mask, we allow numa migration to the executing nodes. If the executing node is not in the policy node mask, we do not allow numa migration. Signed-off-by: Aneesh Kumar K.V (IBM) Signed-off-by: Donet Tom --- mm/mempolicy.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index e635d7ed501b..ccd9c6c5fcf5 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1458,9 +1458,10 @@ static inline int sanitize_mpol_flags(int *mode, unsigned short *flags) if ((*flags & MPOL_F_STATIC_NODES) && (*flags & MPOL_F_RELATIVE_NODES)) return -EINVAL; if (*flags & MPOL_F_NUMA_BALANCING) { - if (*mode != MPOL_BIND) + if (*mode == MPOL_BIND || *mode == MPOL_PREFERRED_MANY) + *flags |= (MPOL_F_MOF | MPOL_F_MORON); + else return -EINVAL; - *flags |= (MPOL_F_MOF | MPOL_F_MORON); } return 0; } @@ -2515,15 +2516,26 @@ int mpol_misplaced(struct folio *folio, struct vm_fault *vmf, break; case MPOL_BIND: - /* Optimize placement among multiple nodes via NUMA balancing */ + case MPOL_PREFERRED_MANY: + /* + * Even though MPOL_PREFERRED_MANY can allocate pages outside + * policy nodemask we don't allow numa migration to nodes + * outside policy nodemask for now. This is done so that if we + * want demotion to slow memory to happen, before allocating + * from some DRAM node say 'x', we will end up using a + * MPOL_PREFERRED_MANY mask excluding node 'x'. In such scenario + * we should not promote to node 'x' from slow memory node. + */ if (pol->flags & MPOL_F_MORON) { + /* + * Optimize placement among multiple nodes + * via NUMA balancing + */ if (node_isset(thisnid, pol->nodes)) break; goto out; } - fallthrough; - case MPOL_PREFERRED_MANY: /* * use current page if in policy nodemask, * else select nearest allowed node, if any.