From patchwork Mon Jul 31 17:24:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 13335337 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 A0CD3C001DC for ; Mon, 31 Jul 2023 17:24:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D1A5B28008D; Mon, 31 Jul 2023 13:24:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CCB2828007A; Mon, 31 Jul 2023 13:24:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B94E828008D; Mon, 31 Jul 2023 13:24:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A890528007A for ; Mon, 31 Jul 2023 13:24:54 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7AEA2120254 for ; Mon, 31 Jul 2023 17:24:54 +0000 (UTC) X-FDA: 81072582108.16.FFA558A Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) by imf01.hostedemail.com (Postfix) with ESMTP id 763934000D for ; Mon, 31 Jul 2023 17:24:52 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=18XUaorM; spf=pass (imf01.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.42 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690824292; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=7NS07eERycsyYXabrMm2ZwmT1XGv12jB2lBTOvtc5rI=; b=kDH5NWZqZZ2na7V4zVpv/Y/6Y57nY5rFrlM63txmZX7VivL6sUxbjqVrL5wWqGJ+yCvnFz 7HITD5LSKeuNkgg2tut+Zpb88oOhp9lpZvyZcaUu/F+pK6tdxWIHe0f8vX98uGFl9r1MV2 7yvyQmgHJ1i6rrT+ckA/9++aKSvyDzM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690824292; a=rsa-sha256; cv=none; b=c8jJXB6S0NMB1dl/OM5C0D8dDf5HN1p0kNhu6XM9qpVaMkAjW7+3OOBycAeQPa+MbXlgWL 2LpeyAqakVvbWI254+/2G54VIADUh1/qDdIkq6YoH1LEd8HIlUW9YDtyc/BkfTWaGKlwfX IslqnPX3IoOM4B7prhWD72aPgLBFmNE= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=18XUaorM; spf=pass (imf01.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.42 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org Received: by mail-qv1-f42.google.com with SMTP id 6a1803df08f44-63cf96c37beso21362906d6.0 for ; Mon, 31 Jul 2023 10:24:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20221208.gappssmtp.com; s=20221208; t=1690824291; x=1691429091; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=7NS07eERycsyYXabrMm2ZwmT1XGv12jB2lBTOvtc5rI=; b=18XUaorMeICGc+jzoF4yol4wK5qJ7gn2mfA4wlpTfRO8KdaQDIH1fD2koXQPYRjEDC NIIdKxiwwM/YDz38sQ+MlsBsV63rH0AdPhBpkcJncF7+4x+s75wttLBi6JthsD+akEjf kSVpMRpqvt2MK1eFqFven2FU8b9mB725b3ESRHKHKsS7dYnYgtR3v58asjyphUq7NiFj 5jghqsA7lxDAKMTJjQB3pcWzpEf5HXUXBBPJLxvXK3P5Hks3j3ctROflA/DZo9QEP3++ iRb2YOn0UOXI+9vd7zHj/AddRy3d3/he+goVguwsXPIRKL0z/STsCp1FqQ/SdeCbmNJY x1Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690824291; x=1691429091; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7NS07eERycsyYXabrMm2ZwmT1XGv12jB2lBTOvtc5rI=; b=Nlmr/V4pOklDzg+EAB3poEu5hw4F31qmXGTRj+Fyf4pyQAZ4nlR27Vhxm8zvztbNbf EtlynP2e2deeWH2n+KGKGCthCV+7UIQIQDTz1kMqSVBYeZ0+O6jgam9wRqN1vrgRIGT2 ZoXX58JqeEQwtFyWCta02y0uiRd5YnhwW+N0OaRRpJO4PFT+TdicDWgXv1GZHDkd+qHL fPhRljLB/g+f/7a8mJ8y/X1LawLxZa6DBQOubh2d4PIhmJOGo2nLxZKDz3rzVPRX4EwL 21BA4LQLzgPqfzZ7GlSsZPfElREkcKWjNOVoKNXQ8c8dlY+4qqFtNLXqPlvbjXOh6iP/ 7KOA== X-Gm-Message-State: ABy/qLZDnTDU/c4JB2spq2rc5fx4+fPtuCJv5hpSQklyWmvXP3So5pvi WFFcEpoU1og7/fJZ0uEfiPiERA== X-Google-Smtp-Source: APBJJlGRy+Nma728a4Fs3yn3m7Q4d9RSDgIp+ZN1CBwpFtcSjS/YiqDh7dIhQbspSC7isIOHk6SmJA== X-Received: by 2002:a05:6214:301b:b0:637:b20d:899d with SMTP id ke27-20020a056214301b00b00637b20d899dmr12116438qvb.10.1690824291357; Mon, 31 Jul 2023 10:24:51 -0700 (PDT) Received: from localhost ([2620:10d:c091:400::5:ad06]) by smtp.gmail.com with ESMTPSA id q6-20020a0ce206000000b006300e92ea02sm3928668qvl.121.2023.07.31.10.24.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 10:24:51 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Vlastimil Babka , Mel Gorman , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm: compaction: fix endless looping over same migrate block Date: Mon, 31 Jul 2023 13:24:50 -0400 Message-ID: <20230731172450.1632195-1-hannes@cmpxchg.org> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: 763934000D X-Rspam-User: X-Stat-Signature: sydprfgkxuk6psxso6p7nck8xo8zf3yw X-Rspamd-Server: rspam03 X-HE-Tag: 1690824292-724434 X-HE-Meta: U2FsdGVkX18RWT/0Iqi23ioNvj7x3rW2yj24YxHfmtmoex4gnKzcKe2d7cpBbd2f5kZ9LdJOlwMN5pGWsASpJ4bqRENzEHveMqbfEpgDlSgPUtVZOZToA5Hj2pclOWwV7nDNJAvHS4fjr6eOcrzszMPL8V5hVkXvOj3AVXX4verHvEy0GLsh5Von3hBsbY4AFax6BJQ2qRl7C8royJdFE1+8/EBmYzvHZKuCOTTahrepMJWH1FCRN8t/nYKLme8HEbGyxoxAUD0F6asUj3Vqd0PZJ5nyoo3X4W79p2bkwNlJfSjtJujcJTrXfynS0fB1IM+ArDqLGpiBA+GoTV3NRXd5zXWd6rvoEFxzxYe2kbgnL3JT5oW01AKzcw5jTHSNaWVnScZkouNPlitLhQylhdaxotMdeY/gFlel5erH0VXEgSyApF/nRTlG26PLxIZx0yObVIrh1sjfrOTohKQLVuoSTBE2nu4lgKwTIbytQkO7b2We9P35+4GeCsoaoUkXZojLteRF8kSyhFZTjDGPqxROfipNGM1WGVkNlp1Tq4SeQpeMKP5C5CZfcGczocHW9d4M30FYvAB32JWfY8xyAcAYqRCykRXRnet0ZAmJdzcT3M3vdAKi3WU2Nw3jQUkaQOYZbMnF0mX7MZYpB/bGpsolMKp3xpzPvDn6thusR2SfMVn+4pTgRDxDRYX6XfuwocxFi8cz5G5/94ygze/y9d1JrevHaXxofYG2ZLz62x6YFNgi9srHRSJX/fhiYu0bD4KWR89hPJCOMXO/o47mJ/DAaa1RSHLQV5RaQ5i27Isn5Xeo0rvxOTWh5xWYnjipA3V+pAjB4XY33QMrUEJsCRaZisXaZFmn6C2SMt87OqhFya/vBFCRDmeT9FegiqMe6Xa8iEH6MP4wxNlr+VaiABHRHrCILnwJcjzEGX6H1qZeLHA9HqTORoAE5grF3FkBdSVxJpfA0YQQX6B7C+R 1H/rr3f7 nk39z2ffvy+FE+socTShWpL8QQujPV45N2yCwOEUBw94sdNMtbQt9cCoUNoDI/Vw31HR+dCVYDs8IucLsxDteTdQx1m6lPXxWzX+Z9CVXTQPO8BDKipiDFeC3ajGg8hjuYbAd8eooCOMwRch8efDXsncAHtqApjsnon1YJyI1OjE4HJR8anh/q0wKRRHWgd5yM+9zGeTVPP8y0eaJxAvBcm5suphdBwTS2vlPaL+0EUX/8dRARGIuR2+iC1F4kakj4sXDuEu8sTUvyCyqzM8jh4SR4V6BhGanDILd3ABwE96XXWDG8h6t3XSxDkv/5k0D72l3tY64QltNjz4zypYjw3dIgTZoG51cJio7L0KGHFU90C53reM5/YnoNVXPbrn7FuoSiunCZbiwFuvCd29fCx5f+wn7bAzeTzvRgFgCgJ6Fy1rsmFqYwSMN8O3u28C09Qy18vsjxOxWb56mKprf3oPRMg== 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: 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: Vlastimil Babka Acked-by: Mel Gorman 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;