Skip to content

Commit

Permalink
vmscan: force scan offline memory cgroups
Browse files Browse the repository at this point in the history
Since commit b205256 ("mm: memcontrol: continue cache reclaim from
offlined groups") pages charged to a memory cgroup are not reparented when
the cgroup is removed.  Instead, they are supposed to be reclaimed in a
regular way, along with pages accounted to online memory cgroups.

However, an lruvec of an offline memory cgroup will sooner or later get so
small that it will be scanned only at low scan priorities (see
get_scan_count()).  Therefore, if there are enough reclaimable pages in
big lruvecs, pages accounted to offline memory cgroups will never be
scanned at all, wasting memory.

Fix this by unconditionally forcing scanning dead lruvecs from kswapd.

[[email protected]: fix build]
Signed-off-by: Vladimir Davydov <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Acked-by: Johannes Weiner <[email protected]>
Cc: Tejun Heo <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Vladimir Davydov authored and torvalds committed Feb 12, 2015
1 parent 81422f2 commit 90cbc25
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
6 changes: 6 additions & 0 deletions include/linux/memcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ void mem_cgroup_iter_break(struct mem_cgroup *, struct mem_cgroup *);
* For memory reclaim.
*/
int mem_cgroup_inactive_anon_is_low(struct lruvec *lruvec);
bool mem_cgroup_lruvec_online(struct lruvec *lruvec);
int mem_cgroup_select_victim_node(struct mem_cgroup *memcg);
unsigned long mem_cgroup_get_lru_size(struct lruvec *lruvec, enum lru_list);
void mem_cgroup_update_lru_size(struct lruvec *, enum lru_list, int);
Expand Down Expand Up @@ -266,6 +267,11 @@ mem_cgroup_inactive_anon_is_low(struct lruvec *lruvec)
return 1;
}

static inline bool mem_cgroup_lruvec_online(struct lruvec *lruvec)
{
return true;
}

static inline unsigned long
mem_cgroup_get_lru_size(struct lruvec *lruvec, enum lru_list lru)
{
Expand Down
14 changes: 14 additions & 0 deletions mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,20 @@ int mem_cgroup_inactive_anon_is_low(struct lruvec *lruvec)
return inactive * inactive_ratio < active;
}

bool mem_cgroup_lruvec_online(struct lruvec *lruvec)
{
struct mem_cgroup_per_zone *mz;
struct mem_cgroup *memcg;

if (mem_cgroup_disabled())
return true;

mz = container_of(lruvec, struct mem_cgroup_per_zone, lruvec);
memcg = mz->memcg;

return !!(memcg->css.flags & CSS_ONLINE);
}

#define mem_cgroup_from_counter(counter, member) \
container_of(counter, struct mem_cgroup, member)

Expand Down
8 changes: 6 additions & 2 deletions mm/vmscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1903,8 +1903,12 @@ static void get_scan_count(struct lruvec *lruvec, int swappiness,
* latencies, so it's better to scan a minimum amount there as
* well.
*/
if (current_is_kswapd() && !zone_reclaimable(zone))
force_scan = true;
if (current_is_kswapd()) {
if (!zone_reclaimable(zone))
force_scan = true;
if (!mem_cgroup_lruvec_online(lruvec))
force_scan = true;
}
if (!global_reclaim(sc))
force_scan = true;

Expand Down

0 comments on commit 90cbc25

Please sign in to comment.