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 0C219C7EE23 for ; Wed, 7 Jun 2023 03:38:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8B6098E0001; Tue, 6 Jun 2023 23:38:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8657B6B0072; Tue, 6 Jun 2023 23:38:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 754B88E0001; Tue, 6 Jun 2023 23:38:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 61E686B0071 for ; Tue, 6 Jun 2023 23:38:28 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3112A1406B9 for ; Wed, 7 Jun 2023 03:38:28 +0000 (UTC) X-FDA: 80874544296.30.48F240A Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) by imf17.hostedemail.com (Postfix) with ESMTP id C295040008 for ; Wed, 7 Jun 2023 03:38:24 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf17.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.111 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=1686109106; 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=CMf2uOotBIzZmRA+fd/5NkM3Dr5Lf0dOASWHwkTwbR8=; b=PVQ8iVAMqlpHUMHlYcJPWnFKovFpWDUyo1spYiXPqHhzkx6Z0ZsiAGHEpil6+Jiy5MEaJr q+6kcKxy0gtcwy7NTSxn2AF0oO9KEF14LoGiwQNkP4LNmAG/FN+c0IzL1FnCB5GE6v7qUG R1oXgGmpRxxIm3LRazMjFW5AKTk7owE= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf17.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686109106; a=rsa-sha256; cv=none; b=iDL8GN1wgNdXID9NzHaY4M7JnIPIm67KK5uyWU/hYgHLS6GIyY9AFsKRJRIPvacOhTwisq PDlhM0q0VDBUo2paDP49qV7+dQ0ve0/wy8LF/BRW/NQkJSeo5wXJ8qlI4A4yM0A6RXTwkt H420nax8PHhSa2Q8w3k/r/vxHR2ZiNw= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0VkYyk7Z_1686109097; Received: from 30.221.128.210(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VkYyk7Z_1686109097) by smtp.aliyun-inc.com; Wed, 07 Jun 2023 11:38:18 +0800 Message-ID: Date: Wed, 7 Jun 2023 11:38:36 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.11.2 Subject: Re: [PATCH 3/4] mm: compaction: Update pageblock skip when first migration candidate is not at the start To: Vlastimil Babka , Mel Gorman Cc: Andrew Morton , Jiri Slaby , Maxim Levitsky , Michal Hocko , Pedro Falcato , Paolo Bonzini , Chuyi Zhou , Linux-MM , LKML References: <20230515113344.6869-1-mgorman@techsingularity.net> <20230515113344.6869-4-mgorman@techsingularity.net> <20230529103342.esek6r5fvmft2nky@techsingularity.net> <6695b7e5-9fa5-fae8-8a66-cc5985b0baaf@suse.cz> <20230602111622.swtxhn6lu2qwgrwq@techsingularity.net> <152e0730-0ddc-a1f8-7122-275d51741a1d@suse.cz> <20230602124825.24a775kwwuf4rs6v@techsingularity.net> <2c802986-3726-f79c-6383-cc03adb9fb0c@suse.cz> From: Baolin Wang In-Reply-To: <2c802986-3726-f79c-6383-cc03adb9fb0c@suse.cz> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: C295040008 X-Stat-Signature: ksx7jogwwzezmyoinaqdjpjwzme5ihzy X-Rspam-User: X-HE-Tag: 1686109104-487207 X-HE-Meta: U2FsdGVkX19qSx67yV9bPA0c2LxSYAVf/kVDIXVVU1gEWRguW9M5uQC0X8S7eOCOvyLan1Bo3E9qJZaGseJ8az3dReB0CoEBxn3fJpgmg6u2hr3mBrXxIVLv4viOd4TRTtc7OrGJATkvgmzS77Tk/rDr9BV0xRDZFM+S85DOs8b4C5avKbaos4jrP8HxUXTkzkInPPw76GV8oRYjPxLUmYZTI8T3bjlFAGfYvhxYAaOL7sJl/f9xWKoK7b2MN6XcH/C4kItfe1aQc4apY3WjEx2jzbpPPFooZQLJVmhkNvUvjBYzPeZvELxGJs6ozc7ev2w/li6BFQCXZZUlLP3K6NfkM2sxuqELK2Q3XBWy1z0dvuJ6B+RCP9FvdVAyy+bDODLqPyD9zvIUzvolO7NJmgWN6m/YUP6qwssGTQYTKeHgqP1jJ5fc5xGFednEiiahHWCDjdbvLXxESBdso0TCYMmNiMKcvle2ROVELhbRBpHMkgQYeZiL5Q52iOzq4Nv5dJh+rw7dDWVJFbXZS0aYpN+Uf7+rlv4BmWcAx9aJPBkxtdehNukbJyjXPuwipAGuLDdQnLjC98fRC9MSEZ/5FxeHrVplqOuxGUWeXYZeO8sJpAs9QtJnk4Afjmd6ZbNdxpzHN6tuMLP1Ya/K+F9gUm5v+gFnRebAvLEYPAfDjYrzxn0XBVF9bwfAE4lqRf6gynSP7U6ZKvsJjmi8DKNvQUgv6AneM7tru7lY+lAhzg9wwZAludm6spqAqqregMt0/5irlAo1dVWLqz0mRaIPcGzh8e5u0omlPmMEx8k0r1Xk2QopDrsDmik00846t6HX5bHaq6T43xWF0iwDPcYbTVZgh34jgIWjvUzAQ4tfTDsEZeiaAX5r6R/uVH0evf5wJjFWCDyk2bdPn+iiPbUDklDSZZRTZXgowR24PMPtjKzPi26n4Gbxbuh8POYtlwbw7Zi4C3pOaO0Rd4hYlMd R81wXCoA Y+rGaHiN7+MsmkFokj3othcuAekgjsIjp/JU602iXfH0t6aZybK5dMjqbuE+tUIWqu1DkbucJexw5XvvQVU8rsqE790xRi00qmgJ+Q6EFucFjXwpp6KqbGKUXsEW+Go3L1+mAvALN9CDs/RNHX3lqANYE8vH4JuWbLxKFRNz8NaawcTzON7EyykEVUdA9jztKXjNXyAmmKJG21k+cJ+0/DTTwhw== 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 6/6/2023 9:11 PM, Vlastimil Babka wrote: > On 6/2/23 14:48, Mel Gorman wrote: >> On Fri, Jun 02, 2023 at 02:19:00PM +0200, Vlastimil Babka wrote: >>> On 6/2/23 13:16, Mel Gorman wrote: >>>> On Mon, May 29, 2023 at 02:43:48PM +0200, Vlastimil Babka wrote: >>>>> On 5/29/23 12:33, Mel Gorman wrote: >>>>>> On Thu, May 25, 2023 at 03:37:43PM +0200, Vlastimil Babka wrote: >>>>>>> On 5/15/23 13:33, Mel Gorman wrote: >>>>>>>> isolate_migratepages_block should mark a pageblock as skip if scanning >>>>>>>> started on an aligned pageblock boundary but it only updates the skip >>>>>>>> flag if the first migration candidate is also aligned. Tracing during >>>>>>>> a compaction stress load (mmtests: workload-usemem-stress-numa-compact) >>>>>>>> that many pageblocks are not marked skip causing excessive scanning of >>>>>>>> blocks that had been recently checked. Update pageblock skip based on >>>>>>>> "valid_page" which is set if scanning started on a pageblock boundary. >>>>>>>> >>>>>>>> Signed-off-by: Mel Gorman >>>>>>> >>>>>>> I wonder if this has an unintended side-effect that if we resume >>>>>>> isolate_migratepages_block() of a partially compacted pageblock to finish >>>>>>> it, test_and_set_skip() will now tell us to abort, because we already set >>>>>>> the skip bit in the previous call. This would include the >>>>>>> cc->finish_pageblock rescan cases. >>>>>>> >>>>>>> So unless I miss something that already prevents that, I agree we should not >>>>>>> tie setting the skip bit to pageblock_aligned(pfn), but maybe if we are not >>>>>>> pageblock aligned, we should ignore the already-set skip bit, as it was most >>>>>>> likely being set by us in the previous iteration and should not prevent us >>>>>>> from finishing the pageblock? >>>>>>> >>>>>> >>>>>> Hmm, I think you're right. While it should not hit the original bug, >>>>>> migration candidates are missed until the next compaction scan which >>>>>> could be tricky to detect. Something like this as a separate patch? >>>>>> Build tested only but the intent is for an unaligned start to set the skip >>>>>> bet if already unset but otherwise complete the scan. Like earlier fixes, >>>>>> this might overscan some pageblocks in a given context but we are probably >>>>>> hitting the limits on how compaction can run efficiently in the current >>>>>> scheme without causing other side-effects :( >>>>> >>>>> Yeah that should work! I think it should be even folded to 3/4 but if you >>>>> want separate, fine too. >>>>> >>>> >>>> I was not happy with the test results so limited the scope of the patch >>>> which performed much better both in terms of absolute performance and >>>> compaction activity. >>> >>> That's surprising. Does that mean that if we isolate COMPACT_CLUSTER_MAX >>> pages, migrate them without failing, but it's not enough to succeed (i.e. >>> there are more pages we need to migrate to free up a whole pageblock), it's >>> better to give up on the rest of the pageblock rather than continue? >> >> I don't have precise enough data to answer that with certainty but probably >> yes, at least in terms of scan activity. The first version had spikes of >> pages scanned for migration that are not always reproducible and not on >> all machines. > > Well, that kinda sucks. So for the patch (with adding the missing NOT below). > > Acked-by: Vlastimil Babka > > But in raises a question whether we should terminate compaction under the > right conditions after a successful migration immediately, rather than > invoke another iteration of isolate_migratepages_block() where we could skip > over some pages uselessly only to abort at first valid page due to the skip bit. > It would save some cycles and be much more obvious than now, where anyone > trying to understand how it works in detail might conclude it's an oversight? IIUC, for direct compactor, we can terminate compaction if there is a suitable free page, that means other pages scanning in this pageblock are uselessly like you said, and we can skip them to save cpu cycles. So we can remove below COMPACT_CONTINUE validation in __compact_finished(): /* * Always finish scanning a pageblock to reduce the possibility of * fallbacks in the future. This is particularly important when * migration source is unmovable/reclaimable but it's not worth * special casing. */ if (!pageblock_aligned(cc->migrate_pfn)) return COMPACT_CONTINUE; And in this case, we also should call update_cached_migrate() to record the partial cc->migrate_pfn, which is the start position for next scanning. Please correct me if I missed something. Thanks. >>> As >>> that's AFAIU the scenario where cc->finish_pageblock is false when we >>> revisit an unfinished pageblock. >>> >>>> Are you still ok with this version? >>> >>> It's better than previously in that cc->finish_pageblock == true case is not >>> sabotaged anymore. But the result as described above seems to be a weird >>> non-intuitive and non-obvious heuristic. How did the test differences look like? >>> >> >> 5 machines were tested in all (different Intel and AMD generations), >> 2 showed unexpected spikes in scan activity. 1 showed high migration >> scan counts for workloads workload-thpchallenge-kernel-build-xfs >> and workload-usemem-stress-numa-compact. They are both basically >> compaction stressors with the first one using a kernel build >> in the background to generate noise. For the second machine, only >> workload-usemem-stress-numa-compact was affected. In all other test cases >> and machines, the patches were equivalent in terms of behaviour but the >> extreme counter-examples led be to conclude the fix should be as constrained >> as possible unless there is a good reason to do otherwise. >> >>>> Vlastimil Babka pointed out the following problem with >>>> mm-compaction-update-pageblock-skip-when-first-migration-candidate-is-not-at-the-start.patch >>>> >>>> I wonder if this has an unintended side-effect that if we resume >>>> isolate_migratepages_block() of a partially compacted pageblock >>>> to finish it, test_and_set_skip() will now tell us to abort, >>>> because we already set the skip bit in the previous call. This >>>> would include the cc->finish_pageblock rescan cases. >>>> >>>> He is correct and a partial rescan as implemented in "mm, compaction: >>>> finish pageblocks on complete migration failure" would abort >>>> prematurely. >>>> >>>> Test and set the skip bit when acquiring "exclusive access" to a pageblock >>>> for migration but only abort if the calling context is rescanning to >>>> finish a pageblock. >>> >>> Should it say NOT rescanning to finish a pageblock? >>> >> >> Yep, it should. The sentence was a last minute update before pushing >> send :( >> >