mm: lru milestones, timestamps and ages
Subsystems (5)
RFC PATCH 1/1 mm: lru milestones, timestamps and ages
This patch adds engine for estimating rotation time for pages in lru lists.
This adds bunch of 'milestones' into each struct lruvec and inserts them into lru lists periodically. Milestone flows in lru together with pages and brings timestamp to the end of lru. Because milestones are embedded into lruvec they can be easily distinguished from pages by comparing pointers. Only few functions should care about that.
This machinery provides discrete-time estimation for age of pages from the end of each lru and average age of each kind of evictable lrus in each zone.
Numbers are shown in '/proc/zoneinfo' and in memcg attribute 'memory.stat'.
Overhead on fast-path is nearly zero: is_lru_milestone() in isolate_lru_pages() distinguishes milestones and pages without touching any extra cache-lines. Memory overhead is more noticeable: 1.5k for 16 milestones per struct lruvec. Struct mem_cgroup_per_node now requires order-1 page on 64-bit system with 4 zones per node.
In our kernel we use similar engine as source of statistics for scheduler in memory reclaimer. This is O(1) scheduler which shifts vmscan priorities for lru vectors depending on their sizes, limits and ages. It tries to balance memory pressure among containers. I'll try to rework it for the mainline kernel soon.
Seems like these ages also can be used for optimal memory pressure distribution between file and anon pages, and probably for balancing pressure among zones. Moreover slab shrinkers also can provide similar time-based statistics, some of them may embed timestamps directly into their objects.
--- include/linux/mmzone.h | 26 ++++++++++ mm/memcontrol.c | 32 ++++++++++++ mm/mmzone.c | 10 ++++ mm/vmscan.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++++ mm/vmstat.c | 9 +++ 5 files changed, 203 insertions(+)
include/linux/mmzone.h +26 -0
@@ -7,6 +7,7 @@#include <linux/spinlock.h> #include <linux/list.h> #include <linux/wait.h> +#include <linux/workqueue.h> #include <linux/bitops.h> #include <linux/cache.h> #include <linux/threads.h>
@@ -164,6 +165,7 @@ enum lru_list {LRU_INACTIVE_FILE =LRU_BASE +LRU_FILE ,LRU_ACTIVE_FILE =LRU_BASE +LRU_FILE +LRU_ACTIVE ,LRU_UNEVICTABLE , +NR_EVICTABLE_LRU_LISTS =LRU_UNEVICTABLE , NR_LRU_LISTS };
@@ -199,14 +201,35 @@ struct zone_reclaim_stat {unsigned long recent_scanned[2 ]; }; +struct lru_milestone { +unsigned long timestamp; +struct list_head lru; +}; + +#define NR_LRU_MILESTONES 16 +struct lruvec {struct list_head lists[NR_LRU_LISTS ];struct zone_reclaim_stat reclaim_stat;#ifdef CONFIG_MEMCG struct zone *zone;#endif +unsigned long age[NR_EVICTABLE_LRU_LISTS ]; +unsigned long next_timestamp[NR_EVICTABLE_LRU_LISTS ]; +unsigned char last_milestone[NR_EVICTABLE_LRU_LISTS ]; +struct lru_milestone milestones[NR_EVICTABLE_LRU_LISTS ][NR_LRU_MILESTONES ]; }; +static inline bool +is_lru_milestone (struct lruvec *lruvec,struct list_head *list) +{ +return unlikely (list >= &lruvec->milestones[0 ][0 ].lru && + list < &lruvec->milestones[NR_EVICTABLE_LRU_LISTS ] + [NR_LRU_MILESTONES ].lru); +} + +void remove_lru_milestone (struct lruvec *lruvec,enum lru_list lru); +/* Mask used at gathering information at once (see memcontrol.c) */ #define LRU_ALL_FILE (BIT(LRU_INACTIVE_FILE) | BIT(LRU_ACTIVE_FILE))#define LRU_ALL_ANON (BIT(LRU_INACTIVE_ANON) | BIT(LRU_ACTIVE_ANON))
@@ -487,6 +510,9 @@ struct zone {* rarely used fields: */ const char *name; + +struct delayed_work milestones_work; +unsigned long average_age[NR_EVICTABLE_LRU_LISTS ]; }____cacheline_internodealigned_in_smp ; typedef enum {
mm/memcontrol.c +32 -0
@@ -967,6 +967,27 @@ static unsigned long mem_cgroup_nr_lru_pages(struct mem_cgroup *memcg,return total; } +static unsigned mem_cgroup_avg_age (struct mem_cgroup *memcg,enum lru_list lru) +{ +struct mem_cgroup_per_zone *mz; +unsigned long size =0 , pages; +int nid, zid; +u64 age =0 ; + +for_each_node_state (nid,N_MEMORY ) { +for (zid =0 ; zid <MAX_NR_ZONES ; zid++) { + mz =mem_cgroup_zoneinfo (memcg, nid, zid); + pages = mz->lru_size[lru]; + size += pages; + age += (u64 )pages * mz->lruvec.age[lru]; + } + } + +if (size) +do_div (age, size); +return jiffies_to_msecs (age); +} +static bool mem_cgroup_event_ratelimit (struct mem_cgroup *memcg,enum mem_cgroup_events_target target) {
@@ -4707,6 +4728,11 @@ static void mem_cgroup_force_empty_list(struct mem_cgroup *memcg,break ; } page = list_entry(list->prev, struct page, lru); +if (is_lru_milestone (lruvec, &page->lru)) { +remove_lru_milestone (lruvec, lru); +spin_unlock_irqrestore (&zone->lru_lock, flags); +continue ; + }if (busy == page) {list_move (&page->lru, list); busy =NULL ;
@@ -5298,6 +5324,10 @@ static int memcg_stat_show(struct cgroup *cont, struct cftype *cft,seq_printf (m,"%s %lu\n" , mem_cgroup_lru_names[i],mem_cgroup_nr_lru_pages (memcg,BIT (i)) *PAGE_SIZE ); +for (i =0 ; i <NR_EVICTABLE_LRU_LISTS ; i++) +seq_printf (m,"avg_age_%s %u\n" , mem_cgroup_lru_names[i], +mem_cgroup_avg_age (memcg, i)); +/* Hierarchical information */ {unsigned long long limit, memsw_limit;
@@ -5923,6 +5953,8 @@ static int alloc_mem_cgroup_per_zone_info(struct mem_cgroup *memcg, int node)*/ if (!node_state (node,N_NORMAL_MEMORY )) tmp =-1 ; +/* Try to decrease NR_LRU_MILESTONES if this happens */ +BUILD_BUG_ON (sizeof (struct mem_cgroup_per_node ) >2 *PAGE_SIZE ); pn =kzalloc_node (sizeof (*pn),GFP_KERNEL , tmp);if (!pn)return 1 ;
mm/mmzone.c +10 -0
@@ -89,12 +89,22 @@ int memmap_valid_within(unsigned long pfn,void lruvec_init (struct lruvec *lruvec) { +unsigned long now = jiffies;enum lru_list lru; +int i;memset (lruvec,0 ,sizeof (struct lruvec ));for_each_lru (lru)INIT_LIST_HEAD (&lruvec->lists[lru]); + +for_each_evictable_lru (lru) { +for (i =0 ; i <NR_LRU_MILESTONES ; i++) { +INIT_LIST_HEAD (&lruvec->milestones[lru][i].lru); + lruvec->milestones[lru][i].timestamp = now; + } + lruvec->next_timestamp[lru] = now; + } }#if defined(CONFIG_NUMA_BALANCING ) && !defined(LAST_NID_NOT_IN_PAGE_FLAGS )
mm/vmscan.c +126 -0
156 lines not on this page · raw message
mm/vmstat.c +9 -0
@@ -1053,6 +1053,15 @@ static void zoneinfo_show_print(struct seq_file *m, pg_data_t *pgdat, zone->all_unreclaimable, zone->zone_start_pfn, zone->inactive_ratio); +seq_printf (m, +"\n avg_age_inactive_anon: %u" +"\n avg_age_active_anon: %u" +"\n avg_age_inactive_file: %u" +"\n avg_age_active_file: %u" , +jiffies_to_msecs (zone->average_age[LRU_INACTIVE_ANON ]), +jiffies_to_msecs (zone->average_age[LRU_ACTIVE_ANON ]), +jiffies_to_msecs (zone->average_age[LRU_INACTIVE_FILE ]), +jiffies_to_msecs (zone->average_age[LRU_ACTIVE_FILE ]));seq_putc (m,'\n' ); }
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 10 lines · Konstantin Khlebnikov
This patch adds engine for estimating rotation time for pages in lru lists.
This adds bunch of 'milestones' into each struct lruvec and inserts them into lru lists periodically. Milestone flows in lru together with pages and brings timestamp to the end of lru. Because milestones are embedded into lruvec they can be easily distinguished from pages by comparing pointers. Only few functions should care about that.
This machinery provides discrete-time estimation for age of pages from the end of each lru and average age of each kind of evictable lrus in each zone.
Great stuff!
Believe it or not, I had an idea of writing something similar to this, but of course having an idea and actually implementing it are two very different things. Thank you for your work!
I will use this to prove (or not) that file pages in the normal zone on a 4GB RAM machine are reused waaaay too soon. Actually, I already have the patch applied and running on the desktop, but it should be much more useful on server workloads. Desktops have erratic load and can go for a long time with very little I/O activity. But, here are the current numbers anyway:
Node 0, zone DMA32
pages free 5371
nr_inactive_anon 4257
nr_active_anon 139719
nr_inactive_file 617537
nr_active_file 51671 inactive_ratio: 5
avg_age_inactive_anon: 2514752
avg_age_active_anon: 2514752
avg_age_inactive_file: 876416
avg_age_active_file: 2514752
Node 0, zone Normal
pages free 424
nr_inactive_anon 253
nr_active_anon 54480
nr_inactive_file 63274
nr_active_file 44116 inactive_ratio: 1
avg_age_inactive_anon: 2531712
avg_age_active_anon: 2531712
avg_age_inactive_file: 901120
avg_age_active_file: 2531712
Quoted 7 lines
In our kernel we use similar engine as source of statistics for scheduler in memory reclaimer. This is O(1) scheduler which shifts vmscan priorities for lru vectors depending on their sizes, limits and ages. It tries to balance memory pressure among containers. I'll try to rework it for the mainline kernel soon.
Seems like these ages also can be used for optimal memory pressure distribution between file and anon pages, and probably for balancing pressure among zones.
This all sounds very promising. Especially because I currently observe quite some imbalance among zones.
Regards,
Signature · 7 lines
Zlatko -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 9 lines · Zlatko Calusic
Quoted 8 lines · Konstantin Khlebnikov
This patch adds engine for estimating rotation time for pages in lru lists.
This adds bunch of 'milestones' into each struct lruvec and inserts them into lru lists periodically. Milestone flows in lru together with pages and brings timestamp to the end of lru. Because milestones are embedded into lruvec they can be easily distinguished from pages by comparing pointers. Only few functions should care about that.
Quoted 4 lines
Quoted 2 lines
This machinery provides discrete-time estimation for age of pages from the end of each lru and average age of each kind of evictable lrus in each zone.
Great stuff!
Thanks!
Quoted 33 lines
Believe it or not, I had an idea of writing something similar to this, but of course having an idea and actually implementing it are two very different things. Thank you for your work!
I will use this to prove (or not) that file pages in the normal zone on a 4GB RAM machine are reused waaaay too soon. Actually, I already have the patch applied and running on the desktop, but it should be much more useful on server workloads. Desktops have erratic load and can go for a long time with very little I/O activity. But, here are the current numbers anyway:
Node 0, zone DMA32
pages free 5371nr_inactive_anon4257nr_active_anon139719nr_inactive_file617537nr_active_file51671inactive_ratio: 5avg_age_inactive_anon: 2514752avg_age_active_anon: 2514752avg_age_inactive_file: 876416avg_age_active_file: 2514752
Node 0, zone Normal
pages free 424nr_inactive_anon253nr_active_anon54480nr_inactive_file63274nr_active_file44116inactive_ratio: 1avg_age_inactive_anon: 2531712avg_age_active_anon: 2531712avg_age_inactive_file: 901120avg_age_active_file: 2531712Quoted 5 lines
In our kernel we use similar engine as source of statistics for scheduler in memory reclaimer. This is O(1) scheduler which shifts vmscan priorities for lru vectors depending on their sizes, limits and ages. It tries to balance memory pressure among containers. I'll try to rework it for the mainline kernel soon.
Quoted 4 lines
Quoted 2 lines
Seems like these ages also can be used for optimal memory pressure distribution between file and anon pages, and probably for balancing pressure among zones.
This all sounds very promising. Especially because I currently observe quite some imbalance among zones.
As I see, most likely reason of such imbalances is 'break' condition inside of shrink_lruvec(). So can try to disable it see what will happen.
But these numbers from your desktop actually doesn't proves this problem. Seems like difference between zones is within the precision of this method. I don't know how to describe this precisely. Probably irregularity between milestones also should be taken into the account to describe current situation and quality of measurement.
Here current numbers from my 8Gb node. Main workload is a torrent client.
Node 0, zone DMA32
nr_inactive_anon 1
nr_active_anon 1494
nr_inactive_file 404028
nr_active_file 365525
nr_dirtied 855068
nr_written 854991 avg_age_inactive_anon: 64942528
avg_age_active_anon: 64942528
avg_age_inactive_file: 1281317
avg_age_active_file: 15813376
Node 0, zone Normal
nr_inactive_anon 376
nr_active_anon 13793
nr_inactive_file 542605
nr_active_file 542247
nr_dirtied 2746747
nr_written 2746266 avg_age_inactive_anon: 65064192
avg_age_active_anon: 65064192
avg_age_inactive_file: 1260611
avg_age_active_file: 8765240
So, here noticeable imbalance in ages of active file lru and nr_dirtied/nr_written. I have no idea why, but torrent client uses syscall fadvise() which messes whole picture.
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 92 lines · Konstantin Khlebnikov
Quoted 9 lines · Zlatko Calusic
Quoted 8 lines · Konstantin Khlebnikov
This patch adds engine for estimating rotation time for pages in lru lists.
This adds bunch of 'milestones' into each struct lruvec and inserts them into lru lists periodically. Milestone flows in lru together with pages and brings timestamp to the end of lru. Because milestones are embedded into lruvec they can be easily distinguished from pages by comparing pointers. Only few functions should care about that.
Quoted 4 lines
Quoted 2 lines
This machinery provides discrete-time estimation for age of pages from the end of each lru and average age of each kind of evictable lrus in each zone.
Great stuff!
Thanks!
Quoted 37 lines
Believe it or not, I had an idea of writing something similar to this, but of course having an idea and actually implementing it are two very different things. Thank you for your work!
I will use this to prove (or not) that file pages in the normal zone on a 4GB RAM machine are reused waaaay too soon. Actually, I already have the patch applied and running on the desktop, but it should be much more useful on server workloads. Desktops have erratic load and can go for a long time with very little I/O activity. But, here are the current numbers anyway:
Node 0, zone DMA32
pages free 5371nr_inactive_anon4257nr_active_anon139719nr_inactive_file617537nr_active_file51671inactive_ratio: 5avg_age_inactive_anon: 2514752avg_age_active_anon: 2514752avg_age_inactive_file: 876416avg_age_active_file: 2514752
Node 0, zone Normal
pages free 424nr_inactive_anon253nr_active_anon54480nr_inactive_file63274nr_active_file44116inactive_ratio: 1avg_age_inactive_anon: 2531712avg_age_active_anon: 2531712avg_age_inactive_file: 901120avg_age_active_file: 2531712Quoted 5 lines
In our kernel we use similar engine as source of statistics for scheduler in memory reclaimer. This is O(1) scheduler which shifts vmscan priorities for lru vectors depending on their sizes, limits and ages. It tries to balance memory pressure among containers. I'll try to rework it for the mainline kernel soon.
Quoted 4 lines
Quoted 2 lines
Seems like these ages also can be used for optimal memory pressure distribution between file and anon pages, and probably for balancing pressure among zones.
This all sounds very promising. Especially because I currently observe quite some imbalance among zones.
As I see, most likely reason of such imbalances is 'break' condition inside of
shrink_lruvec(). So can try to disable it see what will happen.But these numbers from your desktop actually doesn't proves this problem. Seems like difference between zones is within the precision of this method. I don't know how to describe this precisely. Probably irregularity between milestones also should be taken into the account to describe current situation and quality of measurement.
Here current numbers from my 8Gb node. Main workload is a torrent client.
Node 0, zone DMA32
nr_inactive_anon1nr_active_anon1494nr_inactive_file404028nr_active_file365525nr_dirtied855068nr_written854991avg_age_inactive_anon: 64942528avg_age_active_anon: 64942528avg_age_inactive_file: 1281317avg_age_active_file: 15813376
Node 0, zone Normalnr_inactive_anon376nr_active_anon13793nr_inactive_file542605nr_active_file542247nr_dirtied2746747nr_written2746266avg_age_inactive_anon: 65064192avg_age_active_anon: 65064192avg_age_inactive_file: 1260611avg_age_active_file: 8765240
Quoted 2 lines
So, here noticeable imbalance in ages of active file lru and nr_dirtied/nr_written. I have no idea why, but torrent client uses syscall
fadvise()which messes whole picture.
Hey! I can reproduce this:
Node 0, zone DMA32
nr_inactive_anon 1
nr_active_anon 2368
nr_inactive_file 373642
nr_active_file 375462
nr_dirtied 2887369
nr_written 2887291 inactive_ratio: 5
avg_age_inactive_anon: 64942528
avg_age_active_anon: 64942528
avg_age_inactive_file: 389824
avg_age_active_file: 1330368
Node 0, zone Normal
nr_inactive_anon 376
nr_active_anon 17768
nr_inactive_file 534695
nr_active_file 533685
nr_dirtied 12071397
nr_written 11940007 inactive_ratio: 6
avg_age_inactive_anon: 65064192
avg_age_active_anon: 65064192
avg_age_inactive_file: 28074
avg_age_active_file: 1304800
I'm just copying huge files from one disk to another by rsync.
In /proc/vmstat pgsteal_kswapd_normal and pgscan_kswapd_normal are rising rapidly, other pgscan_* pgsteal_* are standing still. So, bug is somewhere in the kswapd.
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 146 lines · Konstantin Khlebnikov
Quoted 113 lines · Konstantin Khlebnikov
Quoted 13 lines · Zlatko Calusic
Quoted 12 lines · Konstantin Khlebnikov
This patch adds engine for estimating rotation time for pages in lru lists.
This adds bunch of 'milestones' into each struct lruvec and inserts them into
lru lists periodically. Milestone flows in lru together with pages and brings
timestamp to the end of lru. Because milestones are embedded into lruvec they
can be easily distinguished from pages by comparing pointers. Only few functions should care about that.Quoted 6 lines
Quoted 4 lines
This machinery provides discrete-time estimation for age of pages from the end
of each lru and average age of each kind of evictable lrus in each zone.Great stuff!
Thanks!
Quoted 45 lines
Believe it or not, I had an idea of writing something similar to this, but of course having an idea and actually
implementing it are two very different things. Thank you for your work!I will use this to prove (or not) that file pages in the normal zone on a 4GB RAM machine are reused waaaay too soon.
Actually, I already have the patch applied and running on the desktop, but it should be much more useful on server workloads. Desktops have erratic load and can go for a long time with very little I/O activity. But, here are the
current numbers anyway:Node 0, zone DMA32
pages free 5371nr_inactive_anon4257nr_active_anon139719nr_inactive_file617537nr_active_file51671inactive_ratio: 5avg_age_inactive_anon: 2514752avg_age_active_anon: 2514752avg_age_inactive_file: 876416avg_age_active_file: 2514752
Node 0, zone Normal
pages free 424nr_inactive_anon253nr_active_anon54480nr_inactive_file63274nr_active_file44116inactive_ratio: 1avg_age_inactive_anon: 2531712avg_age_active_anon: 2531712avg_age_inactive_file: 901120avg_age_active_file: 2531712Quoted 9 lines
In our kernel we use similar engine as source of statistics for scheduler in
memory reclaimer. This is O(1) scheduler which shifts vmscan priorities for lru
vectors depending on their sizes, limits and ages. It tries to balance memory
pressure among containers. I'll try to rework it for the mainline kernel soon.Quoted 7 lines
Quoted 4 lines
Seems like these ages also can be used for optimal memory pressure distribution
between file and anon pages, and probably for balancing pressure among zones.This all sounds very promising. Especially because I currently observe quite some imbalance among zones.
As I see, most likely reason of such imbalances is 'break' condition inside of
shrink_lruvec().
So can try to disable it see what will happen.But these numbers from your desktop actually doesn't proves this problem. Seems like difference
between zones is within the precision of this method. I don't know how to describe this precisely.
Probably irregularity between milestones also should be taken into the account to describe current
situation and quality of measurement.Here current numbers from my 8Gb node. Main workload is a torrent client.
Node 0, zone DMA32
nr_inactive_anon1nr_active_anon1494nr_inactive_file404028nr_active_file365525nr_dirtied855068nr_written854991avg_age_inactive_anon: 64942528avg_age_active_anon: 64942528avg_age_inactive_file: 1281317avg_age_active_file: 15813376
Node 0, zone Normalnr_inactive_anon376nr_active_anon13793nr_inactive_file542605nr_active_file542247nr_dirtied2746747nr_written2746266avg_age_inactive_anon: 65064192avg_age_active_anon: 65064192avg_age_inactive_file: 1260611avg_age_active_file: 8765240Quoted 4 lines
So, here noticeable imbalance in ages of active file lru and nr_dirtied/nr_written.
I have no idea why, but torrent client uses syscallfadvise()which messes whole picture.Hey! I can reproduce this:
Node 0, zone DMA32
nr_inactive_anon 1 nr_active_anon 2368 nr_inactive_file 373642 nr_active_file 375462 nr_dirtied 2887369 nr_written 2887291
inactive_ratio: 5
avg_age_inactive_anon: 64942528
avg_age_active_anon: 64942528
avg_age_inactive_file: 389824
avg_age_active_file: 1330368
Node 0, zone Normalnr_inactive_anon 376 nr_active_anon 17768 nr_inactive_file 534695 nr_active_file 533685 nr_dirtied 12071397 nr_written 11940007
inactive_ratio: 6
avg_age_inactive_anon: 65064192
avg_age_active_anon: 65064192
avg_age_inactive_file: 28074
avg_age_active_file: 1304800
Quoted 7 lines
I'm just copying huge files from one disk to another by rsync.
In
/proc/vmstatpgsteal_kswapd_normalandpgscan_kswapd_normalare rising rapidly,
other pgscan_* pgsteal_* are standing still. So, bug is somewhere in the kswapd.
Not necessarily, because processes also do a direct reclaim. Also, if you continued the copying, I bet you would see that DMA32 zone also gets to play. Just a bit later.
I can now see that effect nicely on the graphs I prepared. Attached is one from the desktop. Where the red line suddenly drops, I copied 2GB file from the network to the machine. Half an hour later I copied another 1.6GB file. That's when the blue line dropped. Though, it all makes sense, about 3GB of I/O was needed to expunge all old inactive pages from both zones, the first 2GB wasn't enough to push old pages from the DMA32 zone.
I'm of the opinion that your instrumentation will be of use only when there's a constant reclaim goin' on. Otherwise pages stay in memory for a long long time, and then it doesn't matter much if it's one hour or two hours before some of them are reclaimed. For the same reason I will limit graphs like these to some useful value, so to get precision for the important time periods when the reclaim is really active.
Signature · 1 line
Zlatko
Johannes Weiner
maintainerMel: we talked about this issue below in SFO, apparently I'm not the only one who noticed :-)
Rik: a fix for the problem below is crucial for the refault distance-based page cache sizing. The unequal LRU aging is a problem in itself, but it's compounded when we use the skewed non-resident times to base reclaim decisions on
Quoted 27 lines · Konstantin Khlebnikov
Hey! I can reproduce this:
Node 0, zone DMA32
nr_inactive_anon 1 nr_active_anon 2368 nr_inactive_file 373642 nr_active_file 375462 nr_dirtied 2887369 nr_written 2887291
inactive_ratio: 5
avg_age_inactive_anon: 64942528
avg_age_active_anon: 64942528
avg_age_inactive_file: 389824
avg_age_active_file: 1330368
Node 0, zone Normalnr_inactive_anon 376 nr_active_anon 17768 nr_inactive_file 534695 nr_active_file 533685 nr_dirtied 12071397 nr_written 11940007
inactive_ratio: 6
avg_age_inactive_anon: 65064192
avg_age_active_anon: 65064192
avg_age_inactive_file: 28074
avg_age_active_file: 1304800
Quoted 4 lines
I'm just copying huge files from one disk to another by rsync.
In
/proc/vmstatpgsteal_kswapd_normalandpgscan_kswapd_normalare rising rapidly, other pgscan_* pgsteal_* are standing still. So, bug is somewhere in the kswapd.
There is a window where a steady stream of allocations and kswapd cooperate in perfect unison and keep the Normal zone always between the low and high watermarks. Kswapd does not stop until the high watermark is met, the allocator does not go to lower zones until the low watermark is breached. As a result, most allocations happen in the Normal zone.
I'm playing around with a round-robin scheme on the page allocator side to spread out file pages more evenly, but I'm torn on whether the fix should actually be on the kswapd side, to enforce reclaim instead of allocation more evenly. Thoughts?
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 71 lines · Konstantin Khlebnikov
Quoted 13 lines · Zlatko Calusic
Quoted 12 lines · Konstantin Khlebnikov
This patch adds engine for estimating rotation time for pages in lru lists.
This adds bunch of 'milestones' into each struct lruvec and inserts them into
lru lists periodically. Milestone flows in lru together with pages and brings
timestamp to the end of lru. Because milestones are embedded into lruvec they
can be easily distinguished from pages by comparing pointers. Only few functions should care about that.Quoted 5 lines
Quoted 3 lines
This machinery provides discrete-time estimation for age of pages from the end
of each lru and average age of each kind of evictable lrus in each zone.Great stuff!
Thanks!
Quoted 49 lines
Believe it or not, I had an idea of writing something similar to this, but of course having an idea and actually implementing it are two very different things. Thank you for your work!
I will use this to prove (or not) that file pages in the normal zone on a 4GB RAM machine are reused waaaay too soon. Actually, I already have the patch applied and running on the desktop, but it should be much more useful on server workloads. Desktops have erratic load and can go for a long time with very little I/O activity. But, here are the current numbers anyway:
Node 0, zone DMA32
pages free 5371nr_inactive_anon4257nr_active_anon139719nr_inactive_file617537nr_active_file51671inactive_ratio: 5avg_age_inactive_anon: 2514752avg_age_active_anon: 2514752avg_age_inactive_file: 876416avg_age_active_file: 2514752
Node 0, zone Normal
pages free 424nr_inactive_anon253nr_active_anon54480nr_inactive_file63274nr_active_file44116inactive_ratio: 1avg_age_inactive_anon: 2531712avg_age_active_anon: 2531712avg_age_inactive_file: 901120avg_age_active_file: 2531712Quoted 13 lines
In our kernel we use similar engine as source of statistics for scheduler in
memory reclaimer. This is O(1) scheduler which shifts vmscan priorities for lru
vectors depending on their sizes, limits and ages. It tries to balance memory
pressure among containers. I'll try to rework it for the mainline kernel soon.Seems like these ages also can be used for optimal memory pressure distribution
between file and anon pages, and probably for balancing pressure among zones.
Quoted 6 lines
Quoted 2 lines
This all sounds very promising. Especially because I currently observe quite some imbalance among zones.
As I see, most likely reason of such imbalances is 'break' condition inside of
shrink_lruvec().
So can try to disable it see what will happen.
Thanks for the hint. I will pay some more attention to this function next time I investigate code.
Quoted 9 lines
But these numbers from your desktop actually doesn't proves this problem. Seems like difference
between zones is within the precision of this method. I don't know how to describe this precisely.
Probably irregularity between milestones also should be taken into the account to describe current
situation and quality of measurement.
Ah, no, the numbers were more like a proof that your patch is running fine, nothing specific about them. I was just making a quick check that your patch is stable enough before I run it in production, and it seems it's working just fine.
In the next hour or so I will patch the kernel on the server where I intend to do much more analysis. I also prepared a set of graphs based on the numbers your code provides. Based on the preliminary tests, I believe that I'll be interested only in the aging of the inactive file lists. What I'm after is the bug explained here http://marc.info/?l=linux-mm&m=136571221426984 and if I'm right, your patch will help to better reveal extreme disbalance observed between dma32 and normal zone file LRU aging. But only on a 4GB nodes. I haven't seen anything similar on a 8GB nodes, where dma32 and normal zones are approximately the same sizes.
Signature · 7 lines
Zlatko -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
include/linux/mmzone.h struct zone_reclaim_stat { · line 230
Quoted 8 lines · Konstantin Khlebnikov
include/linux/mmzone.h +8
-0+static inline bool +is_lru_milestone (struct lruvec *lruvec,struct list_head *list) +{ +return unlikely (list >= &lruvec->milestones[0 ][0 ].lru && + list < &lruvec->milestones[NR_EVICTABLE_LRU_LISTS ] + [NR_LRU_MILESTONES ].lru); +} +
Not reviewing properly yet, just taking a quick look out of interest but this check may be delicate. 32-bit x86 machines start the kernel direct mapping at 0xC0000000 so milestones[0][0].lru will have some value betewen 0xC0000000 and 0xFFFFFFFF. HZ=250 on my distro config so after 0xC0000000 jiffies or a bit over 149 days of uptime, it looks like there will be a window where LRU entries look like milestones. If I'm right, that is bound to cause problems.
Signature · 8 lines
Mel Gorman SUSE Labs -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 18 lines · Mel Gorman
include/linux/mmzone.h struct zone_reclaim_stat { · line 230
Quoted 8 lines · Konstantin Khlebnikov
include/linux/mmzone.h +8
-0+static inline bool +is_lru_milestone (struct lruvec *lruvec,struct list_head *list) +{ +return unlikely (list>=&lruvec->milestones[0 ][0 ].lru&& + list< &lruvec->milestones[NR_EVICTABLE_LRU_LISTS ] + [NR_LRU_MILESTONES ].lru); +} +Not reviewing properly yet, just taking a quick look out of interest but this check may be delicate. 32-bit x86 machines start the kernel direct mapping at
0xC0000000so milestones[0][0].lru will have some value betewen0xC0000000and0xFFFFFFFF. HZ=250 on my distro config so after0xC0000000jiffies or a bit over 149 days of uptime, it looks like there will be a window where LRU entries look like milestones. If I'm right, that is bound to cause problems.
Nope. There is no such dangerous magic. This function compares only pointers. List heads in page LRU list can be either &page->lru or &lru_milestone->lru. Since milestones are embedded into struct lruvec we can separate them in this way.
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>