Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1556384 > unrolled thread

mm, vmscan: commit makes PAE kernel crash nightly (bisected)

Started byTrevor Cordes <trevor@tecnopolis.ca>
First post2017-01-11 11:40 +0100
Last post2017-01-11 13:20 +0100
Articles 20 on this page of 33 — 3 participants

Back to article view | Back to linux.kernel


Contents

  mm, vmscan: commit makes PAE kernel crash nightly (bisected) Trevor Cordes <trevor@tecnopolis.ca> - 2017-01-11 11:40 +0100
    Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Mel Gorman <mgorman@techsingularity.net> - 2017-01-11 13:20 +0100
      Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Trevor Cordes <trevor@tecnopolis.ca> - 2017-01-12 00:00 +0100
        Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Michal Hocko <mhocko@kernel.org> - 2017-01-12 10:40 +0100
          Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Trevor Cordes <trevor@tecnopolis.ca> - 2017-01-15 07:40 +0100
            Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Mel Gorman <mgorman@techsingularity.net> - 2017-01-16 12:10 +0100
              Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Michal Hocko <mhocko@kernel.org> - 2017-01-17 15:00 +0100
                Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Mel Gorman <mgorman@techsingularity.net> - 2017-01-17 15:30 +0100
                  Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Michal Hocko <mhocko@kernel.org> - 2017-01-17 16:00 +0100
                    Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Trevor Cordes <trevor@tecnopolis.ca> - 2017-01-18 08:30 +0100
                    Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Mel Gorman <mgorman@techsingularity.net> - 2017-01-18 18:50 +0100
                    Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Mel Gorman <mgorman@techsingularity.net> - 2017-01-18 19:10 +0100
                    Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Trevor Cordes <trevor@tecnopolis.ca> - 2017-01-19 10:50 +0100
                      Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Michal Hocko <mhocko@kernel.org> - 2017-01-19 12:40 +0100
                        Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Trevor Cordes <trevor@tecnopolis.ca> - 2017-01-20 07:40 +0100
                          Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Mel Gorman <mgorman@techsingularity.net> - 2017-01-20 12:10 +0100
                            Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Mel Gorman <mgorman@techsingularity.net> - 2017-01-20 17:00 +0100
                              Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Mel Gorman <mgorman@techsingularity.net> - 2017-01-23 11:50 +0100
                                Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Mel Gorman <mgorman@techsingularity.net> - 2017-01-23 12:10 +0100
                                  Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Michal Hocko <mhocko@kernel.org> - 2017-01-25 10:50 +0100
                                Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Michal Hocko <mhocko@kernel.org> - 2017-01-24 14:00 +0100
                                Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Trevor Cordes <trevor@tecnopolis.ca> - 2017-01-25 11:30 +0100
                                  Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Michal Hocko <mhocko@kernel.org> - 2017-01-25 13:10 +0100
                                    Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Trevor Cordes <trevor@tecnopolis.ca> - 2017-01-30 00:00 +0100
                                      Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Michal Hocko <mhocko@kernel.org> - 2017-01-30 09:00 +0100
                                      Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Mel Gorman <mgorman@techsingularity.net> - 2017-01-30 10:20 +0100
                              Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Michal Hocko <mhocko@kernel.org> - 2017-01-24 14:00 +0100
                                Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Trevor Cordes <trevor@tecnopolis.ca> - 2017-01-27 00:20 +0100
                                  Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Michal Hocko <mhocko@kernel.org> - 2017-01-27 08:40 +0100
                          Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Michal Hocko <mhocko@kernel.org> - 2017-01-24 14:00 +0100
              Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Trevor Cordes <trevor@tecnopolis.ca> - 2017-01-18 08:00 +0100
            Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Michal Hocko <mhocko@kernel.org> - 2017-01-17 14:50 +0100
    Re: mm, vmscan: commit makes PAE kernel crash nightly (bisected) Mel Gorman <mgorman@techsingularity.net> - 2017-01-11 13:20 +0100

Page 1 of 2  [1] 2  Next page →


#1556384 — mm, vmscan: commit makes PAE kernel crash nightly (bisected)

FromTrevor Cordes <trevor@tecnopolis.ca>
Date2017-01-11 11:40 +0100
Subjectmm, vmscan: commit makes PAE kernel crash nightly (bisected)
Message-ID<sYotY-5KF-33@gated-at.bofh.it>
Hi!  I have biected a nightly oom-killer flood and crash/hang on one of 
the boxes I admin.  It doesn't crash on Fedora 23/24 4.7.10 kernel but 
does on any 4.8 Fedora kernel.  I did a vanilla bisect and the bug is 
here:

commit b2e18757f2c9d1cdd746a882e9878852fdec9501
Author: Mel Gorman <mgorman@techsingularity.net>
Date:   Thu Jul 28 15:45:37 2016 -0700

    mm, vmscan: begin reclaiming pages on a per-node basis

I bisected between:
# bad: [69973b830859bc6529a7a0468ba0d80ee5117826] Linux 4.9
# good: [523d939ef98fd712632d93a5a2b588e477a7565e] Linux 4.7

I have not tried newer than 4.8.13 Fedora kernel, but if someone thinks 
this bug is already fixed in HEAD I could try that next.  It took 3 weeks 
to bisect because the crash only seems to happen in the middle of the 
night, and not every, but most, nights.

It does not occur on most of my other boxes, just this one.  The box is a 
bit unique in that it's running 32-bit PAE on a 64-bit capable CPU, and I 
have the memory tuned down to mem=6G in the kernel command line (I think 
it has 16GB actual).  I tuned the RAM down because around 8GB the PAE 
kernel has massive IO speed issues.

It is a relatively new Intel(R) Xeon(R) CPU E3-1230 V2 @ 3.30GHz on an 
Intel S1200BTL board.  I will eventually change it to 64-bit Fedora which 
I'm sure will solve this bug, but since there's no easy upgrade path, 
that's on the backburner on this production box.

I'm sure this will be another "PAE sucks, don't use it" issue, but like I 
said, I'm currently stuck with it, and in theory the kernel shouldn't 
crash like this (I'm guessing/hoping).

I think I pinned the trigger down to either (or both) big dir scans (like 
"find /bigdir-foo") running at around 3am.  It's either a remote box doing 
indexing via smbd and/or rsync or rdiff-backup also doing big dir scans.  
But when I do "find /" manually I can't trigger the bug.  Very weird.

The commit notes make it sound like the author thought perhaps there could 
be a problem in some scenarios?  I guess I found the scenario.

The only discussion I found on the net regarding this commit is
https://lkml.org/lkml/2016/8/29/154
And perhaps it's somewhat relevant, it's a bit over my head.

I'm available for testing, etc, and can usually rule out a bad kernel 
within 24-hours by just waiting for 3am to roll around.  I also have 
copious logs I can provide and screenshots of the crashes.

The box is extremely lightly loaded, and RAM use is almost always under 
1GB, and swap is 0-20k used most of the time with GB's free.  Everything 
looks great until all of a sudden oom-killer starts running and goes 
through 10-260 iterations before the system just dies.  I wrote a script 
to watch for oom-killer and issue "reboot" immediately, but 80% of the 
time the box will hang before the reboot actually manages to shutdown.

Any information/help I can provide, please just holler.  Thanks!

[toc] | [next] | [standalone]


#1556440

FromMel Gorman <mgorman@techsingularity.net>
Date2017-01-11 13:20 +0100
Message-ID<sYq2K-6QF-13@gated-at.bofh.it>
In reply to#1556384
On Wed, Jan 11, 2017 at 12:11:46PM +0000, Mel Gorman wrote:
> On Wed, Jan 11, 2017 at 04:32:43AM -0600, Trevor Cordes wrote:
> > Hi!  I have biected a nightly oom-killer flood and crash/hang on one of 
> > the boxes I admin.  It doesn't crash on Fedora 23/24 4.7.10 kernel but 
> > does on any 4.8 Fedora kernel.  I did a vanilla bisect and the bug is 
> > here:
> > 
> > commit b2e18757f2c9d1cdd746a882e9878852fdec9501
> > Author: Mel Gorman <mgorman@techsingularity.net>
> > Date:   Thu Jul 28 15:45:37 2016 -0700
> > 
> >     mm, vmscan: begin reclaiming pages on a per-node basis
> > 
> 
> Michal Hocko recently worked on a bug similar to this. Can you test the
> following patch that is currently queued in Andrew Morton's tree? It
> applies cleanly to 4.9
> 

I should have pointed out that this patch primarily affects memcg but
the bug report did not include an OOM report and did not describe
whether memcgs could be involved or not. If memcgs are not involved then
please post the first full OOM kill.

> Thanks.
> 
> From: Michal Hocko <mhocko@suse.com>
> Subject: mm, memcg: fix the active list aging for lowmem requests when memcg is enabled
> 
> Nils Holland and Klaus Ethgen have reported unexpected OOM killer
> invocations with 32b kernel starting with 4.8 kernels
> 
> 	kworker/u4:5 invoked oom-killer: gfp_mask=0x2400840(GFP_NOFS|__GFP_NOFAIL), nodemask=0, order=0, oom_score_adj=0
> 	kworker/u4:5 cpuset=/ mems_allowed=0
> 	CPU: 1 PID: 2603 Comm: kworker/u4:5 Not tainted 4.9.0-gentoo #2
> 	[...]
> 	Mem-Info:
> 	active_anon:58685 inactive_anon:90 isolated_anon:0
> 	 active_file:274324 inactive_file:281962 isolated_file:0
> 	 unevictable:0 dirty:649 writeback:0 unstable:0
> 	 slab_reclaimable:40662 slab_unreclaimable:17754
> 	 mapped:7382 shmem:202 pagetables:351 bounce:0
> 	 free:206736 free_pcp:332 free_cma:0
> 	Node 0 active_anon:234740kB inactive_anon:360kB active_file:1097296kB inactive_file:1127848kB unevictable:0kB isolated(anon):0kB isolated(file):0kB mapped:29528kB dirty:2596kB writeback:0kB shmem:0kB shmem_thp: 0kB shmem_pmdmapped: 184320kB anon_thp: 808kB writeback_tmp:0kB unstable:0kB pages_scanned:0 all_unreclaimable? no
> 	DMA free:3952kB min:788kB low:984kB high:1180kB active_anon:0kB inactive_anon:0kB active_file:7316kB inactive_file:0kB unevictable:0kB writepending:96kB present:15992kB managed:15916kB mlocked:0kB slab_reclaimable:3200kB slab_unreclaimable:1408kB kernel_stack:0kB pagetables:0kB bounce:0kB free_pcp:0kB local_pcp:0kB free_cma:0kB
> 	lowmem_reserve[]: 0 813 3474 3474
> 	Normal free:41332kB min:41368kB low:51708kB high:62048kB active_anon:0kB inactive_anon:0kB active_file:532748kB inactive_file:44kB unevictable:0kB writepending:24kB present:897016kB managed:836248kB mlocked:0kB slab_reclaimable:159448kB slab_unreclaimable:69608kB kernel_stack:1112kB pagetables:1404kB bounce:0kB free_pcp:528kB local_pcp:340kB free_cma:0kB
> 	lowmem_reserve[]: 0 0 21292 21292
> 	HighMem free:781660kB min:512kB low:34356kB high:68200kB active_anon:234740kB inactive_anon:360kB active_file:557232kB inactive_file:1127804kB unevictable:0kB writepending:2592kB present:2725384kB managed:2725384kB mlocked:0kB slab_reclaimable:0kB slab_unreclaimable:0kB kernel_stack:0kB pagetables:0kB bounce:0kB free_pcp:800kB local_pcp:608kB free_cma:0kB
> 
> the oom killer is clearly pre-mature because there there is still a lot of
> page cache in the zone Normal which should satisfy this lowmem request. 
> Further debugging has shown that the reclaim cannot make any forward
> progress because the page cache is hidden in the active list which doesn't
> get rotated because inactive_list_is_low is not memcg aware.
> 
> It simply subtracts per-zone highmem counters from the respective memcg's
> lru sizes which doesn't make any sense.  We can simply end up always
> seeing the resulting active and inactive counts 0 and return false.  This
> issue is not limited to 32b kernels but in practice the effect on systems
> without CONFIG_HIGHMEM would be much harder to notice because we do not
> invoke the OOM killer for allocations requests targeting < ZONE_NORMAL.
> 
> Fix the issue by tracking per zone lru page counts in mem_cgroup_per_node
> and subtract per-memcg highmem counts when memcg is enabled.  Introduce
> helper lruvec_zone_lru_size which redirects to either zone counters or
> mem_cgroup_get_zone_lru_size when appropriate.
> 
> We are losing empty LRU but non-zero lru size detection introduced by
> ca707239e8a7 ("mm: update_lru_size warn and reset bad lru_size") because
> of the inherent zone vs.  node discrepancy.
> 
> Fixes: f8d1a31163fc ("mm: consider whether to decivate based on eligible zones inactive ratio")
> Link: http://lkml.kernel.org/r/20170104100825.3729-1-mhocko@kernel.org
> Signed-off-by: Michal Hocko <mhocko@suse.com>
> Reported-by: Nils Holland <nholland@tisys.org>
> Tested-by: Nils Holland <nholland@tisys.org>
> Reported-by: Klaus Ethgen <Klaus@Ethgen.de>
> Acked-by: Minchan Kim <minchan@kernel.org>
> Acked-by: Mel Gorman <mgorman@suse.de>
> Acked-by: Johannes Weiner <hannes@cmpxchg.org>
> Reviewed-by: Vladimir Davydov <vdavydov.dev@gmail.com>
> Cc: <stable@vger.kernel.org>	[4.8+]
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---
> 
>  include/linux/memcontrol.h |   26 +++++++++++++++++++++++---
>  include/linux/mm_inline.h  |    2 +-
>  mm/memcontrol.c            |   18 ++++++++----------
>  mm/vmscan.c                |   27 +++++++++++++++++----------
>  4 files changed, 49 insertions(+), 24 deletions(-)
> 
> diff -puN include/linux/memcontrol.h~mm-memcg-fix-the-active-list-aging-for-lowmem-requests-when-memcg-is-enabled include/linux/memcontrol.h
> --- a/include/linux/memcontrol.h~mm-memcg-fix-the-active-list-aging-for-lowmem-requests-when-memcg-is-enabled
> +++ a/include/linux/memcontrol.h
> @@ -120,7 +120,7 @@ struct mem_cgroup_reclaim_iter {
>   */
>  struct mem_cgroup_per_node {
>  	struct lruvec		lruvec;
> -	unsigned long		lru_size[NR_LRU_LISTS];
> +	unsigned long		lru_zone_size[MAX_NR_ZONES][NR_LRU_LISTS];
>  
>  	struct mem_cgroup_reclaim_iter	iter[DEF_PRIORITY + 1];
>  
> @@ -432,7 +432,7 @@ static inline bool mem_cgroup_online(str
>  int mem_cgroup_select_victim_node(struct mem_cgroup *memcg);
>  
>  void mem_cgroup_update_lru_size(struct lruvec *lruvec, enum lru_list lru,
> -		int nr_pages);
> +		int zid, int nr_pages);
>  
>  unsigned long mem_cgroup_node_nr_lru_pages(struct mem_cgroup *memcg,
>  					   int nid, unsigned int lru_mask);
> @@ -441,9 +441,23 @@ static inline
>  unsigned long mem_cgroup_get_lru_size(struct lruvec *lruvec, enum lru_list lru)
>  {
>  	struct mem_cgroup_per_node *mz;
> +	unsigned long nr_pages = 0;
> +	int zid;
>  
>  	mz = container_of(lruvec, struct mem_cgroup_per_node, lruvec);
> -	return mz->lru_size[lru];
> +	for (zid = 0; zid < MAX_NR_ZONES; zid++)
> +		nr_pages += mz->lru_zone_size[zid][lru];
> +	return nr_pages;
> +}
> +
> +static inline
> +unsigned long mem_cgroup_get_zone_lru_size(struct lruvec *lruvec,
> +		enum lru_list lru, int zone_idx)
> +{
> +	struct mem_cgroup_per_node *mz;
> +
> +	mz = container_of(lruvec, struct mem_cgroup_per_node, lruvec);
> +	return mz->lru_zone_size[zone_idx][lru];
>  }
>  
>  void mem_cgroup_handle_over_high(void);
> @@ -671,6 +685,12 @@ mem_cgroup_get_lru_size(struct lruvec *l
>  {
>  	return 0;
>  }
> +static inline
> +unsigned long mem_cgroup_get_zone_lru_size(struct lruvec *lruvec,
> +		enum lru_list lru, int zone_idx)
> +{
> +	return 0;
> +}
>  
>  static inline unsigned long
>  mem_cgroup_node_nr_lru_pages(struct mem_cgroup *memcg,
> diff -puN include/linux/mm_inline.h~mm-memcg-fix-the-active-list-aging-for-lowmem-requests-when-memcg-is-enabled include/linux/mm_inline.h
> --- a/include/linux/mm_inline.h~mm-memcg-fix-the-active-list-aging-for-lowmem-requests-when-memcg-is-enabled
> +++ a/include/linux/mm_inline.h
> @@ -39,7 +39,7 @@ static __always_inline void update_lru_s
>  {
>  	__update_lru_size(lruvec, lru, zid, nr_pages);
>  #ifdef CONFIG_MEMCG
> -	mem_cgroup_update_lru_size(lruvec, lru, nr_pages);
> +	mem_cgroup_update_lru_size(lruvec, lru, zid, nr_pages);
>  #endif
>  }
>  
> diff -puN mm/memcontrol.c~mm-memcg-fix-the-active-list-aging-for-lowmem-requests-when-memcg-is-enabled mm/memcontrol.c
> --- a/mm/memcontrol.c~mm-memcg-fix-the-active-list-aging-for-lowmem-requests-when-memcg-is-enabled
> +++ a/mm/memcontrol.c
> @@ -625,8 +625,8 @@ static void mem_cgroup_charge_statistics
>  unsigned long mem_cgroup_node_nr_lru_pages(struct mem_cgroup *memcg,
>  					   int nid, unsigned int lru_mask)
>  {
> +	struct lruvec *lruvec = mem_cgroup_lruvec(NODE_DATA(nid), memcg);
>  	unsigned long nr = 0;
> -	struct mem_cgroup_per_node *mz;
>  	enum lru_list lru;
>  
>  	VM_BUG_ON((unsigned)nid >= nr_node_ids);
> @@ -634,8 +634,7 @@ unsigned long mem_cgroup_node_nr_lru_pag
>  	for_each_lru(lru) {
>  		if (!(BIT(lru) & lru_mask))
>  			continue;
> -		mz = mem_cgroup_nodeinfo(memcg, nid);
> -		nr += mz->lru_size[lru];
> +		nr += mem_cgroup_get_lru_size(lruvec, lru);
>  	}
>  	return nr;
>  }
> @@ -1002,6 +1001,7 @@ out:
>   * mem_cgroup_update_lru_size - account for adding or removing an lru page
>   * @lruvec: mem_cgroup per zone lru vector
>   * @lru: index of lru list the page is sitting on
> + * @zid: zone id of the accounted pages
>   * @nr_pages: positive when adding or negative when removing
>   *
>   * This function must be called under lru_lock, just before a page is added
> @@ -1009,27 +1009,25 @@ out:
>   * so as to allow it to check that lru_size 0 is consistent with list_empty).
>   */
>  void mem_cgroup_update_lru_size(struct lruvec *lruvec, enum lru_list lru,
> -				int nr_pages)
> +				int zid, int nr_pages)
>  {
>  	struct mem_cgroup_per_node *mz;
>  	unsigned long *lru_size;
>  	long size;
> -	bool empty;
>  
>  	if (mem_cgroup_disabled())
>  		return;
>  
>  	mz = container_of(lruvec, struct mem_cgroup_per_node, lruvec);
> -	lru_size = mz->lru_size + lru;
> -	empty = list_empty(lruvec->lists + lru);
> +	lru_size = &mz->lru_zone_size[zid][lru];
>  
>  	if (nr_pages < 0)
>  		*lru_size += nr_pages;
>  
>  	size = *lru_size;
> -	if (WARN_ONCE(size < 0 || empty != !size,
> -		"%s(%p, %d, %d): lru_size %ld but %sempty\n",
> -		__func__, lruvec, lru, nr_pages, size, empty ? "" : "not ")) {
> +	if (WARN_ONCE(size < 0,
> +		"%s(%p, %d, %d): lru_size %ld\n",
> +		__func__, lruvec, lru, nr_pages, size)) {
>  		VM_BUG_ON(1);
>  		*lru_size = 0;
>  	}
> diff -puN mm/vmscan.c~mm-memcg-fix-the-active-list-aging-for-lowmem-requests-when-memcg-is-enabled mm/vmscan.c
> --- a/mm/vmscan.c~mm-memcg-fix-the-active-list-aging-for-lowmem-requests-when-memcg-is-enabled
> +++ a/mm/vmscan.c
> @@ -242,6 +242,16 @@ unsigned long lruvec_lru_size(struct lru
>  	return node_page_state(lruvec_pgdat(lruvec), NR_LRU_BASE + lru);
>  }
>  
> +unsigned long lruvec_zone_lru_size(struct lruvec *lruvec, enum lru_list lru,
> +				   int zone_idx)
> +{
> +	if (!mem_cgroup_disabled())
> +		return mem_cgroup_get_zone_lru_size(lruvec, lru, zone_idx);
> +
> +	return zone_page_state(&lruvec_pgdat(lruvec)->node_zones[zone_idx],
> +			       NR_ZONE_LRU_BASE + lru);
> +}
> +
>  /*
>   * Add a shrinker callback to be called from the vm.
>   */
> @@ -1382,8 +1392,7 @@ int __isolate_lru_page(struct page *page
>   * be complete before mem_cgroup_update_lru_size due to a santity check.
>   */
>  static __always_inline void update_lru_sizes(struct lruvec *lruvec,
> -			enum lru_list lru, unsigned long *nr_zone_taken,
> -			unsigned long nr_taken)
> +			enum lru_list lru, unsigned long *nr_zone_taken)
>  {
>  	int zid;
>  
> @@ -1392,11 +1401,11 @@ static __always_inline void update_lru_s
>  			continue;
>  
>  		__update_lru_size(lruvec, lru, zid, -nr_zone_taken[zid]);
> -	}
> -
>  #ifdef CONFIG_MEMCG
> -	mem_cgroup_update_lru_size(lruvec, lru, -nr_taken);
> +		mem_cgroup_update_lru_size(lruvec, lru, zid, -nr_zone_taken[zid]);
>  #endif
> +	}
> +
>  }
>  
>  /*
> @@ -1501,7 +1510,7 @@ static unsigned long isolate_lru_pages(u
>  	*nr_scanned = scan;
>  	trace_mm_vmscan_lru_isolate(sc->reclaim_idx, sc->order, nr_to_scan, scan,
>  				    nr_taken, mode, is_file_lru(lru));
> -	update_lru_sizes(lruvec, lru, nr_zone_taken, nr_taken);
> +	update_lru_sizes(lruvec, lru, nr_zone_taken);
>  	return nr_taken;
>  }
>  
> @@ -2047,10 +2056,8 @@ static bool inactive_list_is_low(struct
>  		if (!managed_zone(zone))
>  			continue;
>  
> -		inactive_zone = zone_page_state(zone,
> -				NR_ZONE_LRU_BASE + (file * LRU_FILE));
> -		active_zone = zone_page_state(zone,
> -				NR_ZONE_LRU_BASE + (file * LRU_FILE) + LRU_ACTIVE);
> +		inactive_zone = lruvec_zone_lru_size(lruvec, file * LRU_FILE, zid);
> +		active_zone = lruvec_zone_lru_size(lruvec, (file * LRU_FILE) + LRU_ACTIVE, zid);
>  
>  		inactive -= min(inactive, inactive_zone);
>  		active -= min(active, active_zone);
> _

-- 
Mel Gorman
SUSE Labs

[toc] | [prev] | [next] | [standalone]


#1556999

FromTrevor Cordes <trevor@tecnopolis.ca>
Date2017-01-12 00:00 +0100
Message-ID<sYA25-4n7-11@gated-at.bofh.it>
In reply to#1556440

[Multipart message — attachments visible in raw view] — view raw

On 2017-01-11 Mel Gorman wrote:
> On Wed, Jan 11, 2017 at 12:11:46PM +0000, Mel Gorman wrote:
> > On Wed, Jan 11, 2017 at 04:32:43AM -0600, Trevor Cordes wrote:  
> > > Hi!  I have biected a nightly oom-killer flood and crash/hang on
> > > one of the boxes I admin.  It doesn't crash on Fedora 23/24
> > > 4.7.10 kernel but does on any 4.8 Fedora kernel.  I did a vanilla
> > > bisect and the bug is here:
> > > 
> > > commit b2e18757f2c9d1cdd746a882e9878852fdec9501
> > > Author: Mel Gorman <mgorman@techsingularity.net>
> > > Date:   Thu Jul 28 15:45:37 2016 -0700
> > > 
> > >     mm, vmscan: begin reclaiming pages on a per-node basis
> > >   
> > 
> > Michal Hocko recently worked on a bug similar to this. Can you test
> > the following patch that is currently queued in Andrew Morton's
> > tree? It applies cleanly to 4.9
> >   
> 
> I should have pointed out that this patch primarily affects memcg but
> the bug report did not include an OOM report and did not describe
> whether memcgs could be involved or not. If memcgs are not involved
> then please post the first full OOM kill.

I will apply your patch tonight and it will take 48 hours to confirm
that it is "good" (<24 hours if it's bad), and I will reply back.

I'm not sure how I can tell if my bug is because of memcgs so here is
a full first oom example (attached).

Thanks for the help!

[toc] | [prev] | [next] | [standalone]


#1557246

FromMichal Hocko <mhocko@kernel.org>
Date2017-01-12 10:40 +0100
Message-ID<sYK1s-2hi-23@gated-at.bofh.it>
In reply to#1556999
On Wed 11-01-17 16:52:32, Trevor Cordes wrote:
[...]
> I'm not sure how I can tell if my bug is because of memcgs so here is
> a full first oom example (attached).

4.7 kernel doesn't contain 71c799f4982d ("mm: add per-zone lru list
stat") so the OOM report will not tell us whether the Normal zone
doesn't age active lists, unfortunatelly.

You can easily check whether this is memcg related by trying to run the
same workload with cgroup_disable=memory kernel command line parameter.
This will put all the memcg specifics out of the way.
-- 
Michal Hocko
SUSE Labs

[toc] | [prev] | [next] | [standalone]


#1559170

FromTrevor Cordes <trevor@tecnopolis.ca>
Date2017-01-15 07:40 +0100
Message-ID<sZMDT-7Go-1@gated-at.bofh.it>
In reply to#1557246

[Multipart message — attachments visible in raw view] — view raw

On 2017-01-12 Michal Hocko wrote:
> On Wed 11-01-17 16:52:32, Trevor Cordes wrote:
> [...]
> > I'm not sure how I can tell if my bug is because of memcgs so here
> > is a full first oom example (attached).  
> 
> 4.7 kernel doesn't contain 71c799f4982d ("mm: add per-zone lru list
> stat") so the OOM report will not tell us whether the Normal zone
> doesn't age active lists, unfortunatelly.

I compiled the patch Mel provided into the stock F23 kernel
4.8.13-100.fc23.i686+PAE and it ran for 2 nights.  It didn't oom the
first night, but did the second night.  So the bug persists even with
that patch.  However, it does *seem* a bit "better" since it took 2
nights (usually takes only one, but maybe 10% of the time it does take
two) before oom'ing, *and* it allowed my reboot script to reboot it
cleanly when it saw the oom (which happens only 25% of the time).

I'm attaching the 4.8.13 oom message which should have the memcg info
(71c799f4982d) you are asking for above?  Hopefully?

> You can easily check whether this is memcg related by trying to run
> the same workload with cgroup_disable=memory kernel command line
> parameter. This will put all the memcg specifics out of the way.

I will try booting now into cgroup_disable=memory to see if that helps
at all.  I'll reply back in 48 hours, or when it oom's, whichever comes
first.

Also, should I bother trying the latest git HEAD to see if that solves
anything?  Thanks!

[toc] | [prev] | [next] | [standalone]


#1559640

FromMel Gorman <mgorman@techsingularity.net>
Date2017-01-16 12:10 +0100
Message-ID<t0dkL-817-33@gated-at.bofh.it>
In reply to#1559170
On Sun, Jan 15, 2017 at 12:27:52AM -0600, Trevor Cordes wrote:
> On 2017-01-12 Michal Hocko wrote:
> > On Wed 11-01-17 16:52:32, Trevor Cordes wrote:
> > [...]
> > > I'm not sure how I can tell if my bug is because of memcgs so here
> > > is a full first oom example (attached).  
> > 
> > 4.7 kernel doesn't contain 71c799f4982d ("mm: add per-zone lru list
> > stat") so the OOM report will not tell us whether the Normal zone
> > doesn't age active lists, unfortunatelly.
> 
> I compiled the patch Mel provided into the stock F23 kernel
> 4.8.13-100.fc23.i686+PAE and it ran for 2 nights.  It didn't oom the
> first night, but did the second night.  So the bug persists even with
> that patch.  However, it does *seem* a bit "better" since it took 2
> nights (usually takes only one, but maybe 10% of the time it does take
> two) before oom'ing, *and* it allowed my reboot script to reboot it
> cleanly when it saw the oom (which happens only 25% of the time).
> 
> I'm attaching the 4.8.13 oom message which should have the memcg info
> (71c799f4982d) you are asking for above?  Hopefully?
> 

It shows that there are an extremely large number of reclaimable slab
pages in the lower zones. Other pages have been reclaimed as normal but
the failure to reclaim slab pages causes a high-order allocation to
fail.

> > You can easily check whether this is memcg related by trying to run
> > the same workload with cgroup_disable=memory kernel command line
> > parameter. This will put all the memcg specifics out of the way.
> 
> I will try booting now into cgroup_disable=memory to see if that helps
> at all.  I'll reply back in 48 hours, or when it oom's, whichever comes
> first.
> 

Thanks.

> Also, should I bother trying the latest git HEAD to see if that solves
> anything?  Thanks!

That's worth trying. If that also fails then could you try the following
hack to encourage direct reclaim to reclaim slab when buffers are over
the limit please?

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 532a2a750952..46aac487b89a 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2684,6 +2684,7 @@ static void shrink_zones(struct zonelist *zonelist, struct scan_control *sc)
 				continue;
 
 			if (sc->priority != DEF_PRIORITY &&
+			    !buffer_heads_over_limit &&
 			    !pgdat_reclaimable(zone->zone_pgdat))
 				continue;	/* Let kswapd poll it */
 

-- 
Mel Gorman
SUSE Labs

[toc] | [prev] | [next] | [standalone]


#1560603

FromMichal Hocko <mhocko@kernel.org>
Date2017-01-17 15:00 +0100
Message-ID<t0CsO-7MA-35@gated-at.bofh.it>
In reply to#1559640
On Mon 16-01-17 11:09:34, Mel Gorman wrote:
[...]
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 532a2a750952..46aac487b89a 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -2684,6 +2684,7 @@ static void shrink_zones(struct zonelist *zonelist, struct scan_control *sc)
>  				continue;
>  
>  			if (sc->priority != DEF_PRIORITY &&
> +			    !buffer_heads_over_limit &&
>  			    !pgdat_reclaimable(zone->zone_pgdat))
>  				continue;	/* Let kswapd poll it */

I think we should rather remove pgdat_reclaimable here. This sounds like
a wrong layer to decide whether we want to reclaim and how much.

But even that won't help very much I am afraid. As I've noted in the
other response as long as we will scale the slab shrinking based on
nr_scanned we will have a problem with situations where slab outnumbers
lru lists too much. I do not have a good idea how to fix that though...

-- 
Michal Hocko
SUSE Labs

[toc] | [prev] | [next] | [standalone]


#1560640

FromMel Gorman <mgorman@techsingularity.net>
Date2017-01-17 15:30 +0100
Message-ID<t0CVQ-8bo-21@gated-at.bofh.it>
In reply to#1560603
On Tue, Jan 17, 2017 at 02:52:28PM +0100, Michal Hocko wrote:
> On Mon 16-01-17 11:09:34, Mel Gorman wrote:
> [...]
> > diff --git a/mm/vmscan.c b/mm/vmscan.c
> > index 532a2a750952..46aac487b89a 100644
> > --- a/mm/vmscan.c
> > +++ b/mm/vmscan.c
> > @@ -2684,6 +2684,7 @@ static void shrink_zones(struct zonelist *zonelist, struct scan_control *sc)
> >  				continue;
> >  
> >  			if (sc->priority != DEF_PRIORITY &&
> > +			    !buffer_heads_over_limit &&
> >  			    !pgdat_reclaimable(zone->zone_pgdat))
> >  				continue;	/* Let kswapd poll it */
> 
> I think we should rather remove pgdat_reclaimable here. This sounds like
> a wrong layer to decide whether we want to reclaim and how much.
> 

I had considered that but it'd also be important to add the other 32-bit
patches you have posted to see the impact. Because of the ratio of LRU pages
to slab pages, it may not have an impact but it'd need to be eliminated.

> But even that won't help very much I am afraid. As I've noted in the
> other response as long as we will scale the slab shrinking based on
> nr_scanned we will have a problem with situations where slab outnumbers
> lru lists too much. I do not have a good idea how to fix that though...
> 

Right now, I don't either other than a heavy-handed approach of checking if
a) it's a pgdat with a highmem node b) if the ratio of LRU pages to slab
pages on the lower zones is out of whack and if so, ignore nr_scanned for
the slab shrinker.

Before prototyping such a thing, I'd like to hear the outcome of this
heavy hack and then add your 32-bit patches onto the list. If the problem
is still there then I'd next look at taking slab pages into account in
pgdat_reclaimable() instead of an outright removal that has a much wider
impact. If that doesn't work then I'll prototype a heavy-handed forced
slab reclaim when lower zones are almost all slab pages.

-- 
Mel Gorman
SUSE Labs

[toc] | [prev] | [next] | [standalone]


#1560669

FromMichal Hocko <mhocko@kernel.org>
Date2017-01-17 16:00 +0100
Message-ID<t0DoS-8lp-1@gated-at.bofh.it>
In reply to#1560640
On Tue 17-01-17 14:21:14, Mel Gorman wrote:
> On Tue, Jan 17, 2017 at 02:52:28PM +0100, Michal Hocko wrote:
> > On Mon 16-01-17 11:09:34, Mel Gorman wrote:
> > [...]
> > > diff --git a/mm/vmscan.c b/mm/vmscan.c
> > > index 532a2a750952..46aac487b89a 100644
> > > --- a/mm/vmscan.c
> > > +++ b/mm/vmscan.c
> > > @@ -2684,6 +2684,7 @@ static void shrink_zones(struct zonelist *zonelist, struct scan_control *sc)
> > >  				continue;
> > >  
> > >  			if (sc->priority != DEF_PRIORITY &&
> > > +			    !buffer_heads_over_limit &&
> > >  			    !pgdat_reclaimable(zone->zone_pgdat))
> > >  				continue;	/* Let kswapd poll it */
> > 
> > I think we should rather remove pgdat_reclaimable here. This sounds like
> > a wrong layer to decide whether we want to reclaim and how much.
> > 
> 
> I had considered that but it'd also be important to add the other 32-bit
> patches you have posted to see the impact. Because of the ratio of LRU pages
> to slab pages, it may not have an impact but it'd need to be eliminated.

OK, Trevor you can pull from
git://git.kernel.org/pub/scm/linux/kernel/git/mhocko/mm.git tree
fixes/highmem-node-fixes branch. This contains the current mmotm tree +
the latest highmem fixes. I also do not expect this would help much in
your case but as Mel've said we should rule that out at least.

> Right now, I don't either other than a heavy-handed approach of checking if
> a) it's a pgdat with a highmem node

I do not think this is a right approach because we have a similar
problem even without the highmem. I have already seen cases where the
slab memory has eaten the whole DMA32 zone.

> b) if the ratio of LRU pages to slab
> pages on the lower zones is out of whack and if so, ignore nr_scanned for
> the slab shrinker.

this sounds much more promissing.

> Before prototyping such a thing, I'd like to hear the outcome of this
> heavy hack and then add your 32-bit patches onto the list. If the problem
> is still there then I'd next look at taking slab pages into account in
> pgdat_reclaimable() instead of an outright removal that has a much wider
> impact. If that doesn't work then I'll prototype a heavy-handed forced
> slab reclaim when lower zones are almost all slab pages.

I would be really curious to hear whether pgdat_reclaimable removal
makes any bad side effects. It just smells wrong from a highlevel point
of view. Besides that I really _hate_ pgdat_reclaimable for any decision
making. It just behaves very randomly... I do not expect it help much in
this case, though, as the highmem can easily bias the decision.
-- 
Michal Hocko
SUSE Labs

[toc] | [prev] | [next] | [standalone]


#1561335

FromTrevor Cordes <trevor@tecnopolis.ca>
Date2017-01-18 08:30 +0100
Message-ID<t0SQW-16l-7@gated-at.bofh.it>
In reply to#1560669
On 2017-01-17 Michal Hocko wrote:
> On Tue 17-01-17 14:21:14, Mel Gorman wrote:
> > On Tue, Jan 17, 2017 at 02:52:28PM +0100, Michal Hocko wrote:  
> > > On Mon 16-01-17 11:09:34, Mel Gorman wrote:
> > > [...]  
> > > > diff --git a/mm/vmscan.c b/mm/vmscan.c
> > > > index 532a2a750952..46aac487b89a 100644
> > > > --- a/mm/vmscan.c
> > > > +++ b/mm/vmscan.c
> > > > @@ -2684,6 +2684,7 @@ static void shrink_zones(struct zonelist
> > > > *zonelist, struct scan_control *sc) continue;
> > > >  
> > > >  			if (sc->priority != DEF_PRIORITY &&
> > > > +			    !buffer_heads_over_limit &&
> > > >  			    !pgdat_reclaimable(zone->zone_pgdat))
> > > >  				continue;	/* Let kswapd
> > > > poll it */  
> > > 
> > > I think we should rather remove pgdat_reclaimable here. This
> > > sounds like a wrong layer to decide whether we want to reclaim
> > > and how much. 
> > 
> > I had considered that but it'd also be important to add the other
> > 32-bit patches you have posted to see the impact. Because of the
> > ratio of LRU pages to slab pages, it may not have an impact but
> > it'd need to be eliminated.  
> 
> OK, Trevor you can pull from
> git://git.kernel.org/pub/scm/linux/kernel/git/mhocko/mm.git tree
> fixes/highmem-node-fixes branch. This contains the current mmotm tree
> + the latest highmem fixes. I also do not expect this would help much
> in your case but as Mel've said we should rule that out at least.

OK, ignore my last question re: what to do next.  I am building
this mhocko git tree now per your above instructions and will reboot
into it in a few hours with*out* the cgroup_disable=memory option.
Might take ~50 hours for a result.

I should note that the workload on the box with the bug is mostly as a
file server and iptables firewall/router.  It routes around 8GB(ytes) a
day, and periodic file server loads.  That's about it.  Everything else
that is running is not doing much, and not using much RAM; except
maybe clamav, by far the biggest RAM.

I don't see this bug on other nearly identical boxes, including:
F24 4.8.15 32-bit (no PAE) 1GB ram P4
F24 4.8.15 32-bit (no PAE) 2GB ram Core2 Quad

However, just noticed for the first time today that one other box is
also seeing this bug (gets an oom message), though with much less
frequency: twice in 2 months since upgrading to 4.8.  However, it
recovers from the oom without a reboot and hasn't hanged (yet).  That
could be because this box does not do as much file serving or I/O as
the one I've been building/testing on. Also, this box is a much older
Pentium-D with 4GB (PAE on).  If it would be helpful to see its oom
log, let me know.  (Scanning all my boxes now, I also found 1 single oom
on yet another 1 computer with the same story; but this is a Xeon
E3-1220 32-bit with PAE, 4GB.)

So far the commonality seems to be >2GB RAM and PAE on.  Might be
interesting to boot my build/test box with mem=2G and isolate it to
small RAM vs PAE.  "mem=2G" would make a great, easy, immediate
workaround for this problem for me (as cgroup_disable=memory also seems
to do, so far).  Thanks!

[toc] | [prev] | [next] | [standalone]


#1561999

FromMel Gorman <mgorman@techsingularity.net>
Date2017-01-18 18:50 +0100
Message-ID<t12wV-72O-19@gated-at.bofh.it>
In reply to#1560669
On Tue, Jan 17, 2017 at 03:54:51PM +0100, Michal Hocko wrote:
> On Tue 17-01-17 14:21:14, Mel Gorman wrote:
> > On Tue, Jan 17, 2017 at 02:52:28PM +0100, Michal Hocko wrote:
> > > On Mon 16-01-17 11:09:34, Mel Gorman wrote:
> > > [...]
> > > > diff --git a/mm/vmscan.c b/mm/vmscan.c
> > > > index 532a2a750952..46aac487b89a 100644
> > > > --- a/mm/vmscan.c
> > > > +++ b/mm/vmscan.c
> > > > @@ -2684,6 +2684,7 @@ static void shrink_zones(struct zonelist *zonelist, struct scan_control *sc)
> > > >  				continue;
> > > >  
> > > >  			if (sc->priority != DEF_PRIORITY &&
> > > > +			    !buffer_heads_over_limit &&
> > > >  			    !pgdat_reclaimable(zone->zone_pgdat))
> > > >  				continue;	/* Let kswapd poll it */
> > > 
> > > I think we should rather remove pgdat_reclaimable here. This sounds like
> > > a wrong layer to decide whether we want to reclaim and how much.
> > > 
> > 
> > I had considered that but it'd also be important to add the other 32-bit
> > patches you have posted to see the impact. Because of the ratio of LRU pages
> > to slab pages, it may not have an impact but it'd need to be eliminated.
> 
> OK, Trevor you can pull from
> git://git.kernel.org/pub/scm/linux/kernel/git/mhocko/mm.git tree
> fixes/highmem-node-fixes branch. This contains the current mmotm tree +
> the latest highmem fixes. I also do not expect this would help much in
> your case but as Mel've said we should rule that out at least.
> 

After considering slab shrinking of lower nodes, it occurs to me that your
fixes also impacts slab shrinking. For lowmem-constrained allocations,
we accounted for scans on the lower zones but shrunk slabs proportional to
the total LRU size. If the lower zones had few LRU pages and were mostly
slab pages then the proportional calculation would be way off. This may
have a bigger impact on Trevor Cordes' situation that I had imagined at
the start of today.

-- 
Mel Gorman
SUSE Labs

[toc] | [prev] | [next] | [standalone]


#1562039

FromMel Gorman <mgorman@techsingularity.net>
Date2017-01-18 19:10 +0100
Message-ID<t12Qj-7py-37@gated-at.bofh.it>
In reply to#1560669
On Tue, Jan 17, 2017 at 03:54:51PM +0100, Michal Hocko wrote:
> On Tue 17-01-17 14:21:14, Mel Gorman wrote:
> > On Tue, Jan 17, 2017 at 02:52:28PM +0100, Michal Hocko wrote:
> > > On Mon 16-01-17 11:09:34, Mel Gorman wrote:
> > > [...]
> > > > diff --git a/mm/vmscan.c b/mm/vmscan.c
> > > > index 532a2a750952..46aac487b89a 100644
> > > > --- a/mm/vmscan.c
> > > > +++ b/mm/vmscan.c
> > > > @@ -2684,6 +2684,7 @@ static void shrink_zones(struct zonelist *zonelist, struct scan_control *sc)
> > > >  				continue;
> > > >  
> > > >  			if (sc->priority != DEF_PRIORITY &&
> > > > +			    !buffer_heads_over_limit &&
> > > >  			    !pgdat_reclaimable(zone->zone_pgdat))
> > > >  				continue;	/* Let kswapd poll it */
> > > 
> > > I think we should rather remove pgdat_reclaimable here. This sounds like
> > > a wrong layer to decide whether we want to reclaim and how much.
> > > 
> > 
> > I had considered that but it'd also be important to add the other 32-bit
> > patches you have posted to see the impact. Because of the ratio of LRU pages
> > to slab pages, it may not have an impact but it'd need to be eliminated.
> 
> OK, Trevor you can pull from
> git://git.kernel.org/pub/scm/linux/kernel/git/mhocko/mm.git tree
> fixes/highmem-node-fixes branch. This contains the current mmotm tree +
> the latest highmem fixes. I also do not expect this would help much in
> your case but as Mel've said we should rule that out at least.
> 

After considering slab shrinking of lower nodes, it occured to me
that your fixes may have a bigger impact than I believed this morning.
For lowmem-constrained allocations, we account for scans on the lower
zones but shrink proportionally to the LRU size for the entire node. If
the lower zones had few LRU pages and were mostly slab pages then the
proportional calculation would be way off so direct reclaim would barely
touch slab caches. That is fixed up by "mm, vmscan: consider eligible zones
in get_scan_count" so that the slab shrinking will be proportional to the
LRU pages on the lower zones.

-- 
Mel Gorman
SUSE Labs

[toc] | [prev] | [next] | [standalone]


#1562532

FromTrevor Cordes <trevor@tecnopolis.ca>
Date2017-01-19 10:50 +0100
Message-ID<t1hvY-8e7-25@gated-at.bofh.it>
In reply to#1560669
On 2017-01-17 Michal Hocko wrote:
> On Tue 17-01-17 14:21:14, Mel Gorman wrote:
> > On Tue, Jan 17, 2017 at 02:52:28PM +0100, Michal Hocko wrote:  
> > > On Mon 16-01-17 11:09:34, Mel Gorman wrote:
> > > [...]  
> > > > diff --git a/mm/vmscan.c b/mm/vmscan.c
> > > > index 532a2a750952..46aac487b89a 100644
> > > > --- a/mm/vmscan.c
> > > > +++ b/mm/vmscan.c
> > > > @@ -2684,6 +2684,7 @@ static void shrink_zones(struct zonelist
> > > > *zonelist, struct scan_control *sc) continue;
> > > >  
> > > >  			if (sc->priority != DEF_PRIORITY &&
> > > > +			    !buffer_heads_over_limit &&
> > > >  			    !pgdat_reclaimable(zone->zone_pgdat))
> > > >  				continue;	/* Let kswapd
> > > > poll it */  
> > > 
> > > I think we should rather remove pgdat_reclaimable here. This
> > > sounds like a wrong layer to decide whether we want to reclaim
> > > and how much. 
> > 
> > I had considered that but it'd also be important to add the other
> > 32-bit patches you have posted to see the impact. Because of the
> > ratio of LRU pages to slab pages, it may not have an impact but
> > it'd need to be eliminated.  
> 
> OK, Trevor you can pull from
> git://git.kernel.org/pub/scm/linux/kernel/git/mhocko/mm.git tree
> fixes/highmem-node-fixes branch. This contains the current mmotm tree
> + the latest highmem fixes. I also do not expect this would help much
> in your case but as Mel've said we should rule that out at least.

Hi!  The git tree above version oom'd after < 24 hours (3:02am) so
it doesn't solve the bug.  If you need a oom messages dump let me know.

Let me know what to try next, guys, and I'll test it out.

> > Before prototyping such a thing, I'd like to hear the outcome of
> > this heavy hack and then add your 32-bit patches onto the list. If
> > the problem is still there then I'd next look at taking slab pages
> > into account in pgdat_reclaimable() instead of an outright removal
> > that has a much wider impact. If that doesn't work then I'll
> > prototype a heavy-handed forced slab reclaim when lower zones are
> > almost all slab pages.

I don't think I've tried the "heavy hack" patch yet?  It's not in the
mhocko tree I just tried?  Should I try the heavy hack on top of mhocko
git or on vanilla or what?

I also want to mention that these PAE boxes suffer from another
problem/bug that I've worked around for almost a year now.  For some
reason it keeps gnawing at me that it might be related.  The disk I/O
goes to pot on this/these PAE boxes after a certain amount of disk
writes (like some unknown number of GB, around 10-ish maybe).  Like
writes go from 500MB/s to 10MB/s!! Reboot and it's magically 500MB/s
again.  I detail this here:
https://muug.ca/pipermail/roundtable/2016-June/004669.html
My fix was to mem=XG where X is <8 (like 4 or 6) to force the PAE
kernel to be more sane about highmem choices.  I never filed a bug
because I read a ton of stuff saying Linus hates PAE, don't use over
4G, blah blah.  But the other fix is to:
set /proc/sys/vm/highmem_is_dirtyable to 1

I'm not bringing this up to get attention to a new bug, I bring this up
because it smells like it might be related.  If something slowly eats
away at the box's vm to the point that I/O gets horribly slow, perhaps
it's related to the slab and high/lomem issue we have here?  And if
related, it may help to solve the oom bug.  If I'm way off base here,
just ignore my tangent!

The funny thing is I thought mem=XG where X<8 solved the problem, but
it doesn't!  It greatly mitigates it, but I still get subtle slowdown
that gets worse over time (like weeks instead of days).  I now use the
highmem_is_dirtyable on most boxes and that seems to solve it for good
in combo with mem=XG.  Let me note, however, that I have NOT set
highmem_is_dirtyable=1 on the test box I am using for all of this
building/testing, as I wanted the config to stay static while I work
through this oom bug.  (I'm real curious to see if
highmem_is_dirtyable=1 would have any impact on the oom though!)
Thanks!

[toc] | [prev] | [next] | [standalone]


#1562636

FromMichal Hocko <mhocko@kernel.org>
Date2017-01-19 12:40 +0100
Message-ID<t1jeq-X3-5@gated-at.bofh.it>
In reply to#1562532
On Thu 19-01-17 03:48:50, Trevor Cordes wrote:
> On 2017-01-17 Michal Hocko wrote:
> > On Tue 17-01-17 14:21:14, Mel Gorman wrote:
> > > On Tue, Jan 17, 2017 at 02:52:28PM +0100, Michal Hocko wrote:  
> > > > On Mon 16-01-17 11:09:34, Mel Gorman wrote:
> > > > [...]  
> > > > > diff --git a/mm/vmscan.c b/mm/vmscan.c
> > > > > index 532a2a750952..46aac487b89a 100644
> > > > > --- a/mm/vmscan.c
> > > > > +++ b/mm/vmscan.c
> > > > > @@ -2684,6 +2684,7 @@ static void shrink_zones(struct zonelist
> > > > > *zonelist, struct scan_control *sc) continue;
> > > > >  
> > > > >  			if (sc->priority != DEF_PRIORITY &&
> > > > > +			    !buffer_heads_over_limit &&
> > > > >  			    !pgdat_reclaimable(zone->zone_pgdat))
> > > > >  				continue;	/* Let kswapd
> > > > > poll it */  
> > > > 
> > > > I think we should rather remove pgdat_reclaimable here. This
> > > > sounds like a wrong layer to decide whether we want to reclaim
> > > > and how much. 
> > > 
> > > I had considered that but it'd also be important to add the other
> > > 32-bit patches you have posted to see the impact. Because of the
> > > ratio of LRU pages to slab pages, it may not have an impact but
> > > it'd need to be eliminated.  
> > 
> > OK, Trevor you can pull from
> > git://git.kernel.org/pub/scm/linux/kernel/git/mhocko/mm.git tree
> > fixes/highmem-node-fixes branch. This contains the current mmotm tree
> > + the latest highmem fixes. I also do not expect this would help much
> > in your case but as Mel've said we should rule that out at least.
> 
> Hi!  The git tree above version oom'd after < 24 hours (3:02am) so
> it doesn't solve the bug.  If you need a oom messages dump let me know.

Yes please.

> Let me know what to try next, guys, and I'll test it out.
> 
> > > Before prototyping such a thing, I'd like to hear the outcome of
> > > this heavy hack and then add your 32-bit patches onto the list. If
> > > the problem is still there then I'd next look at taking slab pages
> > > into account in pgdat_reclaimable() instead of an outright removal
> > > that has a much wider impact. If that doesn't work then I'll
> > > prototype a heavy-handed forced slab reclaim when lower zones are
> > > almost all slab pages.
> 
> I don't think I've tried the "heavy hack" patch yet?  It's not in the
> mhocko tree I just tried?  Should I try the heavy hack on top of mhocko
> git or on vanilla or what?
> 
> I also want to mention that these PAE boxes suffer from another
> problem/bug that I've worked around for almost a year now.  For some
> reason it keeps gnawing at me that it might be related.  The disk I/O
> goes to pot on this/these PAE boxes after a certain amount of disk
> writes (like some unknown number of GB, around 10-ish maybe).  Like
> writes go from 500MB/s to 10MB/s!! Reboot and it's magically 500MB/s
> again.  I detail this here:
> https://muug.ca/pipermail/roundtable/2016-June/004669.html
> My fix was to mem=XG where X is <8 (like 4 or 6) to force the PAE
> kernel to be more sane about highmem choices.  I never filed a bug
> because I read a ton of stuff saying Linus hates PAE, don't use over
> 4G, blah blah.  But the other fix is to:
> set /proc/sys/vm/highmem_is_dirtyable to 1

Yes this sounds like a dirty memory throttling and there were some
changes in that area. I do not remember when exactly.

> I'm not bringing this up to get attention to a new bug, I bring this up
> because it smells like it might be related.  If something slowly eats
> away at the box's vm to the point that I/O gets horribly slow, perhaps
> it's related to the slab and high/lomem issue we have here?  And if
> related, it may help to solve the oom bug.  If I'm way off base here,
> just ignore my tangent!

From your OOM reports so far it doesn't really seem related because you
never had large number of pages under the writeback when OOM.

The situation with the PAE kernel is unfortunate but it is really hard
to do anything about that considering that the kernel and most its
allocations have to live in a small and scarce lowmem memory. Moreover
the more memory you have to more you have to allocated from that memory.

This is why not only Linus hates 32b systems on a large memory systems.
-- 
Michal Hocko
SUSE Labs

[toc] | [prev] | [next] | [standalone]


#1563320

FromTrevor Cordes <trevor@tecnopolis.ca>
Date2017-01-20 07:40 +0100
Message-ID<t1B1D-3Nl-3@gated-at.bofh.it>
In reply to#1562636

[Multipart message — attachments visible in raw view] — view raw

On 2017-01-19 Michal Hocko wrote:
> On Thu 19-01-17 03:48:50, Trevor Cordes wrote:
> > On 2017-01-17 Michal Hocko wrote:  
> > > On Tue 17-01-17 14:21:14, Mel Gorman wrote:  
> > > > On Tue, Jan 17, 2017 at 02:52:28PM +0100, Michal Hocko
> > > > wrote:    
> > > > > On Mon 16-01-17 11:09:34, Mel Gorman wrote:
> > > > > [...]    
> > > > > > diff --git a/mm/vmscan.c b/mm/vmscan.c
> > > > > > index 532a2a750952..46aac487b89a 100644
> > > > > > --- a/mm/vmscan.c
> > > > > > +++ b/mm/vmscan.c
> > > > > > @@ -2684,6 +2684,7 @@ static void shrink_zones(struct
> > > > > > zonelist *zonelist, struct scan_control *sc) continue;
> > > > > >  
> > > > > >  			if (sc->priority != DEF_PRIORITY &&
> > > > > > +			    !buffer_heads_over_limit &&
> > > > > >  			    !pgdat_reclaimable(zone->zone_pgdat))
> > > > > >  				continue;	/* Let
> > > > > > kswapd poll it */    
> > > > > 
> > > > > I think we should rather remove pgdat_reclaimable here. This
> > > > > sounds like a wrong layer to decide whether we want to reclaim
> > > > > and how much.   
> > > > 
> > > > I had considered that but it'd also be important to add the
> > > > other 32-bit patches you have posted to see the impact. Because
> > > > of the ratio of LRU pages to slab pages, it may not have an
> > > > impact but it'd need to be eliminated.    
> > > 
> > > OK, Trevor you can pull from
> > > git://git.kernel.org/pub/scm/linux/kernel/git/mhocko/mm.git tree
> > > fixes/highmem-node-fixes branch. This contains the current mmotm
> > > tree
> > > + the latest highmem fixes. I also do not expect this would help
> > > much in your case but as Mel've said we should rule that out at
> > > least.  
> > 
> > Hi!  The git tree above version oom'd after < 24 hours (3:02am) so
> > it doesn't solve the bug.  If you need a oom messages dump let me
> > know.  
> 
> Yes please.

The first oom from that night attached.  Note, the oom wasn't as dire
with your mhocko/4.9.0+ as it usually is with stock 4.8.x: my oom
detector and reboot script was able to do its thing cleanly before the
system became unusable.

I'll await further instructions and test right away.  Maybe I'll try a
few tuning ideas until then.  Thanks!

> > Let me know what to try next, guys, and I'll test it out.
> >   
> > > > Before prototyping such a thing, I'd like to hear the outcome of
> > > > this heavy hack and then add your 32-bit patches onto the list.
> > > > If the problem is still there then I'd next look at taking slab
> > > > pages into account in pgdat_reclaimable() instead of an
> > > > outright removal that has a much wider impact. If that doesn't
> > > > work then I'll prototype a heavy-handed forced slab reclaim
> > > > when lower zones are almost all slab pages.  
> > 
> > I don't think I've tried the "heavy hack" patch yet?  It's not in
> > the mhocko tree I just tried?  Should I try the heavy hack on top
> > of mhocko git or on vanilla or what?
> > 
> > I also want to mention that these PAE boxes suffer from another
> > problem/bug that I've worked around for almost a year now.  For some
> > reason it keeps gnawing at me that it might be related.  The disk
> > I/O goes to pot on this/these PAE boxes after a certain amount of
> > disk writes (like some unknown number of GB, around 10-ish maybe).
> > Like writes go from 500MB/s to 10MB/s!! Reboot and it's magically
> > 500MB/s again.  I detail this here:
> > https://muug.ca/pipermail/roundtable/2016-June/004669.html
> > My fix was to mem=XG where X is <8 (like 4 or 6) to force the PAE
> > kernel to be more sane about highmem choices.  I never filed a bug
> > because I read a ton of stuff saying Linus hates PAE, don't use over
> > 4G, blah blah.  But the other fix is to:
> > set /proc/sys/vm/highmem_is_dirtyable to 1  
> 
> Yes this sounds like a dirty memory throttling and there were some
> changes in that area. I do not remember when exactly.

I think my PAE-slow-IO bug started way back in Fedora 22 (4.0?), hard
to know exactly when as I didn't discover the bug for maybe a year as I
didn't realize IO was the problem right away.  Too late to bisect that
one, I guess.  I guess it's not related so we can ignore my tangent!

> > I'm not bringing this up to get attention to a new bug, I bring
> > this up because it smells like it might be related.  If something
> > slowly eats away at the box's vm to the point that I/O gets
> > horribly slow, perhaps it's related to the slab and high/lomem
> > issue we have here?  And if related, it may help to solve the oom
> > bug.  If I'm way off base here, just ignore my tangent!  
> 
> >From your OOM reports so far it doesn't really seem related because
> >you  
> never had large number of pages under the writeback when OOM.
> 
> The situation with the PAE kernel is unfortunate but it is really hard
> to do anything about that considering that the kernel and most its
> allocations have to live in a small and scarce lowmem memory. Moreover
> the more memory you have to more you have to allocated from that
> memory.

You're for sure right that the IO-slow bug was definitely worse the more
ram was in a system!  (The mem=4G really helps alleviate this bug and is
good enough for me.)

> This is why not only Linus hates 32b systems on a large memory
> systems.

Completely off-topic: it would be great if rather than pretending PAE
should work with large RAM (which seems more broken every day), the
kernel guys put out an officially stated policy of a maximum RAM you
can use, and try to have the kernel behave for <= that size, and then
people could use more RAM but clearly "at your own risk, don't bug us
about problems!".  Other than a few posts about Linus hating it,
there's nothing official I can find about it in documentation, etc.  It
gives the (mis)impression that it's perfectly fine to run PAE on a
zillion GB modern system.  Then we later learn the hard way :-)

[toc] | [prev] | [next] | [standalone]


#1563486

FromMel Gorman <mgorman@techsingularity.net>
Date2017-01-20 12:10 +0100
Message-ID<t1FeV-6vs-1@gated-at.bofh.it>
In reply to#1563320
On Fri, Jan 20, 2017 at 12:35:44AM -0600, Trevor Cordes wrote:
> > > Hi!  The git tree above version oom'd after < 24 hours (3:02am) so
> > > it doesn't solve the bug.  If you need a oom messages dump let me
> > > know.  
> > 
> > Yes please.
> 
> The first oom from that night attached.  Note, the oom wasn't as dire
> with your mhocko/4.9.0+ as it usually is with stock 4.8.x: my oom
> detector and reboot script was able to do its thing cleanly before the
> system became unusable.
> 
> I'll await further instructions and test right away.  Maybe I'll try a
> few tuning ideas until then.  Thanks!
> 

Thanks for the OOM report. I was expecting it to be a particular shape and
my expectations were not matched so it took time to consider it further. Can
you try the cumulative patch below? It combines three patches that

1. Allow slab shrinking even if the LRU patches are unreclaimable in
   direct reclaim
2. Shrinks slab based once based on the contents of all memcgs instead
   of shrinking one at a time
3. Tries to shrink slabs if the lowmem usage is too high

Unfortunately it's only boot tested on x86-64 as I didn't get the chance
to setup an i386 test bed.

> > This is why not only Linus hates 32b systems on a large memory
> > systems.
> 
> Completely off-topic: it would be great if rather than pretending PAE
> should work with large RAM (which seems more broken every day), the
> kernel guys put out an officially stated policy of a maximum RAM you
> can use, and try to have the kernel behave for <= that size, and then
> people could use more RAM but clearly "at your own risk, don't bug us
> about problems!".  Other than a few posts about Linus hating it,
> there's nothing official I can find about it in documentation, etc.  It
> gives the (mis)impression that it's perfectly fine to run PAE on a
> zillion GB modern system.  Then we later learn the hard way :-)

The unfortunate reality is that the behaviour is workload dependant so
it's impossible to make a general statement other than "your mileage may
vary considerably".

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 2281ad310d06..76d68a8872c7 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2318,6 +2318,52 @@ static void get_scan_count(struct lruvec *lruvec, struct mem_cgroup *memcg,
 	}
 }
 
+#ifdef CONFIG_HIGHMEM
+static void balance_slab_lowmem(struct pglist_data *pgdat,
+				struct scan_control *sc)
+{
+	unsigned long lru_pages = 0;
+	unsigned long slab_pages = 0;
+	int zid;
+
+	for (zid = 0; zid < MAX_NR_ZONES; zid++) {
+		struct zone *zone = &pgdat->node_zones[zid];
+
+		if (!populated_zone(zone) || !is_highmem_idx(zid))
+			continue;
+
+		lru_pages += zone_page_state(zone, NR_ZONE_INACTIVE_FILE);
+		lru_pages += zone_page_state(zone, NR_ZONE_ACTIVE_FILE);
+		slab_pages += zone_page_state(zone, NR_SLAB_RECLAIMABLE);
+		slab_pages += zone_page_state(zone, NR_SLAB_UNRECLAIMABLE);
+	}
+
+	/*
+	 * Shrink reclaimable slabs if the number of lowmem slab pages is
+	 * over twice the size of LRU pages. Apply pressure relative to
+	 * the imbalance between LRU and slab pages.
+	 */
+	if (slab_pages > lru_pages << 1) {
+		struct reclaim_state *reclaim_state = current->reclaim_state;
+		unsigned long exceed = (lru_pages << 1) - slab_pages;
+		int nid = pgdat->node_id;
+
+		exceed = min(exceed, slab_pages);
+		shrink_slab(sc->gfp_mask, nid, NULL, exceed, slab_pages);
+		if (reclaim_state) {
+			sc->nr_reclaimed += reclaim_state->reclaimed_slab;
+			reclaim_state->reclaimed_slab = 0;
+		}
+	}
+}
+#else
+static void balance_slab_lowmem(struct pglist_data *pgdat,
+				struct scan_control *sc)
+{
+	return false;
+}
+#endif
+
 /*
  * This is a basic per-node page freer.  Used by both kswapd and direct reclaim.
  */
@@ -2336,6 +2382,27 @@ static void shrink_node_memcg(struct pglist_data *pgdat, struct mem_cgroup *memc
 
 	get_scan_count(lruvec, memcg, sc, nr, lru_pages);
 
+	/*
+	 * If direct reclaiming at elevated priority and the node is
+	 * unreclaimable then skip LRU reclaim and let kswapd poll it.
+	 */
+	if (!current_is_kswapd() &&
+	    sc->priority != DEF_PRIORITY &&
+	    !pgdat_reclaimable(pgdat)) {
+		unsigned long nr_scanned;
+
+		/*
+		 * Fake scanning so that slab shrinking will continue. For
+		 * lowmem restricted allocations, shrink aggressively.
+		 */
+		nr_scanned = SWAP_CLUSTER_MAX << (DEF_PRIORITY - sc->priority);
+		if (!(sc->gfp_mask & __GFP_HIGHMEM))
+			nr_scanned = max(nr_scanned, *lru_pages);
+		sc->nr_scanned += nr_scanned;
+
+		return;
+	}
+
 	/* Record the original scan target for proportional adjustments later */
 	memcpy(targets, nr, sizeof(nr));
 
@@ -2369,6 +2436,7 @@ static void shrink_node_memcg(struct pglist_data *pgdat, struct mem_cgroup *memc
 			}
 		}
 
+		balance_slab_lowmem(pgdat, sc);
 		cond_resched();
 
 		if (nr_reclaimed < nr_to_reclaim || scan_adjusted)
@@ -2533,7 +2601,8 @@ static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc)
 			.pgdat = pgdat,
 			.priority = sc->priority,
 		};
-		unsigned long node_lru_pages = 0;
+		unsigned long slab_pressure = 0;
+		unsigned long slab_eligible = 0;
 		struct mem_cgroup *memcg;
 
 		nr_reclaimed = sc->nr_reclaimed;
@@ -2555,12 +2624,8 @@ static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc)
 			scanned = sc->nr_scanned;
 
 			shrink_node_memcg(pgdat, memcg, sc, &lru_pages);
-			node_lru_pages += lru_pages;
-
-			if (memcg)
-				shrink_slab(sc->gfp_mask, pgdat->node_id,
-					    memcg, sc->nr_scanned - scanned,
-					    lru_pages);
+			slab_eligible += lru_pages;
+			slab_pressure += sc->nr_reclaimed - reclaimed;
 
 			/* Record the group's reclaim efficiency */
 			vmpressure(sc->gfp_mask, memcg, false,
@@ -2586,12 +2651,12 @@ static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc)
 
 		/*
 		 * Shrink the slab caches in the same proportion that
-		 * the eligible LRU pages were scanned.
+		 * the eligible LRU pages were scanned. For memcg, this
+		 * will apply the cumulative scanning pressure over all
+		 * memcgs.
 		 */
-		if (global_reclaim(sc))
-			shrink_slab(sc->gfp_mask, pgdat->node_id, NULL,
-				    sc->nr_scanned - nr_scanned,
-				    node_lru_pages);
+		shrink_slab(sc->gfp_mask, pgdat->node_id, NULL, slab_pressure,
+							slab_eligible);
 
 		if (reclaim_state) {
 			sc->nr_reclaimed += reclaim_state->reclaimed_slab;
@@ -2683,10 +2748,6 @@ static void shrink_zones(struct zonelist *zonelist, struct scan_control *sc)
 						 GFP_KERNEL | __GFP_HARDWALL))
 				continue;
 
-			if (sc->priority != DEF_PRIORITY &&
-			    !pgdat_reclaimable(zone->zone_pgdat))
-				continue;	/* Let kswapd poll it */
-
 			/*
 			 * If we already have plenty of memory free for
 			 * compaction in this zone, don't free any more.

[toc] | [prev] | [next] | [standalone]


#1563737

FromMel Gorman <mgorman@techsingularity.net>
Date2017-01-20 17:00 +0100
Message-ID<t1JLA-Gk-23@gated-at.bofh.it>
In reply to#1563486
On Fri, Jan 20, 2017 at 11:02:32AM +0000, Mel Gorman wrote:
> On Fri, Jan 20, 2017 at 12:35:44AM -0600, Trevor Cordes wrote:
> > > > Hi!  The git tree above version oom'd after < 24 hours (3:02am) so
> > > > it doesn't solve the bug.  If you need a oom messages dump let me
> > > > know.  
> > > 
> > > Yes please.
> > 
> > The first oom from that night attached.  Note, the oom wasn't as dire
> > with your mhocko/4.9.0+ as it usually is with stock 4.8.x: my oom
> > detector and reboot script was able to do its thing cleanly before the
> > system became unusable.
> > 
> > I'll await further instructions and test right away.  Maybe I'll try a
> > few tuning ideas until then.  Thanks!
> > 
> 
> Thanks for the OOM report. I was expecting it to be a particular shape and
> my expectations were not matched so it took time to consider it further. Can
> you try the cumulative patch below? It combines three patches that
> 
> 1. Allow slab shrinking even if the LRU patches are unreclaimable in
>    direct reclaim
> 2. Shrinks slab based once based on the contents of all memcgs instead
>    of shrinking one at a time
> 3. Tries to shrink slabs if the lowmem usage is too high
> 
> Unfortunately it's only boot tested on x86-64 as I didn't get the chance
> to setup an i386 test bed.
> 

There was one major flaw in that patch. This version fixes it and
addresses other minor issues. It may still be too agressive shrinking
slab but worth trying out. Thanks.

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 2281ad310d06..2c735ea24a85 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2318,6 +2318,59 @@ static void get_scan_count(struct lruvec *lruvec, struct mem_cgroup *memcg,
 	}
 }
 
+#ifdef CONFIG_HIGHMEM
+static void balance_slab_lowmem(struct pglist_data *pgdat,
+				struct scan_control *sc)
+{
+	unsigned long lru_pages = 0;
+	unsigned long slab_pages = 0;
+	unsigned long managed_pages = 0;
+	int zid;
+
+	for (zid = 0; zid < MAX_NR_ZONES; zid++) {
+		struct zone *zone = &pgdat->node_zones[zid];
+
+		if (!populated_zone(zone) || is_highmem_idx(zid))
+			continue;
+
+		lru_pages += zone_page_state(zone, NR_ZONE_INACTIVE_FILE);
+		lru_pages += zone_page_state(zone, NR_ZONE_ACTIVE_FILE);
+		lru_pages += zone_page_state(zone, NR_ZONE_INACTIVE_ANON);
+		lru_pages += zone_page_state(zone, NR_ZONE_ACTIVE_ANON);
+		slab_pages += zone_page_state(zone, NR_SLAB_RECLAIMABLE);
+		slab_pages += zone_page_state(zone, NR_SLAB_UNRECLAIMABLE);
+	}
+
+	/* Do not balance until LRU and slab exceeds 50% of lowmem */
+	if (lru_pages + slab_pages < (managed_pages >> 1))
+		return;
+
+	/*
+	 * Shrink reclaimable slabs if the number of lowmem slab pages is
+	 * over twice the size of LRU pages. Apply pressure relative to
+	 * the imbalance between LRU and slab pages.
+	 */
+	if (slab_pages > lru_pages << 1) {
+		struct reclaim_state *reclaim_state = current->reclaim_state;
+		unsigned long exceed = slab_pages - (lru_pages << 1);
+		int nid = pgdat->node_id;
+
+		exceed = min(exceed, slab_pages);
+		shrink_slab(sc->gfp_mask, nid, NULL, exceed >> 3, slab_pages);
+		if (reclaim_state) {
+			sc->nr_reclaimed += reclaim_state->reclaimed_slab;
+			reclaim_state->reclaimed_slab = 0;
+		}
+	}
+}
+#else
+static void balance_slab_lowmem(struct pglist_data *pgdat,
+				struct scan_control *sc)
+{
+	return;
+}
+#endif
+
 /*
  * This is a basic per-node page freer.  Used by both kswapd and direct reclaim.
  */
@@ -2336,6 +2389,27 @@ static void shrink_node_memcg(struct pglist_data *pgdat, struct mem_cgroup *memc
 
 	get_scan_count(lruvec, memcg, sc, nr, lru_pages);
 
+	/*
+	 * If direct reclaiming at elevated priority and the node is
+	 * unreclaimable then skip LRU reclaim and let kswapd poll it.
+	 */
+	if (!current_is_kswapd() &&
+	    sc->priority != DEF_PRIORITY &&
+	    !pgdat_reclaimable(pgdat)) {
+		unsigned long nr_scanned;
+
+		/*
+		 * Fake scanning so that slab shrinking will continue. For
+		 * lowmem restricted allocations, shrink aggressively.
+		 */
+		nr_scanned = SWAP_CLUSTER_MAX << (DEF_PRIORITY - sc->priority);
+		if (!(sc->gfp_mask & __GFP_HIGHMEM))
+			nr_scanned = max(nr_scanned, *lru_pages);
+		sc->nr_scanned += nr_scanned;
+
+		return;
+	}
+
 	/* Record the original scan target for proportional adjustments later */
 	memcpy(targets, nr, sizeof(nr));
 
@@ -2435,6 +2509,8 @@ static void shrink_node_memcg(struct pglist_data *pgdat, struct mem_cgroup *memc
 	if (inactive_list_is_low(lruvec, false, sc, true))
 		shrink_active_list(SWAP_CLUSTER_MAX, lruvec,
 				   sc, LRU_ACTIVE_ANON);
+
+	balance_slab_lowmem(pgdat, sc);
 }
 
 /* Use reclaim/compaction for costly allocs or under memory pressure */
@@ -2533,7 +2609,8 @@ static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc)
 			.pgdat = pgdat,
 			.priority = sc->priority,
 		};
-		unsigned long node_lru_pages = 0;
+		unsigned long slab_pressure = 0;
+		unsigned long slab_eligible = 0;
 		struct mem_cgroup *memcg;
 
 		nr_reclaimed = sc->nr_reclaimed;
@@ -2555,12 +2632,8 @@ static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc)
 			scanned = sc->nr_scanned;
 
 			shrink_node_memcg(pgdat, memcg, sc, &lru_pages);
-			node_lru_pages += lru_pages;
-
-			if (memcg)
-				shrink_slab(sc->gfp_mask, pgdat->node_id,
-					    memcg, sc->nr_scanned - scanned,
-					    lru_pages);
+			slab_eligible += lru_pages;
+			slab_pressure += sc->nr_reclaimed - reclaimed;
 
 			/* Record the group's reclaim efficiency */
 			vmpressure(sc->gfp_mask, memcg, false,
@@ -2586,12 +2659,12 @@ static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc)
 
 		/*
 		 * Shrink the slab caches in the same proportion that
-		 * the eligible LRU pages were scanned.
+		 * the eligible LRU pages were scanned. For memcg, this
+		 * will apply the cumulative scanning pressure over all
+		 * memcgs.
 		 */
-		if (global_reclaim(sc))
-			shrink_slab(sc->gfp_mask, pgdat->node_id, NULL,
-				    sc->nr_scanned - nr_scanned,
-				    node_lru_pages);
+		shrink_slab(sc->gfp_mask, pgdat->node_id, NULL, slab_pressure,
+							slab_eligible);
 
 		if (reclaim_state) {
 			sc->nr_reclaimed += reclaim_state->reclaimed_slab;
@@ -2683,10 +2756,6 @@ static void shrink_zones(struct zonelist *zonelist, struct scan_control *sc)
 						 GFP_KERNEL | __GFP_HARDWALL))
 				continue;
 
-			if (sc->priority != DEF_PRIORITY &&
-			    !pgdat_reclaimable(zone->zone_pgdat))
-				continue;	/* Let kswapd poll it */
-
 			/*
 			 * If we already have plenty of memory free for
 			 * compaction in this zone, don't free any more.
-- 
Mel Gorman
SUSE Labs

[toc] | [prev] | [next] | [standalone]


#1564855

FromMel Gorman <mgorman@techsingularity.net>
Date2017-01-23 11:50 +0100
Message-ID<t2Kme-5kk-13@gated-at.bofh.it>
In reply to#1563737
On Sun, Jan 22, 2017 at 06:45:59PM -0600, Trevor Cordes wrote:
> On 2017-01-20 Mel Gorman wrote:
> > > 
> > > Thanks for the OOM report. I was expecting it to be a particular
> > > shape and my expectations were not matched so it took time to
> > > consider it further. Can you try the cumulative patch below? It
> > > combines three patches that
> > > 
> > > 1. Allow slab shrinking even if the LRU patches are unreclaimable in
> > >    direct reclaim
> > > 2. Shrinks slab based once based on the contents of all memcgs
> > > instead of shrinking one at a time
> > > 3. Tries to shrink slabs if the lowmem usage is too high
> > > 
> > > Unfortunately it's only boot tested on x86-64 as I didn't get the
> > > chance to setup an i386 test bed.
> > >   
> > 
> > There was one major flaw in that patch. This version fixes it and
> > addresses other minor issues. It may still be too agressive shrinking
> > slab but worth trying out. Thanks.
> 
> I ran with your patch below and it oom'd on the first night.  It was
> weird, it didn't hang the system, and my rebooter script started a
> reboot but the system never got more than half down before it just sat
> there in a weird state where a local console user could still login but
> not much was working.  So the patches don't seem to solve the problem.
> 
> For the above compile I applied your patches to 4.10.0-rc4+, I hope
> that's ok.
> 

It would be strongly preferred to run them on top of Michal's other
fixes. The main reason it's preferred is because this OOM differs from
earlier ones in that it OOM killed from GFP_NOFS|__GFP_NOFAIL context.
That meant that the slab shrinking could not happen from direct reclaim so
the balancing from my patches would not occur.  As Michal's other patches
affect how kswapd behaves, it's important.

Unfortunately, even that will be race prone for GFP_NOFS callers as
they'll effectively be racing to see if kswapd or another direct
reclaimer can reclaim before the OOM conditions are hit. It is by
design, but it's apparent that a __GFP_NOFAIL request can trigger OOM
relatively easily as it's not necessarily throttled or waiting on kswapd
to complete any work. I'll keep thinking about it.

-- 
Mel Gorman
SUSE Labs

[toc] | [prev] | [next] | [standalone]


#1564865

FromMel Gorman <mgorman@techsingularity.net>
Date2017-01-23 12:10 +0100
Message-ID<t2KFA-5GZ-21@gated-at.bofh.it>
In reply to#1564855
On Mon, Jan 23, 2017 at 10:48:58AM +0000, Mel Gorman wrote:
> On Sun, Jan 22, 2017 at 06:45:59PM -0600, Trevor Cordes wrote:
> > On 2017-01-20 Mel Gorman wrote:
> > > > 
> > > > Thanks for the OOM report. I was expecting it to be a particular
> > > > shape and my expectations were not matched so it took time to
> > > > consider it further. Can you try the cumulative patch below? It
> > > > combines three patches that
> > > > 
> > > > 1. Allow slab shrinking even if the LRU patches are unreclaimable in
> > > >    direct reclaim
> > > > 2. Shrinks slab based once based on the contents of all memcgs
> > > > instead of shrinking one at a time
> > > > 3. Tries to shrink slabs if the lowmem usage is too high
> > > > 
> > > > Unfortunately it's only boot tested on x86-64 as I didn't get the
> > > > chance to setup an i386 test bed.
> > > >   
> > > 
> > > There was one major flaw in that patch. This version fixes it and
> > > addresses other minor issues. It may still be too agressive shrinking
> > > slab but worth trying out. Thanks.
> > 
> > I ran with your patch below and it oom'd on the first night.  It was
> > weird, it didn't hang the system, and my rebooter script started a
> > reboot but the system never got more than half down before it just sat
> > there in a weird state where a local console user could still login but
> > not much was working.  So the patches don't seem to solve the problem.
> > 
> > For the above compile I applied your patches to 4.10.0-rc4+, I hope
> > that's ok.
> > 
> 
> It would be strongly preferred to run them on top of Michal's other
> fixes. The main reason it's preferred is because this OOM differs from
> earlier ones in that it OOM killed from GFP_NOFS|__GFP_NOFAIL context.
> That meant that the slab shrinking could not happen from direct reclaim so
> the balancing from my patches would not occur.  As Michal's other patches
> affect how kswapd behaves, it's important.
> 
> Unfortunately, even that will be race prone for GFP_NOFS callers as
> they'll effectively be racing to see if kswapd or another direct
> reclaimer can reclaim before the OOM conditions are hit. It is by
> design, but it's apparent that a __GFP_NOFAIL request can trigger OOM
> relatively easily as it's not necessarily throttled or waiting on kswapd
> to complete any work. I'll keep thinking about it.
> 

As a slight follow-up albeit without patches, further options are to;

1. In should_reclaim_retry, account for SLAB_RECLAIMABLE as available
   pages when deciding to retry reclaim
2. Stall in should_reclaim_retry for __GFP_NOFAIL|__GFP_NOFS with a
   comment stating that the intent is to allow kswapd make progress
   with the shrinker
3. Stall __GFP_NOFS in direct reclaimer on a workqueue when it's
   failing to make progress to allow kswapd to do some work. This
   may be impaired if kswapd is locked up waiting for a lock held
   by the direct reclaimer
4. Schedule the system workqueue to drain slab for
   __GFP_NOFS|__GFP_NOFAIL.

3 and 4 are extremely heavy handed so we should try them one at a time.

-- 
Mel Gorman
SUSE Labs

[toc] | [prev] | [next] | [standalone]


#1566424

FromMichal Hocko <mhocko@kernel.org>
Date2017-01-25 10:50 +0100
Message-ID<t3snf-8uI-11@gated-at.bofh.it>
In reply to#1564865
On Mon 23-01-17 11:04:12, Mel Gorman wrote:
[...]
> 1. In should_reclaim_retry, account for SLAB_RECLAIMABLE as available
>    pages when deciding to retry reclaim

I am pretty sure I have considered this but then decided to not go that
way. I do not remember details so I will think about this some more. It
might have been just "let's wait for the real issue here". Anyway we can
give it a try and it would be as simple as
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 94ebd30d0f09..87221491be84 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3566,7 +3566,7 @@ should_reclaim_retry(gfp_t gfp_mask, unsigned order,
 		unsigned long min_wmark = min_wmark_pages(zone);
 		bool wmark;
 
-		available = reclaimable = zone_reclaimable_pages(zone);
+		available = reclaimable = zone_reclaimable_pages(zone) + zone_page_state_snapshot(zone, NR_SLAB_RECLAIMABLE);
 		available -= DIV_ROUND_UP((*no_progress_loops) * available,
 					  MAX_RECLAIM_RETRIES);
 		available += zone_page_state_snapshot(zone, NR_FREE_PAGES);

I am not sure it would really help much on its own without further
changes to how we scale LRU->slab scanning. Could you give this a try
on top of the mmotm or linux-next tree?

> 2. Stall in should_reclaim_retry for __GFP_NOFAIL|__GFP_NOFS with a
>    comment stating that the intent is to allow kswapd make progress
>    with the shrinker

The current mmotm tree doesnt need this because we no longer trigger the
oom killer for this combinations of flags.

> 3. Stall __GFP_NOFS in direct reclaimer on a workqueue when it's
>    failing to make progress to allow kswapd to do some work. This
>    may be impaired if kswapd is locked up waiting for a lock held
>    by the direct reclaimer
> 4. Schedule the system workqueue to drain slab for
>    __GFP_NOFS|__GFP_NOFAIL.
> 
> 3 and 4 are extremely heavy handed so we should try them one at a time.

I am not even sure they are really necessary.
-- 
Michal Hocko
SUSE Labs

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | linux.kernel


csiph-web