All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Gregory Price <gourry@gourry.net>
Cc: linux-mm@kvack.org, akpm@linux-foundation.org,
	edumazet@google.com, linux-kernel@vger.kernel.org,
	kernel-team@meta.com, stable@vger.kernel.org, david@kernel.org,
	ziy@nvidia.com, matthew.brost@intel.com, joshua.hahnjy@gmail.com,
	rakie.kim@sk.com, byungchul@sk.com, ying.huang@linux.alibaba.com,
	apopple@nvidia.com,
	syzbot+0dbf6d295b3350944f0b@syzkaller.appspotmail.com
Subject: Re: [PATCH] mm/mempolicy: refcount the weighted interleave state instead of copying it
Date: Mon, 24 Aug 2026 04:06:03 +0100	[thread overview]
Message-ID: <aou1Gwxk2s8Qjdm9@casper.infradead.org> (raw)
In-Reply-To: <20260824024117.1755899-1-gourry@gourry.net>

On Sun, Aug 23, 2026 at 10:41:17PM -0400, Gregory Price wrote:
> @@ -2632,7 +2654,7 @@ static unsigned long alloc_pages_bulk_weighted_interleave(gfp_t gfp,
>  	unsigned long nr_allocated = 0;
>  	unsigned long rounds;
>  	unsigned long node_pages, delta;
> -	u8 *weights, weight;
> +	u8 *table, weight;
>  	unsigned int weight_total = 0;
>  	unsigned long rem_pages = nr_pages;
>  	nodemask_t nodes;
> @@ -2676,25 +2698,12 @@ static unsigned long alloc_pages_bulk_weighted_interleave(gfp_t gfp,
>  	me->il_weight = 0;
>  	prev_node = node;
>  
> -	/* create a local copy of node weights to operate on outside rcu */
> -	weights = kzalloc(nr_node_ids, GFP_KERNEL);
> -	if (!weights)
> -		return total_allocated;
> -
> -	rcu_read_lock();
> -	state = rcu_dereference(wi_state);
> -	if (state) {
> -		memcpy(weights, state->iw_table, nr_node_ids * sizeof(u8));
> -		rcu_read_unlock();
> -	} else {
> -		rcu_read_unlock();
> -		for (i = 0; i < nr_node_ids; i++)
> -			weights[i] = 1;
> -	}
> +	state = wi_state_get();
> +	table = state ? state->iw_table : NULL;
>  
>  	/* calculate total, detect system default usage */
>  	for_each_node_mask(node, nodes)
> -		weight_total += weights[node];
> +		weight_total += table ? table[node] : 1;
>  
>  	/*
>  	 * Calculate rounds/partial rounds to minimize __alloc_pages_bulk calls.
> @@ -2706,10 +2715,10 @@ static unsigned long alloc_pages_bulk_weighted_interleave(gfp_t gfp,
>  	rounds = rem_pages / weight_total;
>  	delta = rem_pages % weight_total;
>  	resume_node = next_node_in(prev_node, nodes);
> -	resume_weight = weights[resume_node];
> +	resume_weight = table ? table[resume_node] : 1;
>  	for (i = 0; i < nnodes; i++) {
>  		node = next_node_in(prev_node, nodes);
> -		weight = weights[node];
> +		weight = table ? table[node] : 1;
>  		node_pages = weight * rounds;
>  		/* If a delta exists, add this node's portion of the delta */
>  		if (delta > weight) {
> @@ -2735,7 +2744,7 @@ static unsigned long alloc_pages_bulk_weighted_interleave(gfp_t gfp,
>  	}
>  	me->il_prev = resume_node;
>  	me->il_weight = resume_weight;
> -	kfree(weights);
> +	wi_state_put(state);
>  	return total_allocated;
>  }
>  

Bit of a shame to take/put a refcount on every memory allocation.  That
seems like it might hurt (even being on a different cacheline).  Would
it make more sense to use SRCU for this?


  reply	other threads:[~2026-08-24  3:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21 17:04 [PATCH] mm/mempolicy: Fix sleeping allocation in alloc_pages_bulk_weighted_interleave() Eric Dumazet
2026-08-21 17:40 ` Gregory Price
2026-08-21 17:40 ` Andrew Morton
2026-08-21 17:47   ` Gregory Price
2026-08-21 17:59   ` Eric Dumazet
2026-08-23 23:01   ` Gregory Price
2026-08-24  2:41   ` [PATCH] mm/mempolicy: refcount the weighted interleave state instead of copying it Gregory Price
2026-08-24  3:06     ` Matthew Wilcox [this message]
2026-08-24  3:52       ` Gregory Price
2026-08-24 15:09         ` Gregory Price
2026-08-24 18:39     ` Andrew Morton
2026-08-24 10:12 ` [PATCH] mm/mempolicy: Fix sleeping allocation in alloc_pages_bulk_weighted_interleave() David Hildenbrand (Arm)

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=aou1Gwxk2s8Qjdm9@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=apopple@nvidia.com \
    --cc=byungchul@sk.com \
    --cc=david@kernel.org \
    --cc=edumazet@google.com \
    --cc=gourry@gourry.net \
    --cc=joshua.hahnjy@gmail.com \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=matthew.brost@intel.com \
    --cc=rakie.kim@sk.com \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+0dbf6d295b3350944f0b@syzkaller.appspotmail.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.