From: Zi Yan <ziy@nvidia.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>, <linux-mm@kvack.org>,
Rik van Riel <riel@surriel.com>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] mm/compaction: count pages and stop correctly during page isolation.
Date: Fri, 30 Oct 2020 11:18:07 -0400 [thread overview]
Message-ID: <7C9FAF14-075D-4E29-B5F5-ADF15E687C3A@nvidia.com> (raw)
In-Reply-To: <16bdfad8-05f9-6ecf-0db6-c2dcf8e60309@suse.cz>
[-- Attachment #1: Type: text/plain, Size: 2336 bytes --]
On 30 Oct 2020, at 10:50, Vlastimil Babka wrote:
> On 10/29/20 9:04 PM, Zi Yan wrote:
>> From: Zi Yan <ziy@nvidia.com>
>>
>> In isolate_migratepages_block, when cc->alloc_contig is true, we are
>> able to isolate compound pages, nr_migratepages and nr_isolated did not
>> count compound pages correctly, causing us to isolate more pages than we
>> thought. Use thp_nr_pages to count pages. Otherwise, we might be trapped
>> in too_many_isolated while loop, since the actual isolated pages can go
>> up to COMPACT_CLUSTER_MAX*512=16384, where COMPACT_CLUSTER_MAX is 32,
>> since we stop isolation after cc->nr_migratepages reaches to
>> COMPACT_CLUSTER_MAX.
>
> I wonder if a better fix would be to adjust the too_many_isolated() check so that if we have non-zero cc->nr_migratepages, we bail out from further isolation and migrate what we have immediately, instead of looping.
I just tested your fix and it works too. The difference is that with
your fix alloc_contig_range will fail quickly without killing the user
application mlocking THPs in the CMA region (for more context, please
see my other email to Andrew explaining how to reproduce in userspace),
whereas my fix will oom the user application and make alloc_contig_range
successful at the end.
Anyway, I will add your fix below and send v2:
diff --git a/mm/compaction.c b/mm/compaction.c
index ee1f8439369e..8fa11637ccfd 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -817,6 +817,9 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
* delay for some time until fewer pages are isolated
*/
while (unlikely(too_many_isolated(pgdat))) {
+ /* stop isolation if there are still pages not migrated */
+ if (cc->nr_migratepages)
+ return 0;
/* async migration should just abort */
if (cc->mode == MIGRATE_ASYNC)
return 0;
>
> Because I can also imagine a hypothetical situation where multiple threads in parallel cause too_many_isolated() to be true, and will all loop there forever. The proposed fix should prevent such situation as well, AFAICT.
Yes. oom01 from ltp tests the multi-threaded situation and my fix works there too.
—
Best Regards,
Yan Zi
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 854 bytes --]
prev parent reply other threads:[~2020-10-30 15:18 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-29 20:04 Zi Yan
2020-10-29 21:14 ` Yang Shi
2020-10-29 21:31 ` Zi Yan
2020-10-30 0:28 ` Andrew Morton
2020-10-30 1:20 ` Zi Yan
2020-10-30 9:43 ` Michal Hocko
2020-10-30 12:20 ` Zi Yan
2020-10-30 13:36 ` Michal Hocko
2020-10-30 14:35 ` Zi Yan
2020-10-30 14:49 ` Michal Hocko
2020-10-30 14:53 ` Zi Yan
2020-10-30 14:55 ` Vlastimil Babka
2020-10-30 18:33 ` Yang Shi
2020-10-30 18:39 ` Zi Yan
2020-10-30 18:55 ` Yang Shi
2020-11-02 13:03 ` Vlastimil Babka
2020-11-02 16:39 ` Yang Shi
2020-10-30 14:50 ` Vlastimil Babka
2020-10-30 15:18 ` Zi Yan [this message]
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=7C9FAF14-075D-4E29-B5F5-ADF15E687C3A@nvidia.com \
--to=ziy@nvidia.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=riel@surriel.com \
--cc=vbabka@suse.cz \
/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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox