From patchwork Fri Jan 4 12:49:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mel Gorman X-Patchwork-Id: 10748317 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7D76A13B5 for ; Fri, 4 Jan 2019 12:52:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D29F283A5 for ; Fri, 4 Jan 2019 12:52:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 616CB28434; Fri, 4 Jan 2019 12:52:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35DE4283C9 for ; Fri, 4 Jan 2019 12:52:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4BFD78E00DE; Fri, 4 Jan 2019 07:52:27 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 46C6C8E00AE; Fri, 4 Jan 2019 07:52:27 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3430A8E00DE; Fri, 4 Jan 2019 07:52:27 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by kanga.kvack.org (Postfix) with ESMTP id C88368E00AE for ; Fri, 4 Jan 2019 07:52:26 -0500 (EST) Received: by mail-ed1-f72.google.com with SMTP id i55so35179058ede.14 for ; Fri, 04 Jan 2019 04:52:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=AO1EIfUjY0wHJt52savv2CHgHGtRk3UkrKypX/70fsA=; b=T2ee5TF5ggeAuocN1OSY8E+3iB4HxnQSg642BnE78AopgCfZ211ftDPEFnIgsFUQ31 SVe+YciAgDuYF+Pkkl4+9AiMMBz+nOadVgXMLMRzpN3Ev/6EflgnuwUHiIhhrpd4oDRo nU1mPV69ssrCAkN71fjwj8GU5Lfk6Jh5hMHvA0zhc2l5+lRd9BED2VDB5duCTbc1W9Zu idvpPFDHNFaUy9hv8/iC3XsKzXaskT4mnFRBp9w+tGzpnszwJsFK9w4zaO1rqIwIkqOI 7A50g+ghQvMZFF34jKxgf5SgnOtpHaWk/KbVjsuMasysNe+qWWdETPcbCTM68r52bnkd B85g== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of mgorman@techsingularity.net designates 46.22.139.15 as permitted sender) smtp.mailfrom=mgorman@techsingularity.net X-Gm-Message-State: AA+aEWZ/X6Olfp7e4j8pFUo1Q2F/702QEM/4bNfTH+JxwkVFkQF1V48T CuB5wGjkYeOmsPzH9M+E2MaqruHdcVEnRZSVbvhJSDhwNfpJ6peAEJ3MStGxIz3aMk9QmVPBsVo 3FBqr304aa+/Bvnfixd5tz18WZerEqTV27tjATDzvKTeX0YhBE3yPP8uTqeF0wFWHcw== X-Received: by 2002:a17:906:55a:: with SMTP id k26-v6mr39036863eja.218.1546606346232; Fri, 04 Jan 2019 04:52:26 -0800 (PST) X-Google-Smtp-Source: AFSGD/X2tEAI3FAYvHIV7VtE/ZL2tp0G3xW595OX6cmgCcYBEuPTvcuxeD2jxlQiXzFNg4Y4N1vZ X-Received: by 2002:a17:906:55a:: with SMTP id k26-v6mr39036821eja.218.1546606344965; Fri, 04 Jan 2019 04:52:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546606344; cv=none; d=google.com; s=arc-20160816; b=KhZbKsOI/fiSs+XzZRuP8yw8vWfVOuo/uOSheCN2hbm5sEJXNgYABtO9hP4NxmGm3n y9hmlyMYH7I1cGjgInxkHAtjSfwCrxN7eeY1wuB5H9XE0rz3fyTZbSOPvR81OTCqfP+b xksq5tccMEqMxxAOzMw5nE5P0Plo6Gw58+nE7M+D20w03c3DotyQ8iOXMVPp34BX1XV7 B9xUhXi0+s0WSAoPJyGGAEuikfLaXBcDchYhLaivVuMopiVGdmykTiL5mal/xGPR78Qt 0cC0uF8aYsukX6lUfxy+mec0bOpx25EAv65mYtDTm88ShxT4vSVVBxFf7xuBfKmxO/bZ 2PGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=AO1EIfUjY0wHJt52savv2CHgHGtRk3UkrKypX/70fsA=; b=k0q++prq9JaXxZfultX91AvNTeA+SRoDOLMPQ0lBbEEyWG8EjjhZ4qCZXdKjdgX77S MyHPjz4LYbtqPfRjEAp23NUvL2kh5kvFFDMexRR39WKcgf/fWyVXQ2u00Mv4JVp1x+rR T09m9Nzm9CZfzntLgb11sVPA3qbmxEPUX/Ot9mapO5hnZrxhw1hFt2rWe2pYs/ti4jjp v58ViuZ2My9mNWgDxPFg+LBXasXyR4FtYGpXCnrz/WxBqXVOo8BqUXyga3ilEQ/pCL7T +4ncGub90zgV5+5ZDu5wJFnm7TD+Z8G3vbADEO0GKZmqjOgnDVvjokal2TfL2tgPkWtJ 8xpQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of mgorman@techsingularity.net designates 46.22.139.15 as permitted sender) smtp.mailfrom=mgorman@techsingularity.net Received: from outbound-smtp10.blacknight.com (outbound-smtp10.blacknight.com. [46.22.139.15]) by mx.google.com with ESMTPS id e16-v6si384789ejk.23.2019.01.04.04.52.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Jan 2019 04:52:24 -0800 (PST) Received-SPF: pass (google.com: domain of mgorman@techsingularity.net designates 46.22.139.15 as permitted sender) client-ip=46.22.139.15; Authentication-Results: mx.google.com; spf=pass (google.com: domain of mgorman@techsingularity.net designates 46.22.139.15 as permitted sender) smtp.mailfrom=mgorman@techsingularity.net Received: from mail.blacknight.com (pemlinmail03.blacknight.ie [81.17.254.16]) by outbound-smtp10.blacknight.com (Postfix) with ESMTPS id 935591C213D for ; Fri, 4 Jan 2019 12:52:24 +0000 (GMT) Received: (qmail 3732 invoked from network); 4 Jan 2019 12:52:24 -0000 Received: from unknown (HELO stampy.163woodhaven.lan) (mgorman@techsingularity.net@[37.228.229.96]) by 81.17.254.9 with ESMTPA; 4 Jan 2019 12:52:24 -0000 From: Mel Gorman To: Linux-MM Cc: David Rientjes , Andrea Arcangeli , Vlastimil Babka , ying.huang@intel.com, kirill@shutemov.name, Andrew Morton , Linux List Kernel Mailing , Mel Gorman Subject: [PATCH 12/25] mm, compaction: Keep migration source private to a single compaction instance Date: Fri, 4 Jan 2019 12:49:58 +0000 Message-Id: <20190104125011.16071-13-mgorman@techsingularity.net> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190104125011.16071-1-mgorman@techsingularity.net> References: <20190104125011.16071-1-mgorman@techsingularity.net> 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: X-Virus-Scanned: ClamAV using ClamSMTP Due to either a fast search of the free list or a linear scan, it is possible for multiple compaction instances to pick the same pageblock for migration. This is lucky for one scanner and increased scanning for all the others. It also allows a race between requests on which first allocates the resulting free block. This patch tests and updates the pageblock skip for the migration scanner carefully. When isolating a block, it will check and skip if the block is already in use. Once the zone lock is acquired, it will be rechecked so that only one scanner can set the pageblock skip for exclusive use. Any scanner contending will continue with a linear scan. The skip bit is still set if no pages can be isolated in a range. While this may result in redundant scanning, it avoids unnecessarily acquiring the zone lock when there are no suitable migration sources. 1-socket thpscale 4.20.0 4.20.0 findmig-v2r15 isolmig-v2r15 Amean fault-both-1 0.00 ( 0.00%) 0.00 * 0.00%* Amean fault-both-3 3505.69 ( 0.00%) 3066.68 * 12.52%* Amean fault-both-5 5794.13 ( 0.00%) 4298.49 * 25.81%* Amean fault-both-7 7663.09 ( 0.00%) 5986.99 * 21.87%* Amean fault-both-12 10983.36 ( 0.00%) 9324.85 ( 15.10%) Amean fault-both-18 13602.71 ( 0.00%) 13350.05 ( 1.86%) Amean fault-both-24 16145.77 ( 0.00%) 13491.77 * 16.44%* Amean fault-both-30 19753.82 ( 0.00%) 15630.86 * 20.87%* Amean fault-both-32 20616.16 ( 0.00%) 17428.50 * 15.46%* This is the first patch that shows a significant reduction in latency as multiple compaction scanners do not operate on the same blocks. There is a small increase in the success rate 4.20.0-rc6 4.20.0-rc6 findmig-v1r4 isolmig-v1r4 Percentage huge-3 90.58 ( 0.00%) 95.84 ( 5.81%) Percentage huge-5 91.34 ( 0.00%) 94.19 ( 3.12%) Percentage huge-7 92.21 ( 0.00%) 93.78 ( 1.71%) Percentage huge-12 92.48 ( 0.00%) 94.33 ( 2.00%) Percentage huge-18 91.65 ( 0.00%) 94.15 ( 2.72%) Percentage huge-24 90.23 ( 0.00%) 94.23 ( 4.43%) Percentage huge-30 90.17 ( 0.00%) 95.17 ( 5.54%) Percentage huge-32 89.72 ( 0.00%) 93.59 ( 4.32%) Compaction migrate scanned 54168306 25516488 Compaction free scanned 800530954 87603321 Migration scan rates are reduced by 52%. Signed-off-by: Mel Gorman Acked-by: Vlastimil Babka --- mm/compaction.c | 126 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 99 insertions(+), 27 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 137e32e8a2f5..24e3a9db4b70 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -279,13 +279,52 @@ void reset_isolation_suitable(pg_data_t *pgdat) } } +/* + * Sets the pageblock skip bit if it was clear. Note that this is a hint as + * locks are not required for read/writers. Returns true if it was already set. + */ +static bool test_and_set_skip(struct compact_control *cc, struct page *page, + unsigned long pfn) +{ + bool skip; + + /* Do no update if skip hint is being ignored */ + if (cc->ignore_skip_hint) + return false; + + if (!IS_ALIGNED(pfn, pageblock_nr_pages)) + return false; + + skip = get_pageblock_skip(page); + if (!skip && !cc->no_set_skip_hint) + set_pageblock_skip(page); + + return skip; +} + +static void update_cached_migrate(struct compact_control *cc, unsigned long pfn) +{ + struct zone *zone = cc->zone; + + pfn = pageblock_end_pfn(pfn); + + /* Set for isolation rather than compaction */ + if (cc->no_set_skip_hint) + return; + + if (pfn > zone->compact_cached_migrate_pfn[0]) + zone->compact_cached_migrate_pfn[0] = pfn; + if (cc->mode != MIGRATE_ASYNC && + pfn > zone->compact_cached_migrate_pfn[1]) + zone->compact_cached_migrate_pfn[1] = pfn; +} + /* * If no pages were isolated then mark this pageblock to be skipped in the * future. The information is later cleared by __reset_isolation_suitable(). */ static void update_pageblock_skip(struct compact_control *cc, - struct page *page, unsigned long nr_isolated, - bool migrate_scanner) + struct page *page, unsigned long nr_isolated) { struct zone *zone = cc->zone; unsigned long pfn; @@ -304,16 +343,8 @@ static void update_pageblock_skip(struct compact_control *cc, pfn = page_to_pfn(page); /* Update where async and sync compaction should restart */ - if (migrate_scanner) { - if (pfn > zone->compact_cached_migrate_pfn[0]) - zone->compact_cached_migrate_pfn[0] = pfn; - if (cc->mode != MIGRATE_ASYNC && - pfn > zone->compact_cached_migrate_pfn[1]) - zone->compact_cached_migrate_pfn[1] = pfn; - } else { - if (pfn < zone->compact_cached_free_pfn) - zone->compact_cached_free_pfn = pfn; - } + if (pfn < zone->compact_cached_free_pfn) + zone->compact_cached_free_pfn = pfn; } #else static inline bool isolation_suitable(struct compact_control *cc, @@ -328,10 +359,19 @@ static inline bool pageblock_skip_persistent(struct page *page) } static inline void update_pageblock_skip(struct compact_control *cc, - struct page *page, unsigned long nr_isolated, - bool migrate_scanner) + struct page *page, unsigned long nr_isolated) +{ +} + +static void update_cached_migrate(struct compact_control *cc, unsigned long pfn) { } + +static bool test_and_set_skip(struct compact_control *cc, struct page *page, + unsigned long pfn) +{ + return false; +} #endif /* CONFIG_COMPACTION */ /* @@ -570,7 +610,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc, /* Update the pageblock-skip if the whole pageblock was scanned */ if (blockpfn == end_pfn) - update_pageblock_skip(cc, valid_page, total_isolated, false); + update_pageblock_skip(cc, valid_page, total_isolated); cc->total_free_scanned += nr_scanned; if (total_isolated) @@ -705,6 +745,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, unsigned long start_pfn = low_pfn; bool skip_on_failure = false; unsigned long next_skip_pfn = 0; + bool skip_updated = false; /* * Ensure that there are not too many pages isolated from the LRU @@ -771,8 +812,19 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, page = pfn_to_page(low_pfn); - if (!valid_page) + /* + * Check if the pageblock has already been marked skipped. + * Only the aligned 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 && IS_ALIGNED(low_pfn, pageblock_nr_pages)) { + if (!cc->ignore_skip_hint && get_pageblock_skip(page)) { + low_pfn = end_pfn; + goto isolate_abort; + } valid_page = page; + } /* * Skip if free. We read page order here without zone lock @@ -860,8 +912,19 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, if (!locked) { locked = compact_trylock_irqsave(zone_lru_lock(zone), &flags, cc); - if (!locked) + + /* Allow future scanning if the lock is contended */ + if (!locked) { + clear_pageblock_skip(page); break; + } + + /* Try get exclusive access under lock */ + if (!skip_updated) { + skip_updated = true; + if (test_and_set_skip(cc, page, low_pfn)) + goto isolate_abort; + } /* Recheck PageLRU and PageCompound under lock */ if (!PageLRU(page)) @@ -939,15 +1002,20 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, if (unlikely(low_pfn > end_pfn)) low_pfn = end_pfn; +isolate_abort: if (locked) spin_unlock_irqrestore(zone_lru_lock(zone), flags); /* - * Update the pageblock-skip information and cached scanner pfn, - * if the whole pageblock was scanned without isolating any page. + * Updated the cached scanner pfn if the pageblock was scanned + * without isolating a page. The pageblock may not be marked + * skipped already if there were no LRU pages in the block. */ - if (low_pfn == end_pfn) - update_pageblock_skip(cc, valid_page, nr_isolated, true); + if (low_pfn == end_pfn && !nr_isolated) { + if (valid_page && !skip_updated) + set_pageblock_skip(valid_page); + update_cached_migrate(cc, low_pfn); + } trace_mm_compaction_isolate_migratepages(start_pfn, low_pfn, nr_scanned, nr_isolated); @@ -1332,8 +1400,6 @@ static unsigned long fast_find_migrateblock(struct compact_control *cc) nr_scanned++; free_pfn = page_to_pfn(freepage); if (free_pfn < high_pfn) { - update_fast_start_pfn(cc, free_pfn); - /* * Avoid if skipped recently. Move to the tail * of the list so it will not be found again @@ -1355,9 +1421,9 @@ static unsigned long fast_find_migrateblock(struct compact_control *cc) /* Reorder to so a future search skips recent pages */ move_freelist_tail(freelist, freepage); + update_fast_start_pfn(cc, free_pfn); pfn = pageblock_start_pfn(free_pfn); cc->fast_search_fail = 0; - set_pageblock_skip(freepage); break; } @@ -1427,7 +1493,6 @@ static isolate_migrate_t isolate_migratepages(struct zone *zone, low_pfn = block_end_pfn, block_start_pfn = block_end_pfn, block_end_pfn += pageblock_nr_pages) { - /* * This can potentially iterate a massively long zone with * many pageblocks unsuitable, so periodically check if we @@ -1442,8 +1507,15 @@ static isolate_migrate_t isolate_migratepages(struct zone *zone, if (!page) continue; - /* If isolation recently failed, do not retry */ - if (!isolation_suitable(cc, page)) + /* + * If isolation recently failed, do not retry. Only check the + * pageblock once. COMPACT_CLUSTER_MAX causes a pageblock + * to be visited multiple times. Assume skip was checked + * before making it "skip" so other compaction instances do + * not scan the same block. + */ + if (IS_ALIGNED(low_pfn, pageblock_nr_pages) && + !isolation_suitable(cc, page)) continue; /*