From patchwork Sat Nov 23 19:09:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junjie Fu X-Patchwork-Id: 13883927 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 C09C1E65D18 for ; Sat, 23 Nov 2024 19:12:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1F1936B007B; Sat, 23 Nov 2024 14:12:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A1E16B0083; Sat, 23 Nov 2024 14:12:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 072BE6B0085; Sat, 23 Nov 2024 14:12:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DB85A6B007B for ; Sat, 23 Nov 2024 14:12:41 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 17160161C12 for ; Sat, 23 Nov 2024 19:12:41 +0000 (UTC) X-FDA: 82818306480.16.8B06934 Received: from xmbghk7.mail.qq.com (xmbghk7.mail.qq.com [43.163.128.47]) by imf28.hostedemail.com (Postfix) with ESMTP id 5EA08C000A for ; Sat, 23 Nov 2024 19:12:36 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=qq.com header.s=s201512 header.b=YBbwVYAO; spf=pass (imf28.hostedemail.com: domain of fujunjie1@qq.com designates 43.163.128.47 as permitted sender) smtp.mailfrom=fujunjie1@qq.com; dmarc=pass (policy=quarantine) header.from=qq.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732389159; 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:references:dkim-signature; bh=eSGfu26T77d7IY4FTCS0fWJCHz54TUU/hG40FkEQcTI=; b=WHecsbC4uumWVpmE5c53E5arPM7+gy4ORBtK5b2DunA7MmFSj5WAErxfEmdtKPrW7u0yD0 3dVD5hPoE2zIc/fQncF7BCsLL6snNnJsZ2kuN/YWC2F0wAvmkVCwjmXFhytaUOU9nup5ZJ 26XHnDxIcrdfcIae2xr6tDT1GYHRQEU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732389159; a=rsa-sha256; cv=none; b=mqpLdbAQEc/37Yhba4E3yMdWEBvSO/iWEYtmPXumuIfj2gbtphzPyn372t/l+GSJXnmCvV TL9cDUqhlwwW+mMNjILlOVv9zXFxrW+gWlLDDc7iHHUmk8tRxuUYimfKoIEkAi1yuN2dSB KkCSMmJ+hOfOmcIrPU5Gfi5wuvwCMWg= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=qq.com header.s=s201512 header.b=YBbwVYAO; spf=pass (imf28.hostedemail.com: domain of fujunjie1@qq.com designates 43.163.128.47 as permitted sender) smtp.mailfrom=fujunjie1@qq.com; dmarc=pass (policy=quarantine) header.from=qq.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1732389138; bh=eSGfu26T77d7IY4FTCS0fWJCHz54TUU/hG40FkEQcTI=; h=From:To:Cc:Subject:Date; b=YBbwVYAO7Wpgmpr779paxBHZVR/KU2TcpVq9oMOPTAqG3y1Qj3D6yUWT23TBcSDYD UlXxbgRX53HHhdqvNL43ltOQUxm09q8nUd8B3Nmmv7Keb0tukbohMJAJnlz9eZejJL wvickF3J0ec44YOUexlh2GEPmneEZ4jdBnyq5AGA= Received: from localhost.localdomain ([2409:875e:a030:1001:14::90f]) by new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wbZGeCcdNyfzWr0bZtrR9AGGd Wk67TISSx6TYyi1VfLGdHMaKA5YQN9BauVCtCcfloS1diOpdQDktqm/mzs1oCz X-QQ-XMRINFO: NS+P29fieYNw95Bth2bWPxk= From: Junjie Fu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: akpm@linux-foundation.org, dave.hansen@intel.com, mhocko@kernel.org, fujunjie1@qq.com Subject: [PATCH] mm/mempolicy: Fix decision-making issues for memory migration during NUMA balancing Date: Sun, 24 Nov 2024 03:09:35 +0800 X-OQ-MSGID: <20241123190935.2433794-1-fujunjie1@qq.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Stat-Signature: irss6bwc1fqfwk6awphkpry7jhnd39xa X-Rspamd-Queue-Id: 5EA08C000A X-Rspam-User: X-HE-Tag: 1732389156-21982 X-HE-Meta: U2FsdGVkX18cb+7QP+X5qw1wqDfWtNJIfVtcYKTvWQ71eQjM/XxeKYI1w7+8KgAo1/Y4hdc9VPSyrn0pJkx70AwzBHUpTZLf/XUEpMedYaW2RC4jkG+Qo29ea97tkYG2xjEpondvYK8zpKKqQiBgzMhlzpFLOMkVpHY0n32dBzH+BQ28Yf0FV3/NWMB3tFJkYjBSKTC6LkCvMneO2UdXUTzkYtar8LOB+FVLfg/Gca2sk2HQX55X2VWo3AYUmpNU7EBy8ItzMWRhaLFxZdL8A0QeBwtxoNcR27B8jIyndC0yLsHsJQn+xwZEJzDM0rvbSyW+FrsSG5LYtpM/WKsD/Us4BiSTuvyvf+zfVfvHTAq+tWQXRMRq1J38hmdupVQ658/gF1lPgGqcA/LJ9NRsrPMC3Q/oRjQC2W9+jDxyc0gKs05CjPOX8a7SxlG+HJ5EfcfqsiyyvSYuqqrkAu8DOs+SvZXykIbOC8Zs9rlDHk0/R1gyYSrD4tYOq9xGft8vQ0i4InR9UrNpAezyYLsSJ336gw3y4F4O0pUvq7DzXvN3eAMEHhFGlBMOpAwDCmL9pk+PMlHSQwH5xPV86HNNJTMp/p8+aKFpNtY3B+x4D/S9dDb+rR/sdC4+mZXWC8aOXakv1QgWwTgbQB9lJXj3+kbtr2aP/da6s0ihu9ActeO1eAWt8BA2efM3eLeDZKJSqzwViE8S0ADw+jN6lry+hVm22suXfAMzRxe47SCyKKMxhoTsYfhrfoVjgvAmXDjzwrU/AFbl6403wcNB+0WuKJ1IHyDL8kgy/1qoU62bQrYH2s7l8m/9f8/6YKuk5CEgN3ZXlrjBkxqCro2ese7psWYkG/X5MdCZGluKjKckJtIgzEvzvVLnXnnEpkRfROfTkurSsKKDZtGevCiPGfINYtkcGJ9F6Ng4tk5tGBAdfSJONtiFzXim4Ei2M6QPFosY01g5mn2rKtzZBpgq4+1 p1PgsFri NJOT/tJ5a1L6Y+2g+vdbHLRMXzPZT7KYHHmbhHmmkHv3rzeZnQMQgvPCpTSILJTlqF+WBPipHlEIt34r3TE9hswaKJpxyFPOsFtbrtZW4J0jI2BDfYWLuBkUD81oi6I+sCW86MPqDQtumAAU/Qge8VSj9m7VAz0mUheHVL7iTK+W9jVf2PVxtwxtSV1UDC3Ih29OVKJQX77vM6T/ZRH0BOfqZqw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.010179, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When handling a page fault caused by NUMA balancing (do_numa_page), it is necessary to decide whether to migrate the current page to another node or keep it on its current node. For pages with the MPOL_PREFERRED memory policy, it is sufficient to check whether the first node set in the nodemask is the same as the node where the page is currently located. If this is the case, the page should remain in its current state. Otherwise, migration to another node should be attempted. Because the definition of MPOL_PREFERRED is as follows: "This mode sets the preferred node for allocation. The kernel will try to allocate pages from this node first and fall back to nearby nodes if the preferred node is low on free memory. If the nodemask specifies more than one node ID, the first node in the mask will be selected as the preferred node." Thus, if the node where the current page resides is not the first node in the nodemask, it is not the PREFERRED node, and memory migration can be attempted. However, in the original code, the check only verifies whether the current node exists in the nodemask (which may or may not be the first node in the mask). This could lead to a scenario where, if the current node is not the first node in the nodemask, the code incorrectly decides not to attempt migration to other nodes. This behavior is clearly incorrect. If the target node for migration and the page's current NUMA node are both within the nodemask but neither is the first node, they should be treated with the same priority, and migration attempts should proceed. Signed-off-by: Junjie Fu --- mm/mempolicy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index bb37cd1a51d8..3454dfc7da8d 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2769,7 +2769,7 @@ int mpol_misplaced(struct folio *folio, struct vm_fault *vmf, break; case MPOL_PREFERRED: - if (node_isset(curnid, pol->nodes)) + if (curnid == first_node(pol->nodes)) goto out; polnid = first_node(pol->nodes); break;