Re: Free memory never fully used, swapping

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Simon Kirby
Date: Thursday, November 25, 2010 - 2:03 am

On Thu, Nov 25, 2010 at 09:07:54AM +0800, Shaohua Li wrote:


There are actually a few problems here.  I think they are worth looking
at them separately, unless "don't use order 3 allocations" is a valid
statement, in which case we should fix slub.

The funny thing here is that slub.c's allocate_slab() calls alloc_pages()
with flags | __GFP_NOWARN | __GFP_NORETRY, and intentionally tries a
lower order allocation automatically if it fails.  This is why there is
no allocation failure warning when this happens.  However, it is too late
-- kswapd is woken and it ties to bring order 3 up to the watermark. 
If we hacked __alloc_pages_slowpath() to not wake kswapd when
__GFP_NOWARN is set, we would never see this problem and the slub
optimization might still mostly work.  Either way, we should "fix" slub
or "fix" order-3 allocations, so that other people who are using slub
don't hit the same problem.

kswapd is throwing out many times what is needed for the order 3
watermark to be met.  It seems to be not as bad now, but look at these
pages being reclaimed (200ms intervals, whitespace-packed buddyinfo
followed by nr_pages_free calculation and final order-3 watermark test,
kswapd woken after the second sample):

  Zone order:0      1     2     3    4   5  6 7 8 9 A nr_free or3-low-chk

 DMA32   20374  35116   975     1    2   5  1 0 0 0 0   94770 257 <= 256
 DMA32   20480  35211   870     1    1   5  1 0 0 0 0   94630 241 <= 256
(kswapd wakes, gobble gobble)
 DMA32   24387  37009  2910   297  100   5  1 0 0 0 0  114245 4193 <= 256
 DMA32   36169  37787  4676   637  110   5  1 0 0 0 0  137527 7073 <= 256
 DMA32   63443  40620  5716   982  144   5  1 0 0 0 0  177931 10377 <= 256
 DMA32   65866  57006  6462  1180  158   5  1 0 0 0 0  217918 12185 <= 256
 DMA32   67188  66779  9328  1893  208   5  1 0 0 0 0  256754 18689 <= 256
 DMA32   67909  67356 18307  2268  235   5  1 0 0 0 0  297977 22121 <= 256
 DMA32   68333  67419 20786  4192  298   7  1 0 0 0 0  324907 38585 <= 256
 DMA32   69872  68096 21580  5141  326   7  1 0 0 0 0  339016 46625 <= 256
 DMA32   69959  67970 22339  5657  371  10  1 0 0 0 0  346831 51569 <= 256
 DMA32   70017  67946 22363  6078  417  11  1 0 0 0 0  351073 55705 <= 256
 DMA32   70023  67949 22376  6204  439  12  1 0 0 0 0  352529 57097 <= 256
 DMA32   70045  67937 22380  6262  451  12  1 0 0 0 0  353199 57753 <= 256
 DMA32   70062  67939 22378  6298  456  12  1 0 0 0 0  353580 58121 <= 256
 DMA32   70079  67959 22388  6370  458  12  1 0 0 0 0  354285 58729 <= 256
 DMA32   70079  67959 22388  6387  460  12  1 0 0 0 0  354453 58897 <= 256
 DMA32   70076  67954 22387  6393  460  12  1 0 0 0 0  354484 58945 <= 256
 DMA32   70105  67975 22385  6466  468  12  1 0 0 0 0  355259 59657 <= 256
 DMA32   70110  67972 22387  6466  470  12  1 0 0 0 0  355298 59689 <= 256
 DMA32   70152  67989 22393  6476  470  12  1 0 0 0 0  355478 59769 <= 256
 DMA32   70175  67991 22401  6493  471  12  1 0 0 0 0  355689 59921 <= 256
 DMA32   70175  67991 22401  6493  471  12  1 0 0 0 0  355689 59921 <= 256
 DMA32   70175  67991 22401  6493  471  12  1 0 0 0 0  355689 59921 <= 256
 DMA32   70192  67990 22401  6495  471  12  1 0 0 0 0  355720 59937 <= 256
 DMA32   70192  67988 22401  6496  471  12  1 0 0 0 0  355724 59945 <= 256
 DMA32   70099  68061 22467  6602  477  12  1 0 0 0 0  356985 60889 <= 256
 DMA32   70099  68062 22467  6602  477  12  1 0 0 0 0  356987 60889 <= 256
 DMA32   70099  68062 22467  6602  477  12  1 0 0 0 0  356987 60889 <= 256
 DMA32   70099  68062 22467  6603  477  12  1 0 0 0 0  356995 60897 <= 256
(kswapd sleeps)

Normal zone at the same time (shown separately for clarity):

Normal     452      1     0     0    0   0  0 0 0 0 0     454 -5 <= 238
Normal     452      1     0     0    0   0  0 0 0 0 0     454 -5 <= 238
(kswapd wakes)
Normal    7618     76     0     0    0   0  0 0 0 0 0    7770 145 <= 238
Normal    8860     73     1     0    0   0  0 0 0 0 0    9010 143 <= 238
Normal    8929     25     0     0    0   0  0 0 0 0 0    8979 43 <= 238
Normal    8917      0     0     0    0   0  0 0 0 0 0    8917 -7 <= 238
Normal    8978     16     0     0    0   0  0 0 0 0 0    9010 25 <= 238
Normal    9064      4     0     0    0   0  0 0 0 0 0    9072 1 <= 238
Normal    9068      2     0     0    0   0  0 0 0 0 0    9072 -3 <= 238
Normal    8992      9     0     0    0   0  0 0 0 0 0    9010 11 <= 238
Normal    9060      6     0     0    0   0  0 0 0 0 0    9072 5 <= 238
Normal    9010      0     0     0    0   0  0 0 0 0 0    9010 -7 <= 238
Normal    8907      5     0     0    0   0  0 0 0 0 0    8917 3 <= 238
Normal    8576      0     0     0    0   0  0 0 0 0 0    8576 -7 <= 238
Normal    8018      0     0     0    0   0  0 0 0 0 0    8018 -7 <= 238
Normal    6778      0     0     0    0   0  0 0 0 0 0    6778 -7 <= 238
Normal    6189      0     0     0    0   0  0 0 0 0 0    6189 -7 <= 238
Normal    6220      0     0     0    0   0  0 0 0 0 0    6220 -7 <= 238
Normal    6096      0     0     0    0   0  0 0 0 0 0    6096 -7 <= 238
Normal    6251      0     0     0    0   0  0 0 0 0 0    6251 -7 <= 238
Normal    6127      0     0     0    0   0  0 0 0 0 0    6127 -7 <= 238
Normal    6218      1     0     0    0   0  0 0 0 0 0    6220 -5 <= 238
Normal    6034      0     0     0    0   0  0 0 0 0 0    6034 -7 <= 238
Normal    6065      0     0     0    0   0  0 0 0 0 0    6065 -7 <= 238
Normal    6189      0     0     0    0   0  0 0 0 0 0    6189 -7 <= 238
Normal    6189      0     0     0    0   0  0 0 0 0 0    6189 -7 <= 238
Normal    6096      0     0     0    0   0  0 0 0 0 0    6096 -7 <= 238
Normal    6127      0     0     0    0   0  0 0 0 0 0    6127 -7 <= 238
Normal    6158      0     0     0    0   0  0 0 0 0 0    6158 -7 <= 238
Normal    6127      0     0     0    0   0  0 0 0 0 0    6127 -7 <= 238
(kswapd sleeps -- maybe too much turkey)

DMA32 get so much reclaimed that the watermark test succeeded long ago.
Meanwhile, Normal is being reclaimed as well, but because it's fighting
with allocations, it tries for a while and eventually succeeds (I think),
but the 200ms samples didn't catch it.

KOSAKI Motohiro, I'm interested in your commit 73ce02e9.  This seems
to be similar to this problem, but your change is not working here. 
We're seeing kswapd run without sleeping, KSWAPD_SKIP_CONGESTION_WAIT
is increasing (so has_under_min_watermark_zone is true), and pageoutrun
increasing all the time.  This means that balance_pgdat() keeps being
called, but sleeping_prematurely() is returning true, so kswapd() just
keeps re-calling balance_pgdat().  If your approach is correct to stop
kswapd here, the problem seems to be that balance_pgdat's copy of order
and sc.order is being set to 0, but not pgdat->kswapd_max_order, so
kswapd never really sleeps.  How is this supposed to work?

Our allocation load here is mostly file pages, some anon pages, and
relatively little slab and anything else.

Simon-
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Free memory never fully used, swapping, Simon Kirby, (Mon Nov 15, 12:52 pm)
Re: Free memory never fully used, swapping, Andrew Morton, (Mon Nov 22, 4:44 pm)
Re: Free memory never fully used, swapping, Simon Kirby, (Mon Nov 22, 6:34 pm)
Re: Free memory never fully used, swapping, Dave Hansen, (Tue Nov 23, 1:35 am)
Re: Free memory never fully used, swapping, Mel Gorman, (Tue Nov 23, 3:04 am)
Re: Free memory never fully used, swapping, Simon Kirby, (Tue Nov 23, 11:43 pm)
Re: Free memory never fully used, swapping, Simon Kirby, (Wed Nov 24, 1:46 am)
Re: Free memory never fully used, swapping, Mel Gorman, (Wed Nov 24, 2:27 am)
Re: Free memory never fully used, swapping, Simon Kirby, (Wed Nov 24, 12:17 pm)
Re: Free memory never fully used, swapping, Shaohua Li, (Wed Nov 24, 6:07 pm)
Re: Free memory never fully used, swapping, KOSAKI Motohiro, (Wed Nov 24, 6:18 pm)
Re: Free memory never fully used, swapping, Simon Kirby, (Thu Nov 25, 2:03 am)
Re: Free memory never fully used, swapping, KOSAKI Motohiro, (Thu Nov 25, 3:18 am)
Re: Free memory never fully used, swapping, KOSAKI Motohiro, (Thu Nov 25, 3:51 am)
Re: Free memory never fully used, swapping, Mel Gorman, (Thu Nov 25, 9:12 am)
Re: Free memory never fully used, swapping, Mel Gorman, (Thu Nov 25, 9:15 am)
Re: Free memory never fully used, swapping, Simon Kirby, (Thu Nov 25, 10:13 am)
Re: Free memory never fully used, swapping, KOSAKI Motohiro, (Thu Nov 25, 5:07 pm)
Re: Free memory never fully used, swapping, KOSAKI Motohiro, (Thu Nov 25, 5:33 pm)
Re: Free memory never fully used, swapping, Shaohua Li, (Thu Nov 25, 6:05 pm)
Re: Free memory never fully used, swapping, Mel Gorman, (Thu Nov 25, 6:25 pm)
Re: Free memory never fully used, swapping, Shaohua Li, (Thu Nov 25, 7:00 pm)
Re: Free memory never fully used, swapping, Shaohua Li, (Thu Nov 25, 7:05 pm)
Re: Free memory never fully used, swapping, KOSAKI Motohiro, (Thu Nov 25, 7:31 pm)
Re: Free memory never fully used, swapping, Shaohua Li, (Thu Nov 25, 7:40 pm)
Re: Free memory never fully used, swapping, KOSAKI Motohiro, (Fri Nov 26, 2:18 am)
Re: Free memory never fully used, swapping, KOSAKI Motohiro, (Fri Nov 26, 4:03 am)
Re: Free memory never fully used, swapping, Mel Gorman, (Fri Nov 26, 4:11 am)
Re: Free memory never fully used, swapping, Christoph Lameter, (Fri Nov 26, 8:48 am)
Re: Free memory never fully used, swapping, Shaohua Li, (Sun Nov 28, 6:03 pm)
Re: Free memory never fully used, swapping, KOSAKI Motohiro, (Sun Nov 28, 6:13 pm)
Re: Free memory never fully used, swapping, KOSAKI Motohiro, (Mon Nov 29, 2:31 am)
Re: Free memory never fully used, swapping, KOSAKI Motohiro, (Mon Nov 29, 5:25 pm)
Re: Free memory never fully used, swapping, KOSAKI Motohiro, (Mon Nov 29, 11:31 pm)
Re: Free memory never fully used, swapping, Simon Kirby, (Tue Nov 30, 1:22 am)
Re: Free memory never fully used, swapping, Simon Kirby, (Tue Nov 30, 2:13 am)
Re: Free memory never fully used, swapping, Mel Gorman, (Tue Nov 30, 3:41 am)
Re: Free memory never fully used, swapping, KOSAKI Motohiro, (Tue Nov 30, 4:19 am)
Re: Free memory never fully used, swapping, Christoph Lameter, (Tue Nov 30, 12:10 pm)
Re: Free memory never fully used, swapping, Christoph Lameter, (Tue Nov 30, 12:13 pm)
Re: Free memory never fully used, swapping, KOSAKI Motohiro, (Wed Dec 1, 3:17 am)
Re: Free memory never fully used, swapping, Christoph Lameter, (Wed Dec 1, 8:29 am)
Re: Free memory never fully used, swapping, KOSAKI Motohiro, (Wed Dec 1, 7:44 pm)
Re: Free memory never fully used, swapping, Christoph Lameter, (Thu Dec 2, 7:39 am)