* [PATCH] mm/mempolicy: convert mempolicy refcnt to refcount_t
@ 2026-10-15 23:13 Gregory Price (Meta)
2026-10-15 23:46 ` SJ Park
2026-10-16 7:54 ` David Hildenbrand (Arm)
0 siblings, 2 replies; 4+ messages in thread
From: Gregory Price (Meta) @ 2026-10-15 23:13 UTC (permalink / raw)
To: linux-mm
Cc: linux-kernel, kernel-team, akpm, david, gourry, ziy,
joshua.hahnjy, rakie.kim, ying.huang, kernel test robot
struct mempolicy uses an atomic_t as a pure reference counter.
Convert it to refcount_t so that overflow and underflow are caught
by the refcount saturation checks.
This silences the atomic_as_refcounter.cocci warning, which started
matching __mpol_put() when it switched kmem_cache_free() to kfree_rcu().
No functional change for correct callers.
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202610061946.Bx22ZFrw-lkp@intel.com/
Signed-off-by: Gregory Price (Meta) <gourry@gourry.net>
---
include/linux/mempolicy.h | 5 +++--
mm/mempolicy.c | 14 +++++++-------
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
index 65c732d440d2..8b7570a90e54 100644
--- a/include/linux/mempolicy.h
+++ b/include/linux/mempolicy.h
@@ -10,6 +10,7 @@
#include <linux/mmzone.h>
#include <linux/slab.h>
#include <linux/rbtree.h>
+#include <linux/refcount.h>
#include <linux/spinlock.h>
#include <linux/node.h>
#include <linux/nodemask.h>
@@ -45,7 +46,7 @@ struct mm_struct;
* to 1, representing the caller of mpol_dup().
*/
struct mempolicy {
- atomic_t refcnt;
+ refcount_t refcnt;
unsigned short mode; /* See MPOL_* above */
unsigned short flags; /* See set_mempolicy() MPOL_F_* above */
nodemask_t nodes; /* interleave/bind/preferred/etc */
@@ -96,7 +97,7 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
static inline void mpol_get(struct mempolicy *pol)
{
if (pol)
- atomic_inc(&pol->refcnt);
+ refcount_inc(&pol->refcnt);
}
extern bool __mpol_equal(struct mempolicy *a, struct mempolicy *b);
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 70298fded1b4..7c78c66f7f21 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -138,7 +138,7 @@ enum zone_type policy_zone = 0;
* run-time system-wide default policy => local allocation
*/
static struct mempolicy default_policy = {
- .refcnt = ATOMIC_INIT(1), /* never free it */
+ .refcnt = REFCOUNT_INIT(1), /* never free it */
.mode = MPOL_LOCAL,
};
@@ -492,7 +492,7 @@ static struct mempolicy *mpol_new(unsigned short mode, unsigned short flags,
policy = kmem_cache_alloc(policy_cache, GFP_KERNEL);
if (!policy)
return ERR_PTR(-ENOMEM);
- atomic_set(&policy->refcnt, 1);
+ refcount_set(&policy->refcnt, 1);
policy->mode = mode;
policy->flags = flags;
policy->home_node = NUMA_NO_NODE;
@@ -503,7 +503,7 @@ static struct mempolicy *mpol_new(unsigned short mode, unsigned short flags,
/* Slow path of a mpol destructor. */
void __mpol_put(struct mempolicy *pol)
{
- if (!atomic_dec_and_test(&pol->refcnt))
+ if (!refcount_dec_and_test(&pol->refcnt))
return;
/*
* Required to allow mmap_lock_speculative*() access, see for example
@@ -2871,7 +2871,7 @@ struct mempolicy *__mpol_dup(struct mempolicy *old)
nodemask_t mems = cpuset_mems_allowed(current);
mpol_rebind_policy(new, &mems);
}
- atomic_set(&new->refcnt, 1);
+ refcount_set(&new->refcnt, 1);
return new;
}
@@ -3188,7 +3188,7 @@ static int shared_policy_replace(struct shared_policy *sp, pgoff_t start,
goto alloc_new;
*mpol_new = *n->policy;
- atomic_set(&mpol_new->refcnt, 1);
+ refcount_set(&mpol_new->refcnt, 1);
sp_node_init(n_new, end, n->end, mpol_new);
n->end = start;
sp_insert(sp, n_new);
@@ -3224,7 +3224,7 @@ static int shared_policy_replace(struct shared_policy *sp, pgoff_t start,
mpol_new = kmem_cache_alloc(policy_cache, GFP_KERNEL);
if (!mpol_new)
goto err_out;
- atomic_set(&mpol_new->refcnt, 1);
+ refcount_set(&mpol_new->refcnt, 1);
goto restart;
}
@@ -3380,7 +3380,7 @@ void __init numa_policy_init(void)
for_each_node(nid) {
preferred_node_policy[nid] = (struct mempolicy) {
- .refcnt = ATOMIC_INIT(1),
+ .refcnt = REFCOUNT_INIT(1),
.mode = MPOL_PREFERRED,
.flags = MPOL_F_MOF | MPOL_F_MORON,
.nodes = nodemask_of_node(nid),
--
2.56.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/mempolicy: convert mempolicy refcnt to refcount_t
2026-10-15 23:13 [PATCH] mm/mempolicy: convert mempolicy refcnt to refcount_t Gregory Price (Meta)
@ 2026-10-15 23:46 ` SJ Park
2026-10-16 7:54 ` David Hildenbrand (Arm)
1 sibling, 0 replies; 4+ messages in thread
From: SJ Park @ 2026-10-15 23:46 UTC (permalink / raw)
To: Gregory Price (Meta)
Cc: SJ Park, linux-mm, linux-kernel, kernel-team, akpm, david, ziy,
joshua.hahnjy, rakie.kim, ying.huang, kernel test robot
On Thu, 15 Oct 2026 19:13:22 -0400 "Gregory Price (Meta)" <gourry@gourry.net> wrote:
> struct mempolicy uses an atomic_t as a pure reference counter.
>
> Convert it to refcount_t so that overflow and underflow are caught
> by the refcount saturation checks.
>
> This silences the atomic_as_refcounter.cocci warning, which started
> matching __mpol_put() when it switched kmem_cache_free() to kfree_rcu().
>
> No functional change for correct callers.
Looks correct to me.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202610061946.Bx22ZFrw-lkp@intel.com/
> Signed-off-by: Gregory Price (Meta) <gourry@gourry.net>
Reviewed-by: SJ Park <sj@kernel.org>
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/mempolicy: convert mempolicy refcnt to refcount_t
2026-10-15 23:13 [PATCH] mm/mempolicy: convert mempolicy refcnt to refcount_t Gregory Price (Meta)
2026-10-15 23:46 ` SJ Park
@ 2026-10-16 7:54 ` David Hildenbrand (Arm)
2026-10-16 13:17 ` Gregory Price
1 sibling, 1 reply; 4+ messages in thread
From: David Hildenbrand (Arm) @ 2026-10-16 7:54 UTC (permalink / raw)
To: Gregory Price (Meta), linux-mm
Cc: linux-kernel, kernel-team, akpm, ziy, joshua.hahnjy, rakie.kim,
ying.huang, kernel test robot
On 10/16/26 01:13, Gregory Price (Meta) wrote:
> struct mempolicy uses an atomic_t as a pure reference counter.
>
> Convert it to refcount_t so that overflow and underflow are caught
> by the refcount saturation checks.
>
> This silences the atomic_as_refcounter.cocci warning, which started
> matching __mpol_put() when it switched kmem_cache_free() to kfree_rcu().
>
> No functional change for correct callers.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202610061946.Bx22ZFrw-lkp@intel.com/
> Signed-off-by: Gregory Price (Meta) <gourry@gourry.net>
> ---
Wondering if we want a Fixes? If this only fixes cocci warnings I guess not.
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/mempolicy: convert mempolicy refcnt to refcount_t
2026-10-16 7:54 ` David Hildenbrand (Arm)
@ 2026-10-16 13:17 ` Gregory Price
0 siblings, 0 replies; 4+ messages in thread
From: Gregory Price @ 2026-10-16 13:17 UTC (permalink / raw)
To: David Hildenbrand (Arm)
Cc: linux-mm, linux-kernel, kernel-team, akpm, ziy, joshua.hahnjy,
rakie.kim, ying.huang, kernel test robot
On Fri, Oct 16, 2026 at 09:54:33AM +0200, David Hildenbrand (Arm) wrote:
> On 10/16/26 01:13, Gregory Price (Meta) wrote:
> > struct mempolicy uses an atomic_t as a pure reference counter.
> >
> > Convert it to refcount_t so that overflow and underflow are caught
> > by the refcount saturation checks.
> >
> > This silences the atomic_as_refcounter.cocci warning, which started
> > matching __mpol_put() when it switched kmem_cache_free() to kfree_rcu().
> >
> > No functional change for correct callers.
> >
> > Reported-by: kernel test robot <lkp@intel.com>
> > Closes: https://lore.kernel.org/oe-kbuild-all/202610061946.Bx22ZFrw-lkp@intel.com/
> > Signed-off-by: Gregory Price (Meta) <gourry@gourry.net>
> > ---
>
> Wondering if we want a Fixes? If this only fixes cocci warnings I guess not.
>
That was my thought.
> Acked-by: David Hildenbrand (Arm) <david@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-10-16 13:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-15 23:13 [PATCH] mm/mempolicy: convert mempolicy refcnt to refcount_t Gregory Price (Meta)
2026-10-15 23:46 ` SJ Park
2026-10-16 7:54 ` David Hildenbrand (Arm)
2026-10-16 13:17 ` Gregory Price
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox