From patchwork Sun Apr 23 10:59:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 86689 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2136046vqo; Sun, 23 Apr 2023 04:04:15 -0700 (PDT) X-Google-Smtp-Source: AKy350ayNbhBmt6W8Lu2NCY1o9vvjl61P55IQfIs/a2d2HSk138VHurWv8bK3pgvcmeKWMKppRQl X-Received: by 2002:a05:6a20:d489:b0:d9:f086:e756 with SMTP id im9-20020a056a20d48900b000d9f086e756mr11051903pzb.39.1682247855270; Sun, 23 Apr 2023 04:04:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682247855; cv=none; d=google.com; s=arc-20160816; b=GqxfFFaTYGmvsyRLdxZHUIqHBSNFjdADrYx3IEm8YA9UJhD6/NmhxEOO3JRERSeHEj OmiM99TGB6vBFk51eagFGIxi46IOSSas4CWyPWDtoHNJPZcj1o5oCaAlt3rojy0rw31p 2XZn0Hu8ed+FnqDJGTAwK9Z3q0flbt//mVHClFWzU0lviRIYNb2PE6i61Cde83i6wAE0 Oz0CYChTOkZLDVC7j+Qj786Hh1IVw4zSTrXG9ySplzPJVj7VENqAU6VmD15upuTJgf7t 1CNYfrAVojs6myY+OJECvF1CGJnUjPjVhlptjO4o21tkwpsf16Ea7wW950yK+02hvFQ5 M/FA== 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 :message-id:date:subject:cc:to:from; bh=64GR5p2l4Z02IYdj0MM9eN1KhH4FGFdVF8hApvUlZkI=; b=JrRPL85B5J9xp6rBiVN/YqXwZgITamnaS5ixn3qH+cS5FYoyn9MyO7KiZHYKrSXF98 9ABSxczz+t7zoQeaPpyPnQTfGLNBb+WxzbNe/dGIKIkn9HWw0fCXPq0YrCk5WYGgjSUH r6Xrp684j4luT/cxxwOEQnJkPXz1calNln2wfHLj46lan4r4ZKXxzLevl7SIZ27G6jJy ERotAvt8lJy0sp6VPoih8nB2T3PGMED300g3YmYI8nb2SHgOz2iP6kWgJN6vf5Lh6PdU Xb7/SBE+VE5PgkFFjTj9gIO301Fq7euAG8DdYYrMswgyIrQwZZ3YOcH7G5kcP7Pjzbei KyxQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a28-20020aa78e9c000000b0063b7c4435bcsi9069408pfr.50.2023.04.23.04.04.00; Sun, 23 Apr 2023 04:04:15 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229523AbjDWLAc (ORCPT + 99 others); Sun, 23 Apr 2023 07:00:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229595AbjDWLAH (ORCPT ); Sun, 23 Apr 2023 07:00:07 -0400 Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 041D11997 for ; Sun, 23 Apr 2023 03:59:42 -0700 (PDT) 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=ay29a033018046050;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0VgjkYeH_1682247579; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VgjkYeH_1682247579) by smtp.aliyun-inc.com; Sun, 23 Apr 2023 18:59:40 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: rppt@kernel.org, ying.huang@intel.com, mgorman@techsingularity.net, vbabka@suse.cz, mhocko@suse.com, david@redhat.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] mm/page_alloc: drop the unnecessary pfn_valid() for start pfn Date: Sun, 23 Apr 2023 18:59:10 +0800 Message-Id: <9fc85cce8908938f4fd75ff50bc981c073779aa5.1682229876.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763964727027523520?= X-GMAIL-MSGID: =?utf-8?q?1763964727027523520?= We've already used pfn_to_online_page() for start pfn to make sure it is online and valid, so the pfn_valid() for the start pfn is unnecessary, drop it. Signed-off-by: Baolin Wang Reviewed-by: David Hildenbrand Reviewed-by: "Huang, Ying" Acked-by: Michal Hocko --- Changes from v1: - Collect reviewed tags. Thanks David and Ying. --- mm/page_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 9de2a18519a1..6457b64fe562 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1512,7 +1512,7 @@ struct page *__pageblock_pfn_to_page(unsigned long start_pfn, /* end_pfn is one past the range we are checking */ end_pfn--; - if (!pfn_valid(start_pfn) || !pfn_valid(end_pfn)) + if (!pfn_valid(end_pfn)) return NULL; start_page = pfn_to_online_page(start_pfn); From patchwork Sun Apr 23 10:59:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 86688 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2134472vqo; Sun, 23 Apr 2023 04:01:19 -0700 (PDT) X-Google-Smtp-Source: AKy350YEnqCGdAGDi1Kzz88rSOZW8Y8ZOBdNKX+jtzmwhH9kOfqGDcspAjlvyqRqllM2/dlJLm0G X-Received: by 2002:a17:903:1250:b0:1a6:cd08:5594 with SMTP id u16-20020a170903125000b001a6cd085594mr12012444plh.69.1682247678727; Sun, 23 Apr 2023 04:01:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682247678; cv=none; d=google.com; s=arc-20160816; b=O+t8FNIvqxzCNKmDV6ww/07J2srP2/JRubTBTctNuAAU9lBjKyPD2HeM4TNm9ZeH2f +rXexC5UQttpzMfkQ3OpLtVdWYpBGRDRaTeJfUPWkYl4wOP/bgneaDx3pmFyTppIY9B6 Tp22FhQYAF8ZLrHlZGP+uDGHyStSZI3LaZjRLPcPLcQ4AXB37ncyOXtzdhWgv8V6PtQK YH8F1VmDeimkTsm7ZsPdgpokFamjIopdLzwmmKYfHxXRnMFHxLacJ14fG9ftp+5Wb+La yiWa7/iECW5+pEHiCzg4tVGCfC8oAv1WQoYYLsNJ1E+uaA3CYFhjeKj0UBHHaXGLugdF 6ykQ== 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=LIqsSOzpJnrF9Fm+xJnpVjcr3PBFv0oWSPLLsllAJ6Q=; b=YFZ0x4c0Vn5UKcpOTv3HyJqfN/o9kQLCWPMIFOu470ERjReV7sTvvYrfku/EI+1TRD Dbg4itPRfHowgOneHONoDSkyLtzYOrjLtdJdXXfQT83TM4ewp7IFJUxWk7T6auSxUg/4 HOP5p2F07pJ19ZA0CSZfFW9w9MDsuLAlQIPL6SwIyXj51pfuJ5duZNVIJsc4PmI/MNMe u2rFrmCS1vGLKOa/X6Y0CLfo/0IFI4b+A9BzMDVkft7daAa+zMjA89pX7k+e2uGU/6Y/ nNiJ6MELAFReFX5Hed22wL8PGJg+qnthugVhwe1vFMymSeNt3WBL5VUDQWmXGIfBASss NFrw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j4-20020a170902758400b001a1f70cc7dbsi8283890pll.562.2023.04.23.04.01.05; Sun, 23 Apr 2023 04:01:18 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229695AbjDWLAg (ORCPT + 99 others); Sun, 23 Apr 2023 07:00:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229843AbjDWLAH (ORCPT ); Sun, 23 Apr 2023 07:00:07 -0400 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20F771728 for ; Sun, 23 Apr 2023 03:59:43 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0VgjjRNn_1682247580; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VgjjRNn_1682247580) by smtp.aliyun-inc.com; Sun, 23 Apr 2023 18:59:41 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: rppt@kernel.org, ying.huang@intel.com, mgorman@techsingularity.net, vbabka@suse.cz, mhocko@suse.com, david@redhat.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] mm/page_alloc: add some comments to explain the possible hole in __pageblock_pfn_to_page() Date: Sun, 23 Apr 2023 18:59:11 +0800 Message-Id: <0733a4cf57109a4136de5ae46fac83fb15bdd528.1682229876.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <9fc85cce8908938f4fd75ff50bc981c073779aa5.1682229876.git.baolin.wang@linux.alibaba.com> References: <9fc85cce8908938f4fd75ff50bc981c073779aa5.1682229876.git.baolin.wang@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763964542089554778?= X-GMAIL-MSGID: =?utf-8?q?1763964542089554778?= Now the __pageblock_pfn_to_page() is used by set_zone_contiguous(), which checks whether the given zone contains holes, and uses pfn_to_online_page() to validate if the start pfn is online and valid, as well as using pfn_valid() to validate the end pfn. However, the __pageblock_pfn_to_page() function may return non-NULL even if the end pfn of a pageblock is in a memory hole in some situations. For example, if the pageblock order is MAX_ORDER, which will fall into 2 sub-sections, and the end pfn of the pageblock may be hole even though the start pfn is online and valid. This did not break anything until now, but the zone continuous is fragile in this possible scenario. So as previous discussion[1], it is better to add some comments to explain this possible issue in case there are some future pfn walkers that rely on this. [1] https://lore.kernel.org/all/87r0sdsmr6.fsf@yhuang6-desk2.ccr.corp.intel.com/ Signed-off-by: Baolin Wang Reviewed-by: "Huang, Ying" --- Changes from v1: - Update the comments per Ying and Mike, thanks. --- mm/page_alloc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 6457b64fe562..9756d66f471c 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1502,6 +1502,13 @@ void __free_pages_core(struct page *page, unsigned int order) * interleaving within a single pageblock. It is therefore sufficient to check * the first and last page of a pageblock and avoid checking each individual * page in a pageblock. + * + * Note: the function may return non-NULL even if the end pfn of a pageblock + * is in a memory hole in some situations. For example, if the pageblock + * order is MAX_ORDER, which will fall into 2 sub-sections, and the end pfn + * of the pageblock may be hole even though the start pfn is online and valid. + * This did not break anything until now, but be careful about this possible + * issue when checking whether all pfns of a pageblock are valid. */ struct page *__pageblock_pfn_to_page(unsigned long start_pfn, unsigned long end_pfn, struct zone *zone)