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 X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 89F15C4361A for ; Fri, 4 Dec 2020 15:51:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 18CA222C97 for ; Fri, 4 Dec 2020 15:51:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 18CA222C97 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8C0A06B0073; Fri, 4 Dec 2020 10:51:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 872DC6B0074; Fri, 4 Dec 2020 10:51:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7882D6B0075; Fri, 4 Dec 2020 10:51:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0050.hostedemail.com [216.40.44.50]) by kanga.kvack.org (Postfix) with ESMTP id 61B6D6B0073 for ; Fri, 4 Dec 2020 10:51:21 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 2BEAF8249980 for ; Fri, 4 Dec 2020 15:51:21 +0000 (UTC) X-FDA: 77556039162.03.view72_3c17f58273c5 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin03.hostedemail.com (Postfix) with ESMTP id BC28128A4E9 for ; Fri, 4 Dec 2020 15:51:20 +0000 (UTC) X-HE-Tag: view72_3c17f58273c5 X-Filterd-Recvd-Size: 5333 Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Fri, 4 Dec 2020 15:51:20 +0000 (UTC) Received: by mail-pl1-f193.google.com with SMTP id y10so1855236plr.10 for ; Fri, 04 Dec 2020 07:51:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=n5W6880DKqAIq9417CXiZaILeavNMzWEyfMm3u4YBRE=; b=09RJ7j13Vuz2H2XyZMov0ihLgHO7ayJoLXI8ilqaksMNwAhdRcn43F2QXpQ3A2gd0+ 07ks051irH922qS/kso+dQmpyR4jv4VOem3NsaHrBR5NyntmE7VU6EdPVDrct+CJZrR9 ORTuNz256TD8L4mhU5tFqK/zVVV3MDpQJLVHrM0Id3l/naW1571tc6tkWZcS6y1jtOs1 CMKpMKE74A/kEYdJDeUqMx61yTIjlTdiyuyencXRJ5AKleLzpSx0Rgx8fJICdbjzf1Ft ORe52RyMXqtU3Lt6x2T+PAPE6+W/B6ioQtJsPcSEN/ZyENEus3JIBybaNxNFDs7hmoH3 wixQ== 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=n5W6880DKqAIq9417CXiZaILeavNMzWEyfMm3u4YBRE=; b=bHxK+nFPEcnl3wk4uBxkLs2aRkLB7BWZHUe5zZ0rnR7wnO0+9evnQrJA/sAXM2PRen SKWH95cx5fxO94A52TXZFUR1+e7fIlQJhUjutn2ZWtLZM3DA7UAWDHl6NpxBHPO2+VgB rpDeLahp3Qr7cgGy1239af21F05oxO8rU8qwm1Kx53qBr+7vt1YhGnRdP8GXEe+4t1xX 1TV77mVwfCS2aqv50zR1F161BZpQKOwwZK1MLFLHSo8RTDeEM9M59fUhA3QwMnZRS2C1 W/qddypAyXNfL4pf6wijmXVfbry0h3E50+VeSW6P1KrEt+7U6CVSRpA56FXsIw/vGaJR mt4Q== X-Gm-Message-State: AOAM532OMQb20s6UBXs4AAZrU1PW1ia4gBDJkNmdQ03OcCtGtS7iRJ1a 74FkWkKxybz1JzSx0cNGulxcgg== X-Google-Smtp-Source: ABdhPJwCc0IIsjbR0gYu1dcq7gxf9VoEsp2MROjWpOwTMgKpWPZ+lXyQsgYg/lRkxsgL+7tC4KQuzw== X-Received: by 2002:a17:90a:940c:: with SMTP id r12mr4592347pjo.201.1607097079193; Fri, 04 Dec 2020 07:51:19 -0800 (PST) Received: from localhost.bytedance.net ([103.136.220.120]) by smtp.gmail.com with ESMTPSA id m7sm5626617pfh.72.2020.12.04.07.51.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Dec 2020 07:51:18 -0800 (PST) From: Muchun Song To: akpm@linux-foundation.org, vbabka@suse.cz Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH v3] mm/page_alloc: speeding up the iteration of max_order Date: Fri, 4 Dec 2020 23:51:09 +0800 Message-Id: <20201204155109.55451-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: When we free a page whose order is very close to MAX_ORDER and greater than pageblock_order, it wastes some CPU cycles to increase max_order to MAX_ORDER one by one and check the pageblock migratetype of that page repeatedly especially when MAX_ORDER is much larger than pageblock_order. We also should not be checking migratetype of buddy when "order =3D=3D MAX_ORDER - 1" as the buddy pfn may be invalid, so adjust the condition. With the new check, we don't need the max_order check anymore, so we replace it. Also adjust max_order initialization so that it's lower by one than previously, which makes the code hopefully more clear. Fixes: d9dddbf55667 ("mm/page_alloc: prevent merging between isolated and= other pageblocks") Signed-off-by: Muchun Song Acked-by: Vlastimil Babka --- Changes in v3: - Update commit log. Changes in v2: - Rework the code suggested by Vlastimil. Thanks. mm/page_alloc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index f91df593bf71..56e603eea1dd 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1002,7 +1002,7 @@ static inline void __free_one_page(struct page *pag= e, struct page *buddy; bool to_tail; =20 - max_order =3D min_t(unsigned int, MAX_ORDER, pageblock_order + 1); + max_order =3D min_t(unsigned int, MAX_ORDER - 1, pageblock_order); =20 VM_BUG_ON(!zone_is_initialized(zone)); VM_BUG_ON_PAGE(page->flags & PAGE_FLAGS_CHECK_AT_PREP, page); @@ -1015,7 +1015,7 @@ static inline void __free_one_page(struct page *pag= e, VM_BUG_ON_PAGE(bad_range(zone, page), page); =20 continue_merging: - while (order < max_order - 1) { + while (order < max_order) { if (compaction_capture(capc, page, order, migratetype)) { __mod_zone_freepage_state(zone, -(1 << order), migratetype); @@ -1041,7 +1041,7 @@ static inline void __free_one_page(struct page *pag= e, pfn =3D combined_pfn; order++; } - if (max_order < MAX_ORDER) { + if (order < MAX_ORDER - 1) { /* If we are here, it means order is >=3D pageblock_order. * We want to prevent merge between freepages on isolate * pageblock and normal pageblock. Without this, pageblock @@ -1062,7 +1062,7 @@ static inline void __free_one_page(struct page *pag= e, is_migrate_isolate(buddy_mt))) goto done_merging; } - max_order++; + max_order =3D order + 1; goto continue_merging; } =20 --=20 2.11.0