Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp622726lqc; Fri, 8 Mar 2024 07:17:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWdjrGymzCJKoEf4jrxACogvUuX63eQXxD+0IvcMYETMFQUbsiUxtFz2TnrdmKD479zxuVoSDgvOrth5Fxb0BjCEM5ffEL/ehKeNsk3gw== X-Google-Smtp-Source: AGHT+IFl/zShXvRavwJwGKRc0jG4mXRLAmhdTs1aQbPc3DNAy+vwVLJcktLBGVdBWgqSAN0KvAOU X-Received: by 2002:ac8:7d14:0:b0:42e:be32:669b with SMTP id g20-20020ac87d14000000b0042ebe32669bmr368384qtb.40.1709911044449; Fri, 08 Mar 2024 07:17:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709911044; cv=pass; d=google.com; s=arc-20160816; b=RhcmMvM0qYl07DeiVgpKA50WAJIV83QHLEtemY/FBf+4EEzaGo6oGse7hxOmCnkCAV wd7NiE3I1ZfopyP1SHhG61ZUu6u3kuzSWlu0J7X8IE3OswmSQ2riiDQWTPIuQ0pn83LZ +a9Z2S5X4YybnzsUA/sO/5fSlz6aHuF4VQ+x310L5k+6a+PxKqTS8n6vFSnQJtLZz23F CgyVbSCTNW+j9MYmKmT4UkojR68p+Rb+UJpNBeFTigxTBcoATV0hH1Ot5M5CAowGaDYy /DmJwV4pUpSX+ZTTmJ9i7RViwlzMLQSRZhdGcjfyCnuxsMSpjKC1Nwn4fh8KezzDvbpS HE+Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=xD4BUagKz9NF9+nwODZKIkXZMdm0V3dM0BpUskdMkng=; fh=U12L/0KYs11bk/JAOkh3R44TAENIDyc2OzRsyWjsraA=; b=z7dzFtQKjZIucK+2RIGvLDlc2vEO/nf7uLC/Aydwukn2Lel/W1+FiEnbhG3DGICX61 an+efkKLGkCN8J+fSfHFOE6yjLun63o99Upw1SIgCzGkTtKLx4VGu+AC/kiEnsiA6Pkv /Yp+wigT0q3aAYUMgC3kH5C6GVaiAhr8a8lmYHvfehmVcgTQESVyS8gO8ETVIxkTGMzH TA+5sS+j0XhoGUP0EvcomWYTy+Vdk2zWap/+SuYMP+jRVKrcbT1+zh+Bn+iCwl38vsBv PcWE0APFn/NAT5od2S+b5eByEX0g+bkXOlJjJRx26c6A/sCG9v9B6312o8pHB1Pkdswe z4Vw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=XF6yIrsu; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-97221-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97221-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id l10-20020a05622a174a00b0042f3083dc3fsi683673qtk.381.2024.03.08.07.17.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 07:17:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97221-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=XF6yIrsu; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-97221-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97221-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 230F71C21624 for ; Fri, 8 Mar 2024 15:17:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BFCD01DDFA; Fri, 8 Mar 2024 15:17:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="XF6yIrsu" Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3B131D54D for ; Fri, 8 Mar 2024 15:17:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709911033; cv=none; b=bsw8EMrKIpgSAyBDlscHLGejmVtM3mmUPuU+X4UdrWjMW9HnpDL4XWFFpu1v74d7Ki43NkJyVVQZy6pVitUqK5K/7phGPpd0ZgfmaHD1TpwutL8W4NC5UwxTvXcqut1jAO8r29qX2G3MG6sxSBL31pVt5n5lIuC18zD3Eg+yYig= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709911033; c=relaxed/simple; bh=L0GXK8sj0SWNJEA45uUS22w/R7Z6RwF0QpW+5FFjFLM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=J8Sjgx8mA2Sf8OI8w+XUSj2/Bry47qb0iLMYJBKFaKMflOAyTrOvLfWeIgMKGt3BrQo/PNRJobr0XP7ZRTIdiAUTCyNx4gFudACBOzG2zX8d7sdLJbKQEB303hK2n7+xMshFn2CHK1z23n9ZoduJyZpw9GlICkzud2ivcD2cybM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=XF6yIrsu; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.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: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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. -- 2.39.3