Message ID | 20230805110711.2975149-5-shikemeng@huaweicloud.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp241506vqr; Fri, 4 Aug 2023 20:23:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEqCGOWd2MScrhYsrUILeiejkpZe+q4qyAjjTxcPpWLADr2tnUYUQu7oUmmY2SgswHwa7f/ X-Received: by 2002:a05:6a20:42a0:b0:130:835b:e260 with SMTP id o32-20020a056a2042a000b00130835be260mr3664722pzj.52.1691205812238; Fri, 04 Aug 2023 20:23:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691205812; cv=none; d=google.com; s=arc-20160816; b=Y94x6sWzU4BaOdc4DGURJ4uKumplNS6oLHJbdjpYx7MwwfT9Mp1lvMtFpTQm8xSE4H cXZnEwvoUwlZXInIJTvVmTi6CVodsO0gbYzSpf0Ez2UdRJISmk6AZWulhjy5bTWs/5xI ujkyW+RiuETF0+sDKTS4vmmkh2kjwIVvEF4ym9ilKgJ66w4EuF5v/AdB3i3dzAPDtSou ufMUEm5iEOFLz+PLATBo3oRvDMmDdtb8gSvBiE2rhQiEW5UhYexL26iKYnXmeG9hHWKh /wZuV895rhIpHqxxUjOX45pzK+L40akw8oI45wW4tkXlAiLs6OHjuY621dPB774nHQAZ 7otA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=BahqPjU4dvuuAUKhAcST1uwOFuiPd6XRA8SSc/fHL9U=; fh=zpCCF/J8Z0sUUNZfCNdnaRvm94yhXPVxl9PzV22VU6k=; b=vvIWaL07D1atlJIT2C3IuAYzPbtHzOMSYLLKoHZ0aTgf4/jciOp/S/sEUjJ2GO5ifL tug+Ds5Ag4GnfZv75HVBhhv9rL+QT5CySscQ9qqT2CDLLx/cmjYsajOFfoUoy9G9Dxrm 5hwHeuyi7Y2JUAzPawlO7yN8Bd+TiBmnjlhtXRYWK2DtW4klCGnaXY3Qc1gcQ4Uz5ZSW bUspWqc3nPjzeQat3ANUHfXj27PlB8T5Qv6M7gfJgoJiP1VSUMNH+uZHt5u8FVtujUys HiiHyE4pYK91eIDh5prM+3uXtYL58o8LU7q95Axj8g2uP9PfF4JPGk6g9ZwHXrQaHfWO XZOg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i8-20020a17090332c800b001ac6d4e1d72si2788084plr.149.2023.08.04.20.23.19; Fri, 04 Aug 2023 20:23:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229809AbjHEDH1 (ORCPT <rfc822;liqunnana@gmail.com> + 99 others); Fri, 4 Aug 2023 23:07:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229558AbjHEDHH (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 4 Aug 2023 23:07:07 -0400 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A26014EE6 for <linux-kernel@vger.kernel.org>; Fri, 4 Aug 2023 20:07:02 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4RHnYb2KYsz4f3jZ6 for <linux-kernel@vger.kernel.org>; Sat, 5 Aug 2023 11:06:59 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP4 (Coremail) with SMTP id gCh0CgAHvrHQvM1k6A5ePg--.23962S6; Sat, 05 Aug 2023 11:06:59 +0800 (CST) From: Kemeng Shi <shikemeng@huaweicloud.com> To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, baolin.wang@linux.alibaba.com, mgorman@techsingularity.net, david@redhat.com Cc: shikemeng@huaweicloud.com Subject: [PATCH 4/9] mm/compaction: simplify pfn iteration in isolate_freepages_range Date: Sat, 5 Aug 2023 19:07:06 +0800 Message-Id: <20230805110711.2975149-5-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230805110711.2975149-1-shikemeng@huaweicloud.com> References: <20230805110711.2975149-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgAHvrHQvM1k6A5ePg--.23962S6 X-Coremail-Antispam: 1UD129KBjvJXoW7uryUKw17Zw15Jr4rZw4rAFb_yoW8Xr43pa 47C3WIgr1UCayYgF17Z3yDZw15Gws8GF4UGr4UJF1rZF9YkF97Kas2yrykXFy0v34xArZ0 vrZrKFWxKw4UZa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2jI8I6cxK62vIxIIY0VWUZVW8XwA2048vs2IY02 0E87I2jVAFwI0_JF0E3s1l82xGYIkIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0 rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6x IIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xv wVC2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFc xC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_ Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2 IErcIFxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r 4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0pRvJPtU UUUU= X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=0.1 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773357825838294034 X-GMAIL-MSGID: 1773357825838294034 |
Series |
Fixes and cleanups to compaction
|
|
Commit Message
Kemeng Shi
Aug. 5, 2023, 11:07 a.m. UTC
We call isolate_freepages_block in strict mode, continuous pages in
pageblock will be isolated if isolate_freepages_block successed.
Then pfn + isolated will point to start of next pageblock to scan
no matter how many pageblocks are isolated in isolate_freepages_block.
Use pfn + isolated as start of next pageblock to scan to simplify the
iteration.
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
mm/compaction.c | 14 ++------------
1 file changed, 2 insertions(+), 12 deletions(-)
Comments
On 8/5/2023 7:07 PM, Kemeng Shi wrote: > We call isolate_freepages_block in strict mode, continuous pages in > pageblock will be isolated if isolate_freepages_block successed. > Then pfn + isolated will point to start of next pageblock to scan > no matter how many pageblocks are isolated in isolate_freepages_block. > Use pfn + isolated as start of next pageblock to scan to simplify the > iteration. IIUC, the isolate_freepages_block() can isolate high-order free pages, which means the pfn + isolated can be larger than the block_end_pfn. So in your patch, the 'block_start_pfn' and 'block_end_pfn' can be in different pageblocks, that will break pageblock_pfn_to_page(). > > Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com> > --- > mm/compaction.c | 14 ++------------ > 1 file changed, 2 insertions(+), 12 deletions(-) > > diff --git a/mm/compaction.c b/mm/compaction.c > index 684f6e6cd8bc..8d7d38073d30 100644 > --- a/mm/compaction.c > +++ b/mm/compaction.c > @@ -733,21 +733,11 @@ isolate_freepages_range(struct compact_control *cc, > block_end_pfn = pageblock_end_pfn(pfn); > > for (; pfn < end_pfn; pfn += isolated, > - block_start_pfn = block_end_pfn, > - block_end_pfn += pageblock_nr_pages) { > + block_start_pfn = pfn, > + block_end_pfn = pfn + pageblock_nr_pages) { > /* Protect pfn from changing by isolate_freepages_block */ > unsigned long isolate_start_pfn = pfn; > > - /* > - * pfn could pass the block_end_pfn if isolated freepage > - * is more than pageblock order. In this case, we adjust > - * scanning range to right one. > - */ > - if (pfn >= block_end_pfn) { > - block_start_pfn = pageblock_start_pfn(pfn); > - block_end_pfn = pageblock_end_pfn(pfn); > - } > - > block_end_pfn = min(block_end_pfn, end_pfn); > > if (!pageblock_pfn_to_page(block_start_pfn,
on 8/15/2023 4:38 PM, Baolin Wang wrote: > > > On 8/5/2023 7:07 PM, Kemeng Shi wrote: >> We call isolate_freepages_block in strict mode, continuous pages in >> pageblock will be isolated if isolate_freepages_block successed. >> Then pfn + isolated will point to start of next pageblock to scan >> no matter how many pageblocks are isolated in isolate_freepages_block. >> Use pfn + isolated as start of next pageblock to scan to simplify the >> iteration. > > IIUC, the isolate_freepages_block() can isolate high-order free pages, which means the pfn + isolated can be larger than the block_end_pfn. So in your patch, the 'block_start_pfn' and 'block_end_pfn' can be in different pageblocks, that will break pageblock_pfn_to_page(). > In for update statement, we always update block_start_pfn to pfn and update block_end_pfn to pfn + pageblock_nr_pages. So they should point to the same pageblock. I guess you missed the change to update of block_end_pfn. :) >> >> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com> >> --- >> mm/compaction.c | 14 ++------------ >> 1 file changed, 2 insertions(+), 12 deletions(-) >> >> diff --git a/mm/compaction.c b/mm/compaction.c >> index 684f6e6cd8bc..8d7d38073d30 100644 >> --- a/mm/compaction.c >> +++ b/mm/compaction.c >> @@ -733,21 +733,11 @@ isolate_freepages_range(struct compact_control *cc, >> block_end_pfn = pageblock_end_pfn(pfn); >> for (; pfn < end_pfn; pfn += isolated, >> - block_start_pfn = block_end_pfn, >> - block_end_pfn += pageblock_nr_pages) { >> + block_start_pfn = pfn, >> + block_end_pfn = pfn + pageblock_nr_pages) { >> /* Protect pfn from changing by isolate_freepages_block */ >> unsigned long isolate_start_pfn = pfn; >> - /* >> - * pfn could pass the block_end_pfn if isolated freepage >> - * is more than pageblock order. In this case, we adjust >> - * scanning range to right one. >> - */ >> - if (pfn >= block_end_pfn) { >> - block_start_pfn = pageblock_start_pfn(pfn); >> - block_end_pfn = pageblock_end_pfn(pfn); >> - } >> - >> block_end_pfn = min(block_end_pfn, end_pfn); >> if (!pageblock_pfn_to_page(block_start_pfn, >
on 8/15/2023 6:07 PM, Baolin Wang wrote: > > > On 8/15/2023 5:32 PM, Kemeng Shi wrote: >> >> >> on 8/15/2023 4:38 PM, Baolin Wang wrote: >>> >>> >>> On 8/5/2023 7:07 PM, Kemeng Shi wrote: >>>> We call isolate_freepages_block in strict mode, continuous pages in >>>> pageblock will be isolated if isolate_freepages_block successed. >>>> Then pfn + isolated will point to start of next pageblock to scan >>>> no matter how many pageblocks are isolated in isolate_freepages_block. >>>> Use pfn + isolated as start of next pageblock to scan to simplify the >>>> iteration. >>> >>> IIUC, the isolate_freepages_block() can isolate high-order free pages, which means the pfn + isolated can be larger than the block_end_pfn. So in your patch, the 'block_start_pfn' and 'block_end_pfn' can be in different pageblocks, that will break pageblock_pfn_to_page(). >>> >> In for update statement, we always update block_start_pfn to pfn and > > I mean, you changed to: > 1) pfn += isolated; > 2) block_start_pfn = pfn; > 3) block_end_pfn = pfn + pageblock_nr_pages; > > But in 1) pfn + isolated can go outside of the currnet pageblock if isolating a high-order page, for example, located in the middle of the next pageblock. So that the block_start_pfn can point to the middle of the next pageblock, not the start position. Meanwhile after 3), the block_end_pfn can point another pageblock. Or I missed something else? > Ah, I miss to explain this in changelog. In case we could we have buddy page with order higher than pageblock: 1. page in buddy page is aligned with it's order 2. order of page is higher than pageblock order Then page is aligned with pageblock order. So pfn of page and isolated pages count are both aligned pageblock order. So pfn + isolated is pageblock order aligned. >> update block_end_pfn to pfn + pageblock_nr_pages. So they should point >> to the same pageblock. I guess you missed the change to update of >> block_end_pfn. :) >>>> >>>> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com> >>>> --- >>>> mm/compaction.c | 14 ++------------ >>>> 1 file changed, 2 insertions(+), 12 deletions(-) >>>> >>>> diff --git a/mm/compaction.c b/mm/compaction.c >>>> index 684f6e6cd8bc..8d7d38073d30 100644 >>>> --- a/mm/compaction.c >>>> +++ b/mm/compaction.c >>>> @@ -733,21 +733,11 @@ isolate_freepages_range(struct compact_control *cc, >>>> block_end_pfn = pageblock_end_pfn(pfn); >>>> for (; pfn < end_pfn; pfn += isolated, >>>> - block_start_pfn = block_end_pfn, >>>> - block_end_pfn += pageblock_nr_pages) { >>>> + block_start_pfn = pfn, >>>> + block_end_pfn = pfn + pageblock_nr_pages) { >>>> /* Protect pfn from changing by isolate_freepages_block */ >>>> unsigned long isolate_start_pfn = pfn; >>>> - /* >>>> - * pfn could pass the block_end_pfn if isolated freepage >>>> - * is more than pageblock order. In this case, we adjust >>>> - * scanning range to right one. >>>> - */ >>>> - if (pfn >= block_end_pfn) { >>>> - block_start_pfn = pageblock_start_pfn(pfn); >>>> - block_end_pfn = pageblock_end_pfn(pfn); >>>> - } >>>> - >>>> block_end_pfn = min(block_end_pfn, end_pfn); >>>> if (!pageblock_pfn_to_page(block_start_pfn, >>> >
on 8/19/2023 7:58 PM, Baolin Wang wrote: > > > On 8/15/2023 6:37 PM, Kemeng Shi wrote: >> >> >> on 8/15/2023 6:07 PM, Baolin Wang wrote: >>> >>> >>> On 8/15/2023 5:32 PM, Kemeng Shi wrote: >>>> >>>> >>>> on 8/15/2023 4:38 PM, Baolin Wang wrote: >>>>> >>>>> >>>>> On 8/5/2023 7:07 PM, Kemeng Shi wrote: >>>>>> We call isolate_freepages_block in strict mode, continuous pages in >>>>>> pageblock will be isolated if isolate_freepages_block successed. >>>>>> Then pfn + isolated will point to start of next pageblock to scan >>>>>> no matter how many pageblocks are isolated in isolate_freepages_block. >>>>>> Use pfn + isolated as start of next pageblock to scan to simplify the >>>>>> iteration. >>>>> >>>>> IIUC, the isolate_freepages_block() can isolate high-order free pages, which means the pfn + isolated can be larger than the block_end_pfn. So in your patch, the 'block_start_pfn' and 'block_end_pfn' can be in different pageblocks, that will break pageblock_pfn_to_page(). >>>>> >>>> In for update statement, we always update block_start_pfn to pfn and >>> >>> I mean, you changed to: >>> 1) pfn += isolated; >>> 2) block_start_pfn = pfn; >>> 3) block_end_pfn = pfn + pageblock_nr_pages; >>> >>> But in 1) pfn + isolated can go outside of the currnet pageblock if isolating a high-order page, for example, located in the middle of the next pageblock. So that the block_start_pfn can point to the middle of the next pageblock, not the start position. Meanwhile after 3), the block_end_pfn can point another pageblock. Or I missed something else? >>> >> Ah, I miss to explain this in changelog. >> In case we could we have buddy page with order higher than pageblock: >> 1. page in buddy page is aligned with it's order >> 2. order of page is higher than pageblock order >> Then page is aligned with pageblock order. So pfn of page and isolated pages >> count are both aligned pageblock order. So pfn + isolated is pageblock order >> aligned. > > That's not what I mean. pfn + isolated is not always pageblock-aligned, since the isolate_freepages_block() can isolated high-order free pages (for example: order-1, order-2 ...). > > Suppose the pageblock size is 2M, when isolating a pageblock (suppose the pfn range is 0 - 511 to make the arithmetic easy) by isolate_freepages_block(), and suppose pfn 0 to pfn 510 are all order-0 page, but pfn 511 is order-1 page, so you will isolate 513 pages from this pageblock, which will make 'pfn + isolated' not pageblock aligned. This is also no supposed to happen as low order buddy pages should never span cross boundary of high order pages: In buddy system, we always split order N pages into two order N - 1 pages as following: | order N | |order N - 1|order N - 1| So buddy pages with order N - 1 will never cross boudary of order N. Similar, buddy pages with order N - 2 will never cross boudary of order N - 1 and so on. Then any pages with order less than N will never cross boudary of order N. > >>>> update block_end_pfn to pfn + pageblock_nr_pages. So they should point >>>> to the same pageblock. I guess you missed the change to update of >>>> block_end_pfn. :) >>>>>> >>>>>> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com> >>>>>> --- >>>>>> mm/compaction.c | 14 ++------------ >>>>>> 1 file changed, 2 insertions(+), 12 deletions(-) >>>>>> >>>>>> diff --git a/mm/compaction.c b/mm/compaction.c >>>>>> index 684f6e6cd8bc..8d7d38073d30 100644 >>>>>> --- a/mm/compaction.c >>>>>> +++ b/mm/compaction.c >>>>>> @@ -733,21 +733,11 @@ isolate_freepages_range(struct compact_control *cc, >>>>>> block_end_pfn = pageblock_end_pfn(pfn); >>>>>> for (; pfn < end_pfn; pfn += isolated, >>>>>> - block_start_pfn = block_end_pfn, >>>>>> - block_end_pfn += pageblock_nr_pages) { >>>>>> + block_start_pfn = pfn, >>>>>> + block_end_pfn = pfn + pageblock_nr_pages) { >>>>>> /* Protect pfn from changing by isolate_freepages_block */ >>>>>> unsigned long isolate_start_pfn = pfn; >>>>>> - /* >>>>>> - * pfn could pass the block_end_pfn if isolated freepage >>>>>> - * is more than pageblock order. In this case, we adjust >>>>>> - * scanning range to right one. >>>>>> - */ >>>>>> - if (pfn >= block_end_pfn) { >>>>>> - block_start_pfn = pageblock_start_pfn(pfn); >>>>>> - block_end_pfn = pageblock_end_pfn(pfn); >>>>>> - } >>>>>> - >>>>>> block_end_pfn = min(block_end_pfn, end_pfn); >>>>>> if (!pageblock_pfn_to_page(block_start_pfn, >>>>> >>> > >
diff --git a/mm/compaction.c b/mm/compaction.c index 684f6e6cd8bc..8d7d38073d30 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -733,21 +733,11 @@ isolate_freepages_range(struct compact_control *cc, block_end_pfn = pageblock_end_pfn(pfn); for (; pfn < end_pfn; pfn += isolated, - block_start_pfn = block_end_pfn, - block_end_pfn += pageblock_nr_pages) { + block_start_pfn = pfn, + block_end_pfn = pfn + pageblock_nr_pages) { /* Protect pfn from changing by isolate_freepages_block */ unsigned long isolate_start_pfn = pfn; - /* - * pfn could pass the block_end_pfn if isolated freepage - * is more than pageblock order. In this case, we adjust - * scanning range to right one. - */ - if (pfn >= block_end_pfn) { - block_start_pfn = pageblock_start_pfn(pfn); - block_end_pfn = pageblock_end_pfn(pfn); - } - block_end_pfn = min(block_end_pfn, end_pfn); if (!pageblock_pfn_to_page(block_start_pfn,