mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-08-27 06:50:37 +00:00

Commit6769183166
removed the parameter of id from swap_cgroup_record() and get the memcg id from mem_cgroup_id(folio_memcg(folio)). However, the caller of it may update a different memcg's counter instead of folio_memcg(folio). E.g. in the caller of mem_cgroup_swapout(), @swap_memcg could be different with @memcg and update the counter of @swap_memcg, but swap_cgroup_record() records the wrong memcg's ID. When it is uncharged from __mem_cgroup_uncharge_swap(), the swap counter will leak since the wrong recorded ID. Fix it by bringing the parameter of id back. Link: https://lkml.kernel.org/r/20250306023133.44838-1-songmuchun@bytedance.com Fixes:6769183166
("mm/swap_cgroup: decouple swap cgroup recording and clearing") Signed-off-by: Muchun Song <songmuchun@bytedance.com> Reviewed-by: Kairui Song <kasong@tencent.com> Cc: Chris Li <chrisl@kernel.org> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@kernel.org> Cc: Roman Gushchin <roman.gushchin@linux.dev> Cc: Shakeel Butt <shakeel.butt@linux.dev> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
48 lines
1004 B
C
48 lines
1004 B
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __LINUX_SWAP_CGROUP_H
|
|
#define __LINUX_SWAP_CGROUP_H
|
|
|
|
#include <linux/swap.h>
|
|
|
|
#if defined(CONFIG_MEMCG) && defined(CONFIG_SWAP)
|
|
|
|
extern void swap_cgroup_record(struct folio *folio, unsigned short id, swp_entry_t ent);
|
|
extern unsigned short swap_cgroup_clear(swp_entry_t ent, unsigned int nr_ents);
|
|
extern unsigned short lookup_swap_cgroup_id(swp_entry_t ent);
|
|
extern int swap_cgroup_swapon(int type, unsigned long max_pages);
|
|
extern void swap_cgroup_swapoff(int type);
|
|
|
|
#else
|
|
|
|
static inline
|
|
void swap_cgroup_record(struct folio *folio, unsigned short id, swp_entry_t ent)
|
|
{
|
|
}
|
|
|
|
static inline
|
|
unsigned short swap_cgroup_clear(swp_entry_t ent, unsigned int nr_ents)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline
|
|
unsigned short lookup_swap_cgroup_id(swp_entry_t ent)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline int
|
|
swap_cgroup_swapon(int type, unsigned long max_pages)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline void swap_cgroup_swapoff(int type)
|
|
{
|
|
return;
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* __LINUX_SWAP_CGROUP_H */
|