Re: [PATCH] mm: vmscan: handle isolated pages with lru lock released

From: Hillf Danton
Date: Thu Feb 16 2012 - 08:01:42 EST


On Fri, Feb 3, 2012 at 9:40 AM, Hugh Dickins <hughd@xxxxxxxxxx> wrote:
> From: Hillf Danton <dhillf@xxxxxxxxx>
>
> When shrinking inactive lru list, isolated pages are queued on locally private
> list, so the lock-hold time could be reduced if pages are counted without lock
> protection.
>
> To achieve that, firstly updating reclaim stat is delayed until the
> putback stage, after reacquiring the lru lock.
>
> Secondly, operations related to vm and zone stats are now proteced with
> preemption disabled as they are per-cpu operations.
>
> Signed-off-by: Hillf Danton <dhillf@xxxxxxxxx>
> Acked-by: Hugh Dickins <hughd@xxxxxxxxxx>
> Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@xxxxxxxxxxxxxx>
> ---
> KAMEZAWA-san and I both admired this patch from Hillf; Rik and David
> liked its precursor: I think we'd all be glad to see it in linux-next.
>
> Âmm/vmscan.c | Â 21 ++++++++++-----------
> Â1 file changed, 10 insertions(+), 11 deletions(-)
>
> --- a/mm/vmscan.c    Sat Jan 14 14:02:20 2012
> +++ b/mm/vmscan.c    Sat Jan 14 20:00:46 2012
> @@ -1414,7 +1414,6 @@ update_isolated_counts(struct mem_cgroup
> Â Â Â Â Â Â Â Â Â Â Â unsigned long *nr_anon,
> Â Â Â Â Â Â Â Â Â Â Â unsigned long *nr_file)
> Â{
> - Â Â Â struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(mz);
> Â Â Â Âstruct zone *zone = mz->zone;
> Â Â Â Âunsigned int count[NR_LRU_LISTS] = { 0, };
> Â Â Â Âunsigned long nr_active = 0;
> @@ -1435,6 +1434,7 @@ update_isolated_counts(struct mem_cgroup
> Â Â Â Â Â Â Â Âcount[lru] += numpages;
> Â Â Â Â}
>
> + Â Â Â preempt_disable();
> Â Â Â Â__count_vm_events(PGDEACTIVATE, nr_active);
>
> Â Â Â Â__mod_zone_page_state(zone, NR_ACTIVE_FILE,
> @@ -1449,8 +1449,9 @@ update_isolated_counts(struct mem_cgroup
> Â Â Â Â*nr_anon = count[LRU_ACTIVE_ANON] + count[LRU_INACTIVE_ANON];
> Â Â Â Â*nr_file = count[LRU_ACTIVE_FILE] + count[LRU_INACTIVE_FILE];
>
> - Â Â Â reclaim_stat->recent_scanned[0] += *nr_anon;
> - Â Â Â reclaim_stat->recent_scanned[1] += *nr_file;
> + Â Â Â __mod_zone_page_state(zone, NR_ISOLATED_ANON, *nr_anon);
> + Â Â Â __mod_zone_page_state(zone, NR_ISOLATED_FILE, *nr_file);
> + Â Â Â preempt_enable();
> Â}
>
> Â/*
> @@ -1512,6 +1513,7 @@ shrink_inactive_list(unsigned long nr_to
> Â Â Â Âunsigned long nr_writeback = 0;
> Â Â Â Âisolate_mode_t reclaim_mode = ISOLATE_INACTIVE;
> Â Â Â Âstruct zone *zone = mz->zone;
> + Â Â Â struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(mz);
>
> Â Â Â Âwhile (unlikely(too_many_isolated(zone, file, sc))) {
> Â Â Â Â Â Â Â Âcongestion_wait(BLK_RW_ASYNC, HZ/10);
> @@ -1546,19 +1548,13 @@ shrink_inactive_list(unsigned long nr_to
> Â Â Â Â Â Â Â Â Â Â Â Â__count_zone_vm_events(PGSCAN_DIRECT, zone,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â nr_scanned);
> Â Â Â Â}
> + Â Â Â spin_unlock_irq(&zone->lru_lock);
>
> - Â Â Â if (nr_taken == 0) {
> - Â Â Â Â Â Â Â spin_unlock_irq(&zone->lru_lock);
> + Â Â Â if (nr_taken == 0)
> Â Â Â Â Â Â Â Âreturn 0;
> - Â Â Â }
>
> Â Â Â Âupdate_isolated_counts(mz, &page_list, &nr_anon, &nr_file);
>
> - Â Â Â __mod_zone_page_state(zone, NR_ISOLATED_ANON, nr_anon);
> - Â Â Â __mod_zone_page_state(zone, NR_ISOLATED_FILE, nr_file);
> -
> - Â Â Â spin_unlock_irq(&zone->lru_lock);
> -
> Â Â Â Ânr_reclaimed = shrink_page_list(&page_list, mz, sc, priority,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â&nr_dirty, &nr_writeback);
>
> @@ -1570,6 +1566,9 @@ shrink_inactive_list(unsigned long nr_to
> Â Â Â Â}
>
> Â Â Â Âspin_lock_irq(&zone->lru_lock);
> +
> + Â Â Â reclaim_stat->recent_scanned[0] += nr_anon;
> + Â Â Â reclaim_stat->recent_scanned[1] += nr_file;
>
> Â Â Â Âif (current_is_kswapd())
> Â Â Â Â Â Â Â Â__count_vm_events(KSWAPD_STEAL, nr_reclaimed);

Hi Andrew

Please consider adding this patch to -mm tree.

Thanks
Hillf
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/