Skip to contentSkip to conversation

mm: fix negative nr_isolated counts

PATCH In review Hugh Dickins 5 participants 6 messages Feb 11, 2015 – Feb 12, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: fix negative nr_isolated counts

The vmstat interfaces are good at hiding negative counts (at least when CONFIG_SMP); but if you peer behind the curtain, you find that nr_isolated_anon and nr_isolated_file soon go negative, and grow ever more negative: so they can absorb larger and larger numbers of isolated pages, yet still appear to be zero.

I'm happy to avoid a congestion_wait() when too_many_isolated() myself; but I guess it's there for a good reason, in which case we ought to get too_many_isolated() working again.

The imbalance comes from isolate_migratepages()'s ISOLATE_ABORT case:
putback_movable_pages() decrements the NR_ISOLATED counts, but we forgot to call acct_isolated() to increment them.

Fixes edc2ca612496 ("mm, compaction: move pageblock checks up from isolate_migratepages_range()")
Cc [email protected] # v3.18+

---

 mm/compaction.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
mm/compaction.c +3 -1
@@ -1015,8 +1015,10 @@ static isolate_migrate_t isolate_migrate
 		low_pfn = isolate_migratepages_block(cc, low_pfn, end_pfn,
 								isolate_mode);
 
-		if (!low_pfn || cc->contended)
+		if (!low_pfn || cc->contended) {
+			acct_isolated(zone, cc);
 			return ISOLATE_ABORT;
+		}
 
 		/*
 		 * Either we isolated something and proceed with migration. Or

--
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>

Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Hugh Dickins

The vmstat interfaces are good at hiding negative counts (at least when CONFIG_SMP); but if you peer behind the curtain, you find that nr_isolated_anon and nr_isolated_file soon go negative, and grow ever more negative: so they can absorb larger and larger numbers of isolated pages, yet still appear to be zero.

I'm happy to avoid a congestion_wait() when too_many_isolated() myself; but I guess it's there for a good reason, in which case we ought to get too_many_isolated() working again.

Quoted 5 lines

The imbalance comes from isolate_migratepages()'s ISOLATE_ABORT case:
putback_movable_pages() decrements the NR_ISOLATED counts, but we forgot to call acct_isolated() to increment them.

Fixes edc2ca612496 ("mm, compaction: move pageblock checks up from isolate_migratepages_range()")

Ccing Joonsoo for completeness, as it seems he contributed to this part [1] (to fix another bug of mine, not trying to dismiss responsibility)

But yeah it looks correct. Thanks for finding and fixing!

[1] https://lkml.org/lkml/2014/9/29/60

Quoted 12 lines

---

  mm/compaction.c |    4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
mm/compaction.c +0 -0
@@ -1015,8 +1015,10 @@ static isolate_migrate_t isolate_migrate
  		low_pfn = isolate_migratepages_block(cc, low_pfn, end_pfn,

mm/compaction.c static isolate_migrate_t isolate_migrate · line 1024

Quoted 10 lines
mm/compaction.c +3 -1
  								isolate_mode);
 
-		if (!low_pfn || cc->contended)
+		if (!low_pfn || cc->contended) {
+			acct_isolated(zone, cc);
  			return ISOLATE_ABORT;
+		}
 
  		/*
  		 * Either we isolated something and proceed with migration. Or

--
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>

Acked-by
#2 lore raw
Quoted 15 lines · Vlastimil Babka
Quoted 14 lines · Hugh Dickins

The vmstat interfaces are good at hiding negative counts (at least when CONFIG_SMP); but if you peer behind the curtain, you find that nr_isolated_anon and nr_isolated_file soon go negative, and grow ever more negative: so they can absorb larger and larger numbers of isolated pages, yet still appear to be zero.

I'm happy to avoid a congestion_wait() when too_many_isolated() myself; but I guess it's there for a good reason, in which case we ought to get too_many_isolated() working again.

The imbalance comes from isolate_migratepages()'s ISOLATE_ABORT case:
putback_movable_pages() decrements the NR_ISOLATED counts, but we forgot to call acct_isolated() to increment them.

Quoted 7 lines
Quoted 1 line
Fixes edc2ca612496 ("mm, compaction: move pageblock checks up from isolate_migratepages_range()")

Ccing Joonsoo for completeness, as it seems he contributed to this part [1] (to fix another bug of mine, not trying to dismiss responsibility)

But yeah it looks correct. Thanks for finding and fixing!

Yes, it looks correct to me.

Quoted 7 lines

[1] https://lkml.org/lkml/2014/9/29/60

Quoted 2 lines

--
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>

maintainer
#3 lore raw
In reply to Hugh Dickins
Quoted 6 lines · On Tue, 10 Feb 2015 23:06:09 -0800 (PST) Hugh Dickins <[email protected]> wrote:

The vmstat interfaces are good at hiding negative counts (at least when CONFIG_SMP); but if you peer behind the curtain, you find that nr_isolated_anon and nr_isolated_file soon go negative, and grow ever more negative: so they can absorb larger and larger numbers of isolated pages, yet still appear to be zero.

Quoted 7 lines

I'm happy to avoid a congestion_wait() when too_many_isolated() myself; but I guess it's there for a good reason, in which case we ought to get too_many_isolated() working again.

The imbalance comes from isolate_migratepages()'s ISOLATE_ABORT case:
putback_movable_pages() decrements the NR_ISOLATED counts, but we forgot to call acct_isolated() to increment them.

So if I'm understanding this correctly, shrink_inactive_list()'s call to congestion_wait() basically never happens?

If so I'm pretty reluctant to merge this up until it has had plenty of careful testing - there's a decent chance that it will make the kernel behave worse.

Quoted 3 lines
Fixes edc2ca612496 ("mm, compaction: move pageblock checks up from isolate_migratepages_range()")
Cc [email protected] # v3.18+

And why -stable? What user-visible problem is the bug causing?

--
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>

#4 lore raw
Quoted 12 lines · Andrew Morton
Quoted 10 lines · On Tue, 10 Feb 2015 23:06:09 -0800 (PST) Hugh Dickins <[email protected]> wrote:

The vmstat interfaces are good at hiding negative counts (at least when CONFIG_SMP); but if you peer behind the curtain, you find that nr_isolated_anon and nr_isolated_file soon go negative, and grow ever more negative: so they can absorb larger and larger numbers of isolated pages, yet still appear to be zero.

I'm happy to avoid a congestion_wait() when too_many_isolated() myself; but I guess it's there for a good reason, in which case we ought to get too_many_isolated() working again.

Quoted 6 lines
Quoted 3 lines

The imbalance comes from isolate_migratepages()'s ISOLATE_ABORT case:
putback_movable_pages() decrements the NR_ISOLATED counts, but we forgot to call acct_isolated() to increment them.

So if I'm understanding this correctly, shrink_inactive_list()'s call to congestion_wait() basically never happens?

I think so, the more the counters go negative, the less chance of congestion_wait() to happen from there.

Quoted 3 lines

If so I'm pretty reluctant to merge this up until it has had plenty of careful testing - there's a decent chance that it will make the kernel behave worse.

You mean "worse" by letting shrink_inactive_list() call congestion_wait() again, as it used to before 3.18, since 2009 it seems?
Maybe it's not needed anymore, but it IMHO shouldn't get disabled by accident, but properly evaluated and removed. Hugh's patch just fixes the accidental disable.

Quoted 6 lines
Quoted 3 lines
Fixes edc2ca612496 ("mm, compaction: move pageblock checks up from isolate_migratepages_range()")
Cc [email protected] # v3.18+

And why -stable? What user-visible problem is the bug causing?

Commit 35cd78156c "vmscan: throttle direct reclaim when too many pages are isolated already" by Rik seems to have introduced this congestion_wait() based on too_many_isolated(). The bug it was fixing:

"When way too many processes go into direct reclaim, it is possible
for all of the pages to be taken off the LRU. One result of this is that the next process in the page reclaim code thinks there are no reclaimable pages left and triggers an out of memory kill."

So either this is now prevented by something else and too_many_isolated() could go away, or we should restore its functionality. Any idea, Rik?

--
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>

#5 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 14 lines · Vlastimil Babka
Quoted 6 lines · Andrew Morton
Quoted 3 lines
Fixes edc2ca612496 ("mm, compaction: move pageblock checks up

from isolate_migratepages_range()") Signed-off-by: Hugh Dickins <[email protected]> Cc: [email protected] # v3.18+

And why -stable? What user-visible problem is the bug causing?

Commit 35cd78156c "vmscan: throttle direct reclaim when too many pages are isolated already" by Rik seems to have introduced this congestion_wait() based on too_many_isolated(). The bug it was fixing:

Quoted 8 lines

"When way too many processes go into direct reclaim, it is possible for all of the pages to be taken off the LRU. One result of this is that the next process in the page reclaim code thinks there are no reclaimable pages left and triggers an out of memory kill."

So either this is now prevented by something else and too_many_isolated() could go away, or we should restore its functionality. Any idea, Rik?

I don't think that bug is prevented.

I have seen reports of OOM kills happening while the system still has a lot of reclaimable page cache pages.

This might actually help explain that bug...

- --
All rights reversed
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQEcBAEBAgAGBQJU3MLdAAoJEM553pKExN6DheAH/RgOqPr/HwzgaalKd2JcQcSx xuIL/AhjIf8SYIHO5TTr00lF6mMpXfLs6+7UzYlICYmJ+wA4jZ6MapfpqYH/nkYG tCS/8kMvH+rfkrUMp8NDz1od4Akp9w153xpA/6rmNrGTrcwXY9L4R2ANj30sJ9bw 5aRvwsYKAbGjXwJqDFbkR6UySthEZ8wPlOZpjJyhBoA9kMx+hP/Aka+qjYkiS7Ny DfMuEjaNl8dsFZuulc7olhKNSXLyQPNmZt+oQCfb82KH78r6qpH2mhIrRtTunY6z 9iLHrxRgN2j8ZtDPFVaxMWQ3CQlaBZgTigSx1p+MTYVq8nfUe2HhkBgs2EKuV18= =hWac
-----END PGP SIGNATURE-----

--
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>