From: Junjie Fu <fujunjie1@qq.com>
To: Michal Hocko <mhocko@suse.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
akpm@linux-foundation.org, dave.hansen@intel.com,
gourry@gourry.net
Subject: Re: [PATCH] mm/mempolicy: Fix decision-making issues for memory migration during NUMA balancing
Date: Tue, 26 Nov 2024 03:45:01 +0800 [thread overview]
Message-ID: <tencent_52B8009E65148BE7B93C42479E6E642C0409@qq.com> (raw)
In-Reply-To: <Z0RgoOHMRFCTM1JB@tiehlicka>
On November 25, 2024 at 19:33, Michal Hocko wrote:
> On Sun 24-11-24 03:09:35, Junjie Fu wrote:
>> 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.
>
> The code is clearly confusing but is there any actual problem to be
> solved? IIRC although we do keep nodemask for MPOL_PREFERRED
> policy we do not allow to set more than a single node to be set there.
> Have a look at mpol_new_preferred
>
I apologize for the oversight when reviewing the code regarding the
process of setting only the first node in the nodemask for the
MPOL_PREFERRED memory policy. After reviewing the mpol_new_preferred
function, I realized that when setting the memory policy, only the first
node from the user's nodemask is copied into the corresponding memory
policy instance's nodemask, as shown in the following code:
static int mpol_new_preferred(struct mempolicy *pol, const nodemask_t
*nodes)
{
if (nodes_empty(*nodes))
return -EINVAL;
nodes_clear(pol->nodes);
node_set(first_node(*nodes), pol->nodes); //only the first node to
be set
return 0;
}
Due to my previous oversight, I mistakenly assumed that multiple nodes
could be set in pol->nodes, leading to my incorrect understanding.
Therefore, the original code is correct. Thank you all for your responses.
next prev parent reply other threads:[~2024-11-25 19:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-23 19:09 Junjie Fu
2024-11-23 22:15 ` Matthew Wilcox
2024-11-25 11:33 ` Michal Hocko
2024-11-25 16:06 ` Gregory Price
2024-11-25 19:45 ` Junjie Fu [this message]
2024-11-25 20:18 ` Michal Hocko
2024-11-25 20:41 ` Junjie Fu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tencent_52B8009E65148BE7B93C42479E6E642C0409@qq.com \
--to=fujunjie1@qq.com \
--cc=akpm@linux-foundation.org \
--cc=dave.hansen@intel.com \
--cc=gourry@gourry.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox