All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rakie Kim <rakie.kim@sk.com>
To: Gregory Price <gourry@gourry.net>
Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com,
	akpm@linux-foundation.org, david@kernel.org, ziy@nvidia.com,
	matthew.brost@intel.com, joshua.hahnjy@gmail.com,
	byungchul@sk.com, ying.huang@linux.alibaba.com,
	apopple@nvidia.com, urezki@gmail.com, chenwandun@huawei.com,
	linux-mm@kvack.org, kernel_team@skhynix.com,
	Rakie Kim <rakie.kim@sk.com>
Subject: Re: [PATCH 2/2] mm/mempolicy: stop copying the nodemask in the interleave paths
Date: Mon,  7 Sep 2026 17:57:27 +0900	[thread overview]
Message-ID: <20260907085730.2009-1-rakie.kim@sk.com> (raw)
In-Reply-To: <aprm5dwF_kWaOe44@gourry-fedora-PF4VCD3F>

On Fri, 4 Sep 2026 11:50:47 -0400 Gregory Price <gourry@gourry.net> wrote:

> On Fri, Sep 04, 2026 at 05:01:37PM +0900, Rakie Kim wrote:
> >
> > What I had in mind is the gap between the two reads. Say the policy
> > starts with two nodes, every weight is 10, and 100 pages are
> > requested:
> >
> > 	/* the mask is {0,1} here */
> > 	do {
> > 		cpuset_mems_cookie = read_mems_allowed_begin();
> > 		nnodes = nodes_weight(pol->nodes);	/* nnodes = 2 */
> > 	} while (read_mems_allowed_retry(cpuset_mems_cookie));
> >
> > 	/* a rebind grows the mask to {0,1,2,3} at this point */
> >
> > 	/* calculate total, detect system default usage */
> > 	for_each_node_mask(node, pol->nodes)
> > 		weight_total += ...;			/* 10 * 4 = 40 */
> >
> > 	rounds = rem_pages / weight_total;		/* 100 / 40 = 2 */
> >
> > 	for (i = 0; i < nnodes; i++)			/* bounded by 2 */
> > 		...
> >
>
> Consider:
>
> 	/* nodemask: {0,1} */
>  	for_each_node_mask(node, pol->nodes) {
>  		weight_total += ...;
> 		nnodes++;
> 	}
>
>  	/* a rebind grows the mask to {2,3,4,5} */
>
>  	rounds = rem_pages / weight_total;		/* 100 / 10 = 10 */
>  	for (i = 0; i < nnodes; i++)			/* bounded by 2 */
>  		...
>
> in this scenario every value is wrong.  The weight total was calculated
> based on {0,1} and the loop will use {2,3} weights and ignore {4,5}
> entirely.
>
> It's the nature of the mechanism and race - best we can do is ensure
> safety.  Ensuring correct distributions would likely require locks or
> reworking the entire weight mechanism.
>
> I'd rather keep the change simple (cookie the value that can cause a
> div/0) and leave the math alone.
>
> ~Gregory

Fair enough. Your example makes the point. The mask can change after
the sum as well, so matching the two reads does not get us a correct
distribution either. Keeping it simple sounds right to me.

Please feel free to add the following to this patch:
Reviewed-by: Rakie Kim <rakie.kim@sk.com>

Thanks for walking through it.

Rakie Kim


  reply	other threads:[~2026-09-07  8:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-29  1:59 [PATCH 0/2] mm/mempolicy: stop copying state in the interleave paths Gregory Price
2026-08-29  1:59 ` [PATCH 1/2] mm/mempolicy: use SRCU for the weighted interleave state Gregory Price
2026-08-29  1:59 ` [PATCH 2/2] mm/mempolicy: stop copying the nodemask in the interleave paths Gregory Price
2026-09-02  9:00   ` Rakie Kim
2026-09-02 14:52     ` Gregory Price
2026-09-04  8:01       ` Rakie Kim
2026-09-04 15:50         ` Gregory Price
2026-09-07  8:57           ` Rakie Kim [this message]
2026-08-29 23:18 ` [PATCH 0/2] mm/mempolicy: stop copying state " Andrew Morton
2026-08-30 16:39   ` Gregory Price

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=20260907085730.2009-1-rakie.kim@sk.com \
    --to=rakie.kim@sk.com \
    --cc=akpm@linux-foundation.org \
    --cc=apopple@nvidia.com \
    --cc=byungchul@sk.com \
    --cc=chenwandun@huawei.com \
    --cc=david@kernel.org \
    --cc=gourry@gourry.net \
    --cc=joshua.hahnjy@gmail.com \
    --cc=kernel-team@meta.com \
    --cc=kernel_team@skhynix.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=matthew.brost@intel.com \
    --cc=urezki@gmail.com \
    --cc=ying.huang@linux.alibaba.com \
    --cc=ziy@nvidia.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.