From: Hugh Dickins <hughd@google.com> To: Alex Shi <alex.shi@linux.alibaba.com> Cc: akpm@linux-foundation.org, mgorman@techsingularity.net, tj@kernel.org, khlebnikov@yandex-team.ru, daniel.m.jordan@oracle.com, yang.shi@linux.alibaba.com, willy@infradead.org, hannes@cmpxchg.org, lkp@intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, shakeelb@google.com, iamjoonsoo.kim@lge.com, richard.weiyang@gmail.com Subject: [PATCH alexv12 1/2] mm/compaction: fix isolate_migratepages_block() fails Date: Thu, 11 Jun 2020 15:28:54 -0700 (PDT) [thread overview] Message-ID: <alpine.LSU.2.11.2006111526290.10801@eggly.anvils> (raw) Fix lots of crashes under compaction load: isolate_migratepages_block() must clean up appropriately when rejecting a page, setting PageLRU again if it had been cleared; and a put_page() after get_page_unless_zero() cannot safely be done while holding locked_lruvec - it may turn out to be the final put_page(), which will take an lruvec lock when PageLRU. Signed-off-by: Hugh Dickins <hughd@google.com> --- These fixes should be folded into 10/16 and 12/16, I have not tried to figure out what belongs in which. mm/compaction.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) --- alexv12/mm/compaction.c 2020-06-11 13:24:52.037154793 -0700 +++ hughd/mm/compaction.c 2020-06-11 13:48:10.437046025 -0700 @@ -879,6 +879,7 @@ isolate_migratepages_block(struct compac if (!valid_page && IS_ALIGNED(low_pfn, pageblock_nr_pages)) { if (!cc->ignore_skip_hint && get_pageblock_skip(page)) { low_pfn = end_pfn; + page = NULL; goto isolate_abort; } valid_page = page; @@ -971,10 +972,8 @@ isolate_migratepages_block(struct compac goto isolate_fail; /* Try isolate the page */ - if (!TestClearPageLRU(page)) { - put_page(page); - goto isolate_fail; - } + if (!TestClearPageLRU(page)) + goto isolate_fail_put; rcu_read_lock(); lruvec = mem_cgroup_page_lruvec(page, pgdat); @@ -1005,7 +1004,8 @@ isolate_migratepages_block(struct compac */ if (unlikely(PageCompound(page) && !cc->alloc_contig)) { low_pfn += compound_nr(page) - 1; - goto isolate_fail; + SetPageLRU(page); + goto isolate_fail_put; } } else rcu_read_unlock(); @@ -1038,6 +1038,15 @@ isolate_success: } continue; + +isolate_fail_put: + /* Avoid potential deadlock in freeing page under lru_lock */ + if (locked_lruvec) { + unlock_page_lruvec_irqrestore(locked_lruvec, flags); + locked_lruvec = NULL; + } + put_page(page); + isolate_fail: if (!skip_on_failure) continue; @@ -1074,10 +1083,15 @@ isolate_fail: */ if (unlikely(low_pfn > end_pfn)) low_pfn = end_pfn; + page = NULL; isolate_abort: if (locked_lruvec) unlock_page_lruvec_irqrestore(locked_lruvec, flags); + if (page) { + SetPageLRU(page); + put_page(page); + } /* * Updated the cached scanner pfn once the pageblock has been scanned
WARNING: multiple messages have this Message-ID (diff)
From: Hugh Dickins <hughd-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org> To: Alex Shi <alex.shi-KPsoFbNs7GizrGE5bRqYAgC/G2K4zDHf@public.gmane.org> Cc: akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org, mgorman-3eNAlZScCAx27rWaFMvyedHuzzzSOjJt@public.gmane.org, tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, khlebnikov-XoJtRXgx1JseBXzfvpsJ4g@public.gmane.org, daniel.m.jordan-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org, yang.shi-KPsoFbNs7GizrGE5bRqYAgC/G2K4zDHf@public.gmane.org, willy-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org, hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org, lkp-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org, linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, shakeelb-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org, iamjoonsoo.kim-Hm3cg6mZ9cc@public.gmane.org, richard.weiyang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Subject: [PATCH alexv12 1/2] mm/compaction: fix isolate_migratepages_block() fails Date: Thu, 11 Jun 2020 15:28:54 -0700 (PDT) [thread overview] Message-ID: <alpine.LSU.2.11.2006111526290.10801@eggly.anvils> (raw) Fix lots of crashes under compaction load: isolate_migratepages_block() must clean up appropriately when rejecting a page, setting PageLRU again if it had been cleared; and a put_page() after get_page_unless_zero() cannot safely be done while holding locked_lruvec - it may turn out to be the final put_page(), which will take an lruvec lock when PageLRU. Signed-off-by: Hugh Dickins <hughd-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org> --- These fixes should be folded into 10/16 and 12/16, I have not tried to figure out what belongs in which. mm/compaction.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) --- alexv12/mm/compaction.c 2020-06-11 13:24:52.037154793 -0700 +++ hughd/mm/compaction.c 2020-06-11 13:48:10.437046025 -0700 @@ -879,6 +879,7 @@ isolate_migratepages_block(struct compac if (!valid_page && IS_ALIGNED(low_pfn, pageblock_nr_pages)) { if (!cc->ignore_skip_hint && get_pageblock_skip(page)) { low_pfn = end_pfn; + page = NULL; goto isolate_abort; } valid_page = page; @@ -971,10 +972,8 @@ isolate_migratepages_block(struct compac goto isolate_fail; /* Try isolate the page */ - if (!TestClearPageLRU(page)) { - put_page(page); - goto isolate_fail; - } + if (!TestClearPageLRU(page)) + goto isolate_fail_put; rcu_read_lock(); lruvec = mem_cgroup_page_lruvec(page, pgdat); @@ -1005,7 +1004,8 @@ isolate_migratepages_block(struct compac */ if (unlikely(PageCompound(page) && !cc->alloc_contig)) { low_pfn += compound_nr(page) - 1; - goto isolate_fail; + SetPageLRU(page); + goto isolate_fail_put; } } else rcu_read_unlock(); @@ -1038,6 +1038,15 @@ isolate_success: } continue; + +isolate_fail_put: + /* Avoid potential deadlock in freeing page under lru_lock */ + if (locked_lruvec) { + unlock_page_lruvec_irqrestore(locked_lruvec, flags); + locked_lruvec = NULL; + } + put_page(page); + isolate_fail: if (!skip_on_failure) continue; @@ -1074,10 +1083,15 @@ isolate_fail: */ if (unlikely(low_pfn > end_pfn)) low_pfn = end_pfn; + page = NULL; isolate_abort: if (locked_lruvec) unlock_page_lruvec_irqrestore(locked_lruvec, flags); + if (page) { + SetPageLRU(page); + put_page(page); + } /* * Updated the cached scanner pfn once the pageblock has been scanned
next reply other threads:[~2020-06-11 22:29 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-06-11 22:28 Hugh Dickins [this message] 2020-06-11 22:28 ` [PATCH alexv12 1/2] mm/compaction: fix isolate_migratepages_block() fails Hugh Dickins 2020-06-11 22:28 ` Hugh Dickins
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=alpine.LSU.2.11.2006111526290.10801@eggly.anvils \ --to=hughd@google.com \ --cc=akpm@linux-foundation.org \ --cc=alex.shi@linux.alibaba.com \ --cc=cgroups@vger.kernel.org \ --cc=daniel.m.jordan@oracle.com \ --cc=hannes@cmpxchg.org \ --cc=iamjoonsoo.kim@lge.com \ --cc=khlebnikov@yandex-team.ru \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=lkp@intel.com \ --cc=mgorman@techsingularity.net \ --cc=richard.weiyang@gmail.com \ --cc=shakeelb@google.com \ --cc=tj@kernel.org \ --cc=willy@infradead.org \ --cc=yang.shi@linux.alibaba.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.