From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D38DC001DF for ; Tue, 1 Aug 2023 11:03:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84E768E0011; Tue, 1 Aug 2023 07:03:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7FF278E0002; Tue, 1 Aug 2023 07:03:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6ED9F8E0011; Tue, 1 Aug 2023 07:03:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 622268E0002 for ; Tue, 1 Aug 2023 07:03:37 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2F433A04DB for ; Tue, 1 Aug 2023 11:03:37 +0000 (UTC) X-FDA: 81075250074.29.B020C72 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by imf03.hostedemail.com (Postfix) with ESMTP id 6E60520032 for ; Tue, 1 Aug 2023 11:03:31 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf03.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.132 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690887814; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H6JMYGd/wqte3oNek4mbRTEzIawGdT/9O8/XXt9uW3w=; b=kP5R6ftVXycCVVq0RJNSlVnuipj1Y85SnfJ0iBmHOMj4jfkL2V2C3vHNU1OHTGZLknA71t kanUggYXekuTHbBP+5CEg69BIOk6CPB6flL2yBahvs/Bt7gROvbUG133x+WCPs7q1S2qzT 0CnbsmTlKNe+aUVVEwr9F13W+zJF0K4= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf03.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.132 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690887814; a=rsa-sha256; cv=none; b=BFa7zkqDcbadpN07rK088yFMWx+WyIBEm48aqvx0rR6k4WvdZo8YpCdDoE6phrI0Jj2nTu P2giVCl64AiZ71gKc6LPQfCI1ceYZlQZ8bX46sbknDdycalw8JIrbkSIVIL2zqNQ7kRMIg 3QfvMOyiFvdmiOCJQnnQBQXF07WCF4U= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046051;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0Vor2y66_1690887804; Received: from 30.97.48.66(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0Vor2y66_1690887804) by smtp.aliyun-inc.com; Tue, 01 Aug 2023 19:03:25 +0800 Message-ID: <8e445d60-e8b1-7172-4577-20e7f28d1e9d@linux.alibaba.com> Date: Tue, 1 Aug 2023 19:03:52 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH] mm: compaction: fix endless looping over same migrate block To: Johannes Weiner , Andrew Morton Cc: Vlastimil Babka , Mel Gorman , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20230731172450.1632195-1-hannes@cmpxchg.org> From: Baolin Wang In-Reply-To: <20230731172450.1632195-1-hannes@cmpxchg.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 6E60520032 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: zybzw9kbfsmu8g1saxe4tp9qkqsawtth X-HE-Tag: 1690887811-481739 X-HE-Meta: U2FsdGVkX196cn+TyIymJMTVzWySXD2IEa22V8Vey7F9cCEeqJWXvN+sdhCMNZurhqFlRr/C3DMnaYBGZiv55eXySIkfjuwN7XYoKaphYDRt2AcmV0jp8d+lktrP2aYzi/u3Tw6dFAE8061+w97Zz1fn9Njcv/ZXD6qWpXPKEt+bauLwr/VHPGzN2ri04bJbdVLuNaPKg8o4FTZG2v0MAtAcAsdeK/lXuGhrMgMMDZJOVZiQeLbO3xblw3QnxMbhPlP4YZ0FxceiTf2l6z0mwnJegnfvE8SHcC5m/SNS56FkeYGN4Tr6iwiwiLWlwK5QNz2WVntIAeO5mLkKtf1UTlCt57+82OEV8DUC0mGCggEPjdxPYL5OPIFggv9BXShloBIxrFo+q6Ng0kPnFnxpj/lstVHbDP3dBt7x2dicU+qvIcTeHLJKwWxcuWiEtr14KI3bXkgRhqEOJ5a/9ltNRrTLzM8ma7f8afD61MJ+/ZZR7pXc4zGMNW0cRhIAVAjkQ5/UBbB1kwUc1ZvOvM9xc2JXi7emDtDZsoQOgCgC4LevuLIecTfEXkQYwSM0dej7ck+p7eqVpdE67pJ1fgU+HFGKndFiPxbeXMr8OdODN4FhcR1eYrzirgOESCTpVG6RE5FzMFGlcngqsjqNGn4Pk4i2dT/TWqaz+NhAa4D/Krx6EvrfOroR9bIJ3a0PJEN55QiQUIo93L8PCpZRs1xA/2+9SxlTCS8MYJnQeS6giJjvFFD9dt0SyFFv+2XWVbX10O3SLub+stofsgp77+niqcBkmjTgMebWrkBUlghx+g6R3BX6BkQVnTVKUHR6CkDP0HuQL0FPHa4cHSf2p8AYyw3yeGkQTyZY4sc6knmcRMTZfdPTzKSoiQ+xfvDAM1Pe8uu7TwxRuIFV7aBKUxIuflUB1Jbw6KjH04jzN0F2SH2hcp06z3HToPOMBJAZC+8+4FdfOn7i70t8O6hggXF ecekejdn A3p/fW+dfaIJ25nAG7GYcjVlUXb0mWCkdUYLoNvnitrIyvKXEikhqec3S912PRWTF6Ma+7SP4M/76MHTGAbrVVXVJ22JFdYWR9rlRw0uY+qatMjnTZaVKkSWJ3Wq0iPrBxjrfAtm1PQr+0+WD+rspfgScLSEmbBixljjP X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 8/1/2023 1:24 AM, Johannes Weiner wrote: > During stress testing, the following situation was observed: > > 70 root 39 19 0 0 0 R 100.0 0.0 959:29.92 khugepaged > 310936 root 20 0 84416 25620 512 R 99.7 1.5 642:37.22 hugealloc > > Tracing shows isolate_migratepages_block() endlessly looping over the > first block in the DMA zone: > > hugealloc-310936 [001] ..... 237297.415718: mm_compaction_finished: node=0 zone=DMA order=9 ret=no_suitable_page > hugealloc-310936 [001] ..... 237297.415718: mm_compaction_isolate_migratepages: range=(0x1 ~ 0x400) nr_scanned=513 nr_taken=0 > hugealloc-310936 [001] ..... 237297.415718: mm_compaction_finished: node=0 zone=DMA order=9 ret=no_suitable_page > hugealloc-310936 [001] ..... 237297.415718: mm_compaction_isolate_migratepages: range=(0x1 ~ 0x400) nr_scanned=513 nr_taken=0 > hugealloc-310936 [001] ..... 237297.415718: mm_compaction_finished: node=0 zone=DMA order=9 ret=no_suitable_page > hugealloc-310936 [001] ..... 237297.415718: mm_compaction_isolate_migratepages: range=(0x1 ~ 0x400) nr_scanned=513 nr_taken=0 > hugealloc-310936 [001] ..... 237297.415718: mm_compaction_finished: node=0 zone=DMA order=9 ret=no_suitable_page > hugealloc-310936 [001] ..... 237297.415718: mm_compaction_isolate_migratepages: range=(0x1 ~ 0x400) nr_scanned=513 nr_taken=0 > > The problem is that the functions tries to test and set the skip bit > once on the block, to avoid skipping on its own skip-set, using > pageblock_aligned() on the pfn as a test. But because this is the DMA > zone which starts at pfn 1, this is never true for the first block, > and the skip bit isn't set or tested at all. As a result, > fast_find_migrateblock() returns the same pageblock over and over. > > If the pfn isn't pageblock-aligned, also check if it's the start of > the zone to ensure test-and-set-exactly-once on unaligned ranges. > > Thanks to Vlastimil Babka for the help in debugging this. > > Fixes: 90ed667c03fe ("Revert "Revert "mm/compaction: fix set skip in fast_find_migrateblock""") > Signed-off-by: Johannes Weiner Reviewed-by: Baolin Wang > --- > mm/compaction.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/mm/compaction.c b/mm/compaction.c > index dbc9f86b1934..eacca2794e47 100644 > --- a/mm/compaction.c > +++ b/mm/compaction.c > @@ -912,11 +912,12 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, > > /* > * Check if the pageblock has already been marked skipped. > - * Only the aligned PFN is checked as the caller isolates > + * Only the first PFN is checked as the caller isolates > * COMPACT_CLUSTER_MAX at a time so the second call must > * not falsely conclude that the block should be skipped. > */ > - if (!valid_page && pageblock_aligned(low_pfn)) { > + if (!valid_page && (pageblock_aligned(low_pfn) || > + low_pfn == cc->zone->zone_start_pfn)) { > if (!isolation_suitable(cc, page)) { > low_pfn = end_pfn; > folio = NULL; > @@ -2002,7 +2003,8 @@ static isolate_migrate_t isolate_migratepages(struct compact_control *cc) > * before making it "skip" so other compaction instances do > * not scan the same block. > */ > - if (pageblock_aligned(low_pfn) && > + if ((pageblock_aligned(low_pfn) || > + low_pfn == cc->zone->zone_start_pfn) && > !fast_find_block && !isolation_suitable(cc, page)) > continue; >