From patchwork Thu Jan 28 13:04:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wonhyuk Yang X-Patchwork-Id: 12053649 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E33CEC433DB for ; Thu, 28 Jan 2021 13:04:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7777D64DD8 for ; Thu, 28 Jan 2021 13:04:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7777D64DD8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AFE006B006C; Thu, 28 Jan 2021 08:04:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AAF026B0072; Thu, 28 Jan 2021 08:04:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 99D7C6B0073; Thu, 28 Jan 2021 08:04:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0251.hostedemail.com [216.40.44.251]) by kanga.kvack.org (Postfix) with ESMTP id 8330C6B006C for ; Thu, 28 Jan 2021 08:04:16 -0500 (EST) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 3B0653625 for ; Thu, 28 Jan 2021 13:04:16 +0000 (UTC) X-FDA: 77755202112.04.smoke32_5b110712759f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin04.hostedemail.com (Postfix) with ESMTP id 161E980118C9 for ; Thu, 28 Jan 2021 13:04:16 +0000 (UTC) X-HE-Tag: smoke32_5b110712759f X-Filterd-Recvd-Size: 6529 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Thu, 28 Jan 2021 13:04:14 +0000 (UTC) Received: by mail-pl1-f182.google.com with SMTP id d4so3291169plh.5 for ; Thu, 28 Jan 2021 05:04:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tsbka8HYYey6jG9YZfzFgQ+lgpyITOkmF6il2kQ/3Qg=; b=UQHM4De8vx48HR2McMBkYuhMejGEWDDKbiZQMYnunDM/Xt/eeP2fLA5/C35QhbKZNM ARWvStd1IbVuWtKcV8tWZeZVE+TuvFFt3+1J3wPusTE71rJed0sLUoeWmqh/0x2jjndn Qr0fhQnO26rQNfqb0Y2VyUCTZLFp5VTwrTXVbU+DRh0AAkeKeZ9G/eVO0Et5BSuXnek2 dEkC2uSz9pKKkfXrhmNSBbkFnJ/OW3lv1OJACCjNBpJMDfk+9xwnqtktPNvlVWUGRIPj g5PzruVmAUNwchPUPa4Z3yL75F97YrgDuRlbblbUie/D8sIwewYS2EAS1agt1zdvM6Ei YfLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tsbka8HYYey6jG9YZfzFgQ+lgpyITOkmF6il2kQ/3Qg=; b=Ob+kL+qDFz+spFrZswQ/wxa69bFWxz//Vz0z+c3ZqHhSShSy05fklhHLGcPfS9Jj1k IyhUEM9d3CaGYtOGmH1moaCjEpu8yanU4uNX/5aGAIDTZlRntAuCJBUB/q8vL/qQXK05 xr2xw9gpUKinBF2NobUBm3UhIIOG4+ohaU442FkBP3cvf2tFtIiDOWlZdKxwbUoKi5RX y549P6JgFVgei7f6r5Oyref6ZI8kpsAtG8E6xNqMivIp+HU++bi1YXsQfnxV39ytiUsJ +mIxj66rzOorwNZyIgYAAWIRZyRFX+BIHEoLfgwYhVZu499Sug5MBMy0uPD+IuYw0zGB zTzQ== X-Gm-Message-State: AOAM53279HakY0hI+PxyHAPM7Bzq2Bpcz6FafDKLIKgI8Px5c4Nfys1f Gd0FhCOf9A/faI7t2e/XeDI= X-Google-Smtp-Source: ABdhPJzCsFLv0QZ+kkuAuxdEF4laAt5EcZwDx0jbGD+B9RnqLSmZXbgzYTrDEhJlpUjPar4EjoWxKg== X-Received: by 2002:a17:90b:2352:: with SMTP id ms18mr10971292pjb.138.1611839053792; Thu, 28 Jan 2021 05:04:13 -0800 (PST) Received: from DESKTOP-FCFI5AT.localdomain ([125.131.156.99]) by smtp.gmail.com with ESMTPSA id o20sm5812110pgn.6.2021.01.28.05.04.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Jan 2021 05:04:12 -0800 (PST) From: Wonhyuk Yang To: Andrew Morton Cc: Mel Gorman , Vlastimil Babka , linux-mm@kvack.org, Wonhyuk Yang Subject: [PATCH v2] mm/compactoin: Fix misbehaviors of fast_find_migrateblock() Date: Thu, 28 Jan 2021 22:04:11 +0900 Message-Id: <20210128130411.6125-1-vvghjk1234@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 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: In the fast_find_migrateblock(), It iterate freelist to find proper pageblock. But there are some misbehaviors. First, if the page we found is equal to cc->migrate_pfn, it is considered that we didn't found suitable pageblock. Second, if the loop was terminated because order is less than PAGE_ALLOC_COSTLY_ORDER, it could be considered that we found suitable one. Third, if the skip bit is set on the page block and go continue, it doesn't check the nr_scanned. Fourth, if the page block's skip bit is set, it check that page block is the last of list. But it is unnecessary. Fixes: 70b44595eafe9 ("mm, compaction: use free lists to quickly locate a migration source") Signed-off-by: Wonhyuk Yang Acked-by: Vlastimil Babka --- Changes in v2: - Follow Vlastimil's suggestions, using bool varable. - Fix new misbehavior and remove unecessary . v1: https://lore.kernel.org/linux-mm/20210123154320.24278-1-vvghjk1234@gmail.com --- mm/compaction.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index e5acb9714436..8e5cd9d20435 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1701,6 +1701,7 @@ static unsigned long fast_find_migrateblock(struct compact_control *cc) unsigned long pfn = cc->migrate_pfn; unsigned long high_pfn; int order; + bool found_block = false; /* Skip hints are relied on to avoid repeats on the fast search */ if (cc->ignore_skip_hint) @@ -1743,7 +1744,7 @@ static unsigned long fast_find_migrateblock(struct compact_control *cc) high_pfn = pageblock_start_pfn(cc->migrate_pfn + distance); for (order = cc->order - 1; - order >= PAGE_ALLOC_COSTLY_ORDER && pfn == cc->migrate_pfn && nr_scanned < limit; + order >= PAGE_ALLOC_COSTLY_ORDER && !found_block && nr_scanned < limit; order--) { struct free_area *area = &cc->zone->free_area[order]; struct list_head *freelist; @@ -1758,7 +1759,11 @@ static unsigned long fast_find_migrateblock(struct compact_control *cc) list_for_each_entry(freepage, freelist, lru) { unsigned long free_pfn; - nr_scanned++; + if (nr_scanned++ >= limit) { + move_freelist_tail(freelist, freepage); + break; + } + free_pfn = page_to_pfn(freepage); if (free_pfn < high_pfn) { /* @@ -1767,12 +1772,8 @@ static unsigned long fast_find_migrateblock(struct compact_control *cc) * the list assumes an entry is deleted, not * reordered. */ - if (get_pageblock_skip(freepage)) { - if (list_is_last(freelist, &freepage->lru)) - break; - + if (get_pageblock_skip(freepage)) continue; - } /* Reorder to so a future search skips recent pages */ move_freelist_tail(freelist, freepage); @@ -1780,15 +1781,10 @@ static unsigned long fast_find_migrateblock(struct compact_control *cc) update_fast_start_pfn(cc, free_pfn); pfn = pageblock_start_pfn(free_pfn); cc->fast_search_fail = 0; + found_block = true; set_pageblock_skip(freepage); break; } - - if (nr_scanned >= limit) { - cc->fast_search_fail++; - move_freelist_tail(freelist, freepage); - break; - } } spin_unlock_irqrestore(&cc->zone->lock, flags); } @@ -1799,9 +1795,10 @@ static unsigned long fast_find_migrateblock(struct compact_control *cc) * If fast scanning failed then use a cached entry for a page block * that had free pages as the basis for starting a linear scan. */ - if (pfn == cc->migrate_pfn) + if (!found_block) { + cc->fast_search_fail++; pfn = reinit_migrate_pfn(cc); - + } return pfn; }