Re: [PATCH 2/3][v2] vmstat: add anon_scan_ratio field to zoneinfo

From: Minchan Kim
Date: Wed Jan 13 2010 - 05:32:00 EST


Hi, Kosaki.

On Wed, Jan 13, 2010 at 5:21 PM, KOSAKI Motohiro
<kosaki.motohiro@xxxxxxxxxxxxxx> wrote:
> Changelog
> Âfrom v1
> Â- get_anon_scan_ratio don't tak zone->lru_lock anymore
> Â because zoneinfo_show_print takes zone->lock.

When I saw this changelog first, I got confused.
That's because there is no relation between lru_lock and lock in zone.
You mean zoneinfo is allowed to have a stale data?
Tend to agree with it.

>
>
> ======================================
> Vmscan folks was asked "why does my system makes so much swap-out?"
> in lkml at several times.
> At that time, I made the debug patch to show recent_anon_{scanned/rorated}
> parameter at least three times.
>
> Thus, its parameter should be showed on /proc/zoneinfo. It help
> vmscan folks debugging.

I support this suggestion.

>
> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@xxxxxxxxxxxxxx>
> Reviewed-by: Rik van Riel <riel@xxxxxxxxxx>
> Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@xxxxxxxxxxxxxx>
> ---
> Âinclude/linux/swap.h | Â Â2 ++
> Âmm/vmscan.c     Â|  50 ++++++++++++++++++++++++++++++++++++--------------
> Âmm/vmstat.c     Â|  Â7 +++++--
> Â3 files changed, 43 insertions(+), 16 deletions(-)
>
> diff --git a/include/linux/swap.h b/include/linux/swap.h
> index a2602a8..e95d7ed 100644
> --- a/include/linux/swap.h
> +++ b/include/linux/swap.h
> @@ -280,6 +280,8 @@ extern void scan_unevictable_unregister_node(struct node *node);
> Âextern int kswapd_run(int nid);
> Âextern void kswapd_stop(int nid);
>
> +unsigned long get_anon_scan_ratio(struct zone *zone, struct mem_cgroup *memcg, int swappiness);

Today Andrew said to me. :)
"The vmscan.c code makes an effort to look nice in an 80-col display."

> +
> Â#ifdef CONFIG_MMU
> Â/* linux/mm/shmem.c */
> Âextern int shmem_unuse(swp_entry_t entry, struct page *page);
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 640486b..0900931 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -1493,8 +1493,8 @@ static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan,
> Â* percent[0] specifies how much pressure to put on ram/swap backed
> Â* memory, while percent[1] determines pressure on the file LRUs.
> Â*/
> -static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â unsigned long *percent)
> +static void __get_scan_ratio(struct zone *zone, struct scan_control *sc,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Âint need_update, unsigned long *percent)
> Â{
> Â Â Â Âunsigned long anon, file, free;
> Â Â Â Âunsigned long anon_prio, file_prio;
> @@ -1535,18 +1535,19 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
> Â Â Â Â *
> Â Â Â Â * anon in [0], file in [1]
> Â Â Â Â */
> - Â Â Â if (unlikely(reclaim_stat->recent_scanned[0] > anon / 4)) {
> - Â Â Â Â Â Â Â spin_lock_irq(&zone->lru_lock);
> - Â Â Â Â Â Â Â reclaim_stat->recent_scanned[0] /= 2;
> - Â Â Â Â Â Â Â reclaim_stat->recent_rotated[0] /= 2;
> - Â Â Â Â Â Â Â spin_unlock_irq(&zone->lru_lock);
> - Â Â Â }
> -
> - Â Â Â if (unlikely(reclaim_stat->recent_scanned[1] > file / 4)) {
> - Â Â Â Â Â Â Â spin_lock_irq(&zone->lru_lock);
> - Â Â Â Â Â Â Â reclaim_stat->recent_scanned[1] /= 2;
> - Â Â Â Â Â Â Â reclaim_stat->recent_rotated[1] /= 2;
> - Â Â Â Â Â Â Â spin_unlock_irq(&zone->lru_lock);

Why do you add new parameter 'need_update'?
Do you see any lru_lock heavy contention? (reclaim VS cat /proc/zoneinfo)
I think maybe not.
I am not sure no locking version is needed.

> + Â Â Â if (need_update) {
> + Â Â Â Â Â Â Â if (unlikely(reclaim_stat->recent_scanned[0] > anon / 4)) {
> + Â Â Â Â Â Â Â Â Â Â Â spin_lock_irq(&zone->lru_lock);
> + Â Â Â Â Â Â Â Â Â Â Â reclaim_stat->recent_scanned[0] /= 2;
> + Â Â Â Â Â Â Â Â Â Â Â reclaim_stat->recent_rotated[0] /= 2;
> + Â Â Â Â Â Â Â Â Â Â Â spin_unlock_irq(&zone->lru_lock);
> + Â Â Â Â Â Â Â }
> + Â Â Â Â Â Â Â if (unlikely(reclaim_stat->recent_scanned[1] > file / 4)) {
> + Â Â Â Â Â Â Â Â Â Â Â spin_lock_irq(&zone->lru_lock);
> + Â Â Â Â Â Â Â Â Â Â Â reclaim_stat->recent_scanned[1] /= 2;
> + Â Â Â Â Â Â Â Â Â Â Â reclaim_stat->recent_rotated[1] /= 2;
> + Â Â Â Â Â Â Â Â Â Â Â spin_unlock_irq(&zone->lru_lock);
> + Â Â Â Â Â Â Â }
> Â Â Â Â}
>
> Â Â Â Â/*
> @@ -1572,6 +1573,27 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
> Â Â Â Âpercent[1] = 100 - percent[0];
> Â}
>
> +static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
> + Â Â Â Â Â Â Â Â Â Â Â Â Âunsigned long *percent)
> +{
> + Â Â Â __get_scan_ratio(zone, sc, 1, percent);
> +}
> +

If we really need this version and your changelog is right,
Let's add 'note'. ;-)

/* Caller have to hold zone->lock */
> +unsigned long get_anon_scan_ratio(struct zone *zone, struct mem_cgroup *memcg, int swappiness)
> +{
> + Â Â Â unsigned long percent[2];
> + Â Â Â struct scan_control sc = {
> + Â Â Â Â Â Â Â .may_swap = 1,
> + Â Â Â Â Â Â Â .swappiness = swappiness,
> + Â Â Â Â Â Â Â .mem_cgroup = memcg,
> + Â Â Â };
> +
> + Â Â Â __get_scan_ratio(zone, &sc, 0, percent);
> +
> + Â Â Â return percent[0];
> +}
> +
> +
> Â/*
> Â* Smallish @nr_to_scan's are deposited in @nr_saved_scan,
> Â* until we collected @swap_cluster_max pages to scan.
> diff --git a/mm/vmstat.c b/mm/vmstat.c
> index 6051fba..f690117 100644
> --- a/mm/vmstat.c
> +++ b/mm/vmstat.c
> @@ -15,6 +15,7 @@
> Â#include <linux/cpu.h>
> Â#include <linux/vmstat.h>
> Â#include <linux/sched.h>
> +#include <linux/swap.h>
>
> Â#ifdef CONFIG_VM_EVENT_COUNTERS
> ÂDEFINE_PER_CPU(struct vm_event_state, vm_event_states) = {{0}};
> @@ -760,11 +761,13 @@ static void zoneinfo_show_print(struct seq_file *m, pg_data_t *pgdat,
> Â Â Â Â Â Â Â Â Â "\n Âall_unreclaimable: %u"
> Â Â Â Â Â Â Â Â Â "\n Âprev_priority: Â Â %i"
> Â Â Â Â Â Â Â Â Â "\n Âstart_pfn: Â Â Â Â %lu"
> - Â Â Â Â Â Â Â Â Â"\n Âinactive_ratio: Â Â%u",
> + Â Â Â Â Â Â Â Â Â"\n Âinactive_ratio: Â Â%u"
> + Â Â Â Â Â Â Â Â Â"\n Âanon_scan_ratio: Â %lu",
> Â Â Â Â Â Â Â Â Â Â Â Â Â zone_is_all_unreclaimable(zone),
> Â Â Â Â Â Â Â Â Â zone->prev_priority,
> Â Â Â Â Â Â Â Â Â zone->zone_start_pfn,
> - Â Â Â Â Â Â Â Â Âzone->inactive_ratio);
> + Â Â Â Â Â Â Â Â Âzone->inactive_ratio,
> + Â Â Â Â Â Â Â Â Âget_anon_scan_ratio(zone, NULL, vm_swappiness));
> Â Â Â Âseq_putc(m, '\n');
> Â}
>
> --
> 1.6.5.2
>
>
>
>



--
Kind regards,
Minchan Kim
--
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/