From: Qi Zheng <zhengqi.arch@bytedance.com>
The nr_pages parameter of mem_cgroup_update_lru_size() represents a page
count. During the reparenting of LRU folios, the value passed to it can
potentially exceed the maximum value of a 32-bit integer. It should be
declared as long instead of int to match the types used in lruvec size
accounting and to prevent possible overflow.
Update the parameter type to long to ensure correctness.
Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
---
include/linux/memcontrol.h | 2 +-
mm/memcontrol.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 0782c72a1997b..4a7d8c4f55b48 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -874,7 +874,7 @@ static inline bool mem_cgroup_online(struct mem_cgroup *memcg)
}
void mem_cgroup_update_lru_size(struct lruvec *lruvec, enum lru_list lru,
- int zid, int nr_pages);
+ int zid, long nr_pages);
static inline
unsigned long mem_cgroup_get_zone_lru_size(struct lruvec *lruvec,
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 51d72ddf08119..bf74167d77c5b 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1472,7 +1472,7 @@ struct lruvec *folio_lruvec_lock_irqsave(struct folio *folio,
* to or just after a page is removed from an lru list.
*/
void mem_cgroup_update_lru_size(struct lruvec *lruvec, enum lru_list lru,
- int zid, int nr_pages)
+ int zid, long nr_pages)
{
struct mem_cgroup_per_node *mz;
unsigned long *lru_size;
@@ -1489,7 +1489,7 @@ void mem_cgroup_update_lru_size(struct lruvec *lruvec, enum lru_list lru,
size = *lru_size;
if (WARN_ONCE(size < 0,
- "%s(%p, %d, %d): lru_size %ld\n",
+ "%s(%p, %d, %ld): lru_size %ld\n",
__func__, lruvec, lru, nr_pages, size)) {
VM_BUG_ON(1);
*lru_size = 0;
--
2.20.1
On Fri, Mar 27, 2026 at 06:16:30PM +0800, Qi Zheng wrote: > From: Qi Zheng <zhengqi.arch@bytedance.com> > > The nr_pages parameter of mem_cgroup_update_lru_size() represents a page > count. During the reparenting of LRU folios, the value passed to it can > potentially exceed the maximum value of a 32-bit integer. It should be > declared as long instead of int to match the types used in lruvec size > accounting and to prevent possible overflow. > > Update the parameter type to long to ensure correctness. > > Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com> > --- Looks good to me, Reviewed-by: Harry Yoo (Oracle) <harry@kernel.org> -- Cheers, Harry / Hyeonggon
On 27 Mar 2026, at 6:16, Qi Zheng wrote: > From: Qi Zheng <zhengqi.arch@bytedance.com> > > The nr_pages parameter of mem_cgroup_update_lru_size() represents a page > count. During the reparenting of LRU folios, the value passed to it can > potentially exceed the maximum value of a 32-bit integer. It should be > declared as long instead of int to match the types used in lruvec size > accounting and to prevent possible overflow. > > Update the parameter type to long to ensure correctness. > > Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com> > --- > include/linux/memcontrol.h | 2 +- > mm/memcontrol.c | 4 ++-- > 2 files changed, 3 insertions(+), 3 deletions(-) > Acked-by: Zi Yan <ziy@nvidia.com> Best Regards, Yan, Zi
On Fri, Mar 27, 2026 at 06:16:30PM +0800, Qi Zheng wrote:
> From: Qi Zheng <zhengqi.arch@bytedance.com>
>
> The nr_pages parameter of mem_cgroup_update_lru_size() represents a page
> count. During the reparenting of LRU folios, the value passed to it can
> potentially exceed the maximum value of a 32-bit integer. It should be
> declared as long instead of int to match the types used in lruvec size
> accounting and to prevent possible overflow.
>
> Update the parameter type to long to ensure correctness.
>
> Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
LGTM so:
Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
> ---
> include/linux/memcontrol.h | 2 +-
> mm/memcontrol.c | 4 ++--
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index 0782c72a1997b..4a7d8c4f55b48 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -874,7 +874,7 @@ static inline bool mem_cgroup_online(struct mem_cgroup *memcg)
> }
>
> void mem_cgroup_update_lru_size(struct lruvec *lruvec, enum lru_list lru,
> - int zid, int nr_pages);
> + int zid, long nr_pages);
>
> static inline
> unsigned long mem_cgroup_get_zone_lru_size(struct lruvec *lruvec,
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 51d72ddf08119..bf74167d77c5b 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -1472,7 +1472,7 @@ struct lruvec *folio_lruvec_lock_irqsave(struct folio *folio,
> * to or just after a page is removed from an lru list.
> */
> void mem_cgroup_update_lru_size(struct lruvec *lruvec, enum lru_list lru,
> - int zid, int nr_pages)
> + int zid, long nr_pages)
> {
> struct mem_cgroup_per_node *mz;
> unsigned long *lru_size;
> @@ -1489,7 +1489,7 @@ void mem_cgroup_update_lru_size(struct lruvec *lruvec, enum lru_list lru,
>
> size = *lru_size;
> if (WARN_ONCE(size < 0,
> - "%s(%p, %d, %d): lru_size %ld\n",
> + "%s(%p, %d, %ld): lru_size %ld\n",
> __func__, lruvec, lru, nr_pages, size)) {
> VM_BUG_ON(1);
> *lru_size = 0;
> --
> 2.20.1
>
© 2016 - 2026 Red Hat, Inc.