Skip to content

Commit

Permalink
mm/memcontrol:rewrite mem_cgroup_page_lruvec()
Browse files Browse the repository at this point in the history
mem_cgroup_page_lruvec() in memcontrol.c and mem_cgroup_lruvec() in
memcontrol.h is very similar except for the param(page and memcg) which
also can be convert to each other.

So rewrite mem_cgroup_page_lruvec() with mem_cgroup_lruvec().

[[email protected]: add missed warning in mem_cgroup_lruvec]
  Link: https://lkml.kernel.org/r/[email protected]
[[email protected]: warn on missing memcg on mem_cgroup_page_lruvec()]
  Link: https://lkml.kernel.org/r/[email protected]

Link: https://lkml.kernel.org/r/20201108143731.GA74138@rlk
Signed-off-by: Hui Su <[email protected]>
Signed-off-by: Alex Shi <[email protected]>
Signed-off-by: Lorenzo Stoakes <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Acked-by: Johannes Weiner <[email protected]>
Reviewed-by: Shakeel Butt <[email protected]>
Acked-by: Roman Gushchin <[email protected]>
Cc: Vladimir Davydov <[email protected]>
Cc: Yafang Shao <[email protected]>
Cc: Chris Down <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
liulangrenaaa authored and torvalds committed Dec 19, 2020
1 parent 93bb59c commit 9a1ac22
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 39 deletions.
19 changes: 17 additions & 2 deletions include/linux/memcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,10 @@ mem_cgroup_nodeinfo(struct mem_cgroup *memcg, int nid)
/**
* mem_cgroup_lruvec - get the lru list vector for a memcg & node
* @memcg: memcg of the wanted lruvec
* @pgdat: pglist_data
*
* Returns the lru list vector holding pages for a given @memcg &
* @node combination. This can be the node lruvec, if the memory
* @pgdat combination. This can be the node lruvec, if the memory
* controller is disabled.
*/
static inline struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg,
Expand Down Expand Up @@ -652,7 +653,21 @@ static inline struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg,
return lruvec;
}

struct lruvec *mem_cgroup_page_lruvec(struct page *, struct pglist_data *);
/**
* mem_cgroup_page_lruvec - return lruvec for isolating/putting an LRU page
* @page: the page
* @pgdat: pgdat of the page
*
* This function relies on page->mem_cgroup being stable.
*/
static inline struct lruvec *mem_cgroup_page_lruvec(struct page *page,
struct pglist_data *pgdat)
{
struct mem_cgroup *memcg = page_memcg(page);

VM_WARN_ON_ONCE_PAGE(!memcg, page);
return mem_cgroup_lruvec(memcg, pgdat);
}

static inline bool lruvec_holds_page_lru_lock(struct page *page,
struct lruvec *lruvec)
Expand Down
37 changes: 0 additions & 37 deletions mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1342,43 +1342,6 @@ void lruvec_memcg_debug(struct lruvec *lruvec, struct page *page)
}
#endif

/**
* mem_cgroup_page_lruvec - return lruvec for isolating/putting an LRU page
* @page: the page
* @pgdat: pgdat of the page
*
* This function relies on page's memcg being stable - see the
* access rules in commit_charge().
*/
struct lruvec *mem_cgroup_page_lruvec(struct page *page, struct pglist_data *pgdat)
{
struct mem_cgroup_per_node *mz;
struct mem_cgroup *memcg;
struct lruvec *lruvec;

if (mem_cgroup_disabled()) {
lruvec = &pgdat->__lruvec;
goto out;
}

memcg = page_memcg(page);
VM_WARN_ON_ONCE_PAGE(!memcg, page);
if (!memcg)
memcg = root_mem_cgroup;

mz = mem_cgroup_page_nodeinfo(memcg, page);
lruvec = &mz->lruvec;
out:
/*
* Since a node can be onlined after the mem_cgroup was created,
* we have to be prepared to initialize lruvec->zone here;
* and if offlined then reonlined, we need to reinitialize it.
*/
if (unlikely(lruvec->pgdat != pgdat))
lruvec->pgdat = pgdat;
return lruvec;
}

/**
* lock_page_lruvec - lock and return lruvec for a given page.
* @page: the page
Expand Down

0 comments on commit 9a1ac22

Please sign in to comment.