From mboxrd@z Thu Jan 1 00:00:00 1970 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 754B1C71136 for ; Mon, 16 Jun 2025 10:55:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB7F56B008A; Mon, 16 Jun 2025 06:55:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E8FAA6B008C; Mon, 16 Jun 2025 06:55:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DCCFB6B0092; Mon, 16 Jun 2025 06:55:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id CDF836B008A for ; Mon, 16 Jun 2025 06:55:42 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7FCFF1A0F0F for ; Mon, 16 Jun 2025 10:55:42 +0000 (UTC) X-FDA: 83560958124.18.7C2F29A Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by imf27.hostedemail.com (Postfix) with ESMTP id 80D6340003 for ; Mon, 16 Jun 2025 10:55:39 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=BaOhuSjW; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf27.hostedemail.com: domain of ying.huang@linux.alibaba.com designates 115.124.30.130 as permitted sender) smtp.mailfrom=ying.huang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750071340; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=i8EdbzyYXZcEWHaoQ9QBBBH1FZsnTBo/AD39uza65v0=; b=lgHD8bgOW89Ae/QTvcW7cPJMZ6i39feQJg/QIVKsV3c4ROHH+ZI5LJm4QB+Tb0KtNbCRZf lCfYEMglKwbwym4dKNbdtIf5tZs+g+FKjFhpsLgi0doUNGXM5fK707lBK7dplhCTfdUuoN mUDYkaTt0sCqImJdBs2FbdG/ZmsKzRY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750071340; a=rsa-sha256; cv=none; b=78InuHDNi4lnTmERE2gwXr3jHMr2r4EGyBiVW/7p1bNs1mSYvoq0bCLJAdJ58wnyNdkFaC kRaAPAi3Zb/8AceMb+tAJmFMKrMUB0Evu9Nm3PjwZUHRQLxH/sgJQ8W9bFQhMXXDZFVdYL JAhofO++ARwHiL9sfHeSAmQTyY0Q3x0= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=BaOhuSjW; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf27.hostedemail.com: domain of ying.huang@linux.alibaba.com designates 115.124.30.130 as permitted sender) smtp.mailfrom=ying.huang@linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1750071336; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; bh=i8EdbzyYXZcEWHaoQ9QBBBH1FZsnTBo/AD39uza65v0=; b=BaOhuSjWV2CRDTzhpmjBaK/4xbXSSvO9tMNMleL/tVkUBnw8CMQeBDW8X6ChHLz8dFt8EvhI+hfN3COW2tBNagx8BBfQnl8PycM3h8nEwV1s9i64r+UW9Lgfxuf5MyW/r1MjFvYJbFAsO0yvVLj8BA3E1YDsuMrCpTYxqaSfPR4= Received: from DESKTOP-5N7EMDA(mailfrom:ying.huang@linux.alibaba.com fp:SMTPD_---0WdwwWRd_1750071334 cluster:ay36) by smtp.aliyun-inc.com; Mon, 16 Jun 2025 18:55:34 +0800 From: "Huang, Ying" To: Bijan Tabatabai Cc: David Hildenbrand , linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, sj@kernel.org, akpm@linux-foundation.org, corbet@lwn.net, ziy@nvidia.com, matthew.brost@intel.com, joshua.hahnjy@gmail.com, rakie.kim@sk.com, byungchul@sk.com, gourry@gourry.net, apopple@nvidia.com, bijantabatab@micron.com, venkataravis@micron.com, emirakhur@micron.com, ajayjoshi@micron.com, vtavarespetr@micron.com, damon@lists.linux.dev Subject: Re: [RFC PATCH 1/4] mm/mempolicy: Expose policy_nodemask() in include/linux/mempolicy.h In-Reply-To: (Bijan Tabatabai's message of "Fri, 13 Jun 2025 11:33:18 -0500") References: <20250612181330.31236-1-bijan311@gmail.com> <20250612181330.31236-2-bijan311@gmail.com> <5a50eeba-b26d-4913-8016-45278608a1ee@redhat.com> Date: Mon, 16 Jun 2025 18:55:32 +0800 Message-ID: <87zfe83qhn.fsf@DESKTOP-5N7EMDA> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 80D6340003 X-Stat-Signature: ki81y7dh1bpqjkqdtu8s4ona1auhfx3w X-Rspam-User: X-HE-Tag: 1750071339-51881 X-HE-Meta: U2FsdGVkX19ojJmPXr4fwLR6IHau8iVIELQ1STv+lfutNd8MqQIlvAOsfIdYB2gh90oR6zx3H2FMBMymi1DsbUT2Qevuff933iIs+m0r7tajjGuzD4rVOZa0rQFHAzd1JHhsVDT3YkBZfkfPdmnzm0Ggu1XhCLliuyLvFHc+0KbplYbtuI7yIdTk48Y0CsSzE8lsiY26oOSSP70x8rhHucugznvCBn6MaOL0ySF2/1fSFUbrAoriYYHsYtngC10YzhbnvjezhPm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2B1rFOz9ytCh81zDNxw1i1uytGm3W6K1mlpWZk0M0dIyLF6IxMzxqnb3eco0XUWpyz/n5GZVnell28dkvcnMPHiocvXNKMOSNngoSzX45RGVEUXJD17slOwW3y1l2LsasgOZN4VxJ5Rgg9JQ8Gm1RpaRYUSG4gYRn/R5ZmvnV+xJWgYMOSEk+o/7KC0E2kvtYm/e3zIDp31hMQ== 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: Bijan Tabatabai writes: > On Fri, Jun 13, 2025 at 8:45=E2=80=AFAM David Hildenbrand wrote: >> >> On 12.06.25 20:13, Bijan Tabatabai wrote: >> > From: Bijan Tabatabai >> > >> > This patch is to allow DAMON to call policy_nodemask() so it can >> > determine where to place a page for interleaving. >> > >> > Signed-off-by: Bijan Tabatabai >> > --- >> > include/linux/mempolicy.h | 9 +++++++++ >> > mm/mempolicy.c | 4 +--- >> > 2 files changed, 10 insertions(+), 3 deletions(-) >> > >> > diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h >> > index 0fe96f3ab3ef..e96bf493ff7a 100644 >> > --- a/include/linux/mempolicy.h >> > +++ b/include/linux/mempolicy.h >> > @@ -133,6 +133,8 @@ struct mempolicy *__get_vma_policy(struct vm_area_= struct *vma, >> > struct mempolicy *get_vma_policy(struct vm_area_struct *vma, >> > unsigned long addr, int order, pgoff_t *ilx); >> > bool vma_policy_mof(struct vm_area_struct *vma); >> > +nodemask_t *policy_nodemask(gfp_t gfp, struct mempolicy *pol, >> > + pgoff_t ilx, int *nid); >> > >> > extern void numa_default_policy(void); >> > extern void numa_policy_init(void); >> > @@ -232,6 +234,13 @@ static inline struct mempolicy *get_vma_policy(st= ruct vm_area_struct *vma, >> > return NULL; >> > } >> > >> > +static inline nodemask_t *policy_nodemask(gfp_t gfp, struct mempolicy= *pol, >> > + pgoff_t ilx, int *nid) >> > +{ >> > + *nid =3D NUMA_NO_NODE; >> > + return NULL; >> > +} >> > + >> > static inline int >> > vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *ds= t) >> > { >> > diff --git a/mm/mempolicy.c b/mm/mempolicy.c >> > index 3b1dfd08338b..54f539497e20 100644 >> > --- a/mm/mempolicy.c >> > +++ b/mm/mempolicy.c >> > @@ -596,8 +596,6 @@ static const struct mempolicy_operations mpol_ops[= MPOL_MAX] =3D { >> > >> > static bool migrate_folio_add(struct folio *folio, struct list_head = *foliolist, >> > unsigned long flags); >> > -static nodemask_t *policy_nodemask(gfp_t gfp, struct mempolicy *pol, >> > - pgoff_t ilx, int *nid); >> > >> > static bool strictly_unmovable(unsigned long flags) >> > { >> > @@ -2195,7 +2193,7 @@ static unsigned int interleave_nid(struct mempol= icy *pol, pgoff_t ilx) >> > * Return a nodemask representing a mempolicy for filtering nodes for >> > * page allocation, together with preferred node id (or the input no= de id). >> > */ >> > -static nodemask_t *policy_nodemask(gfp_t gfp, struct mempolicy *pol, >> > +nodemask_t *policy_nodemask(gfp_t gfp, struct mempolicy *pol, >> > pgoff_t ilx, int *nid) >> > { >> > nodemask_t *nodemask =3D NULL; >> >> You actually only care about the nid for your use case. >> >> Maybe we should add >> >> get_vma_policy_node() that internally does a get_vma_policy() to then >> give you only the node back. >> >> If get_vma_policy() is not the right thing (see my reply to patch #2), >> of course a get_task_policy_node() could be added. >> >> -- >> Cheers, >> >> David / dhildenb > > Hi David, > > I did not use get_vma_policy or mpol_misplaced, which I believe is the > closest function that exists for what I want in this patch, because > those functions > seem to assume they are called inside of the task that the folio/vma > is mapped to. > More specifically, mpol_misplaced assumes it is being called within a > page fault. > This doesn't work for us, because we call it inside of a kdamond process. > > I would be open to adding a new function that takes in a folio, vma, > address, and > task_struct and returns the nid the folio should be placed on. It could p= ossibly > be implemented as a function internal to mpol_misplaced because the two w= ould > be very similar. > > How would you propose we handle MPOL_BIND and MPOL_PREFFERED_MANY > in this function? mpol_misplaced chooses a nid based on the node and > cpu the fault > occurred on, which we wouldn't have in a kdamond context. The two options= I see > are either: > 1. return the nid of the first node in the policy's nodemask > 2. return NUMA_NO_NODE > I think I would lean towards the first. You can try numa_node_id() first, then fall back to the first nid in the nodemask. --- Best Regards, Huang, Ying