memcg: break the zone->lru_lock in memcg-aware reclaim.
Subsystems (4)
RFC PATCH 1/1 memcg: break the zone->lru_lock in memcg-aware reclaim.
This patch is based on mmotm-2011-05-12-15-52 plus Johannes patchset "[patch 0/8] mm: memcg naturalization -rc2".
This patch is only in RFC stage and i have things listed in the TODO. For now, I would like to collect early feedbacks of the direction, and more comments are welcomed.
Now with all the efforts of memcg reclaim, we are going to have better targetting per-memcg reclaim both under global memory pressure and per-memcg memory pressure. The patch fixes the last piece which making the lru_lock to be exclusive across memcgs.
The reasons we have the zone->lru_lock shared due to the following:
1. each page is linked both in per-memcg lru as well as per-zone lru due to the lack of targetting reclaim under global memory pressure.
2. since we have 1), it is easier to maintain and less race conditions to have the zone->lru_lock shared vs per-memcg lock.
After Johannes patchset, there will be no global lru list when memcg is enabled. All the pages are in exclusive per-memcg lru. So it makes senses to make the spinlock exclusive which could be easily causing bad lock contention with lots of memcgs each running memory intensive workload. The zone->lru_lock is still being used if memcg is not enabled and there shouldn't be any change in that condition.
TODO:
1. move the spinlock lru_lock from mem_cgroup_per_zone struct to lruvec. the later one is introduced by Johannes patch which I think fits the lock much better.
2. add the changes in the CONFIG_TRANSPARENT_HUGEPAGE and CONFIG_COMPACTION. in my testing kernel, i don't have those configs enabled.
3. i have test triggers BUG() in __isolate_lru_page() sometimes. looking into that next.
Test: I created a testcase which is intended to show the zone->lru_lock contention before vs after the patch. On my 8-core machine, i created 8 memcgs and each is doing a read from a ramdisk file. The filesize is larger than the hard_limit which triggers the per-memcg direct reclaim. Here I am using ramdisk to avoid the run-to-run noise from the hard drive which in turn exaggerate the contention.
1. results from the lock_stat shows the zone->lru_lock contention went down. without the patch:
--------------------------------------------------------------------------------------------------------------------------------------------
class name con-bounces contentions waittime-min waittime-max waittime-total acq-bounces acquisitions holdtime-min holdtime-max holdtime-total
&(&zone->lru_lock)->rlock: 4872501 4882517 0.23 106.26 42040610.52 29395780 35129035 0.00 69.07 125609975.67
With the patch:
--------------------------------------------------------------------------------------------------------------------------------------------
class name con-bounces contentions waittime-min waittime-max waittime-total acq-bounces acquisitions holdtime-min holdtime-max holdtime-total
&(&zone->lock)->rlock: 6713 6714 0.27 32.87 14452.22 184249 400523 0.00 994.81 898119.61
2. meanwhile, i measured the "time" on one of the memcgs and compared the "real". I would assume with bad lock contention, the real time might go up due to frequent cpu load balancing. With those runs, i disabled the CONFIG_LOCK_STAT. However, i don't see big difference on the two runs. It implies either the test is not the right indicator or something else outside that I missed.
$ ../ministat real_lock real_nolock
x real_lock
+ real_nolock
--------------------------------------------------------------------------------------------------------------------------------------------
N Min Max Median Avg Stddev
x 10 374.765 387.513 380.896 381.549 4.1587153
+ 11 369.487 382.836 378.288 377.63245 4.6018663
No difference proven at 95.0% confidence--- include/linux/memcontrol.h | 17 +++++++++ mm/memcontrol.c | 59 ++++++++++++++++++++++++++---- mm/swap.c | 69 ++++++++++++++++++++--------------- mm/vmscan.c | 86 ++++++++++++++++++++++++++++++-------------- 4 files changed, 167 insertions(+), 64 deletions(-)
include/linux/memcontrol.h +17 -0
@@ -80,6 +80,9 @@ int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem);extern struct mem_cgroup *try_get_mem_cgroup_from_page (struct page *page);extern struct mem_cgroup *mem_cgroup_from_task (struct task_struct *p); +spinlock_t *page_lru_lock (struct page *page); +spinlock_t *mem_cgroup_lru_lock (struct mem_cgroup *mem,struct zone *zone); +static inline int mm_match_cgroup (const struct mm_struct *mm,const struct mem_cgroup *cgroup) {
@@ -378,6 +381,20 @@ static inlinevoid mem_cgroup_count_vm_event (struct mm_struct *mm,enum vm_event_item idx) { } + +static inline spinlock_t *page_lru_lock (struct page *page) +{ +struct zone *zone; + + zone =page_zone (page); +return &zone->lru_lock; +} + +static inline spinlock_t * +mem_cgroup_lru_lock (struct mem_cgroup *mem,struct zone *zone) +{ +return &zone->lru_lock; +}#endif /* CONFIG_CGROUP_MEM_CONT */ #if !defined(CONFIG_CGROUP_MEM_RES_CTLR ) || !defined(CONFIG_DEBUG_VM )
mm/memcontrol.c +51 -8
123 lines not on this page · raw message
mm/swap.c +40 -29
153 lines not on this page · raw message
mm/vmscan.c +59 -27
269 lines not on this page · raw message
Signature · 8 lines
1.7.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>