Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp801599rwl; Wed, 12 Apr 2023 04:28:29 -0700 (PDT) X-Google-Smtp-Source: AKy350bIEYyT6DGyrm8h46jAGDs7PtFvhmcBAkTo09c+Do/OnwpMD91EKQtvDPXGYUykUQuJ/Inf X-Received: by 2002:a17:906:395:b0:94e:df0:51c3 with SMTP id b21-20020a170906039500b0094e0df051c3mr1622934eja.69.1681298909703; Wed, 12 Apr 2023 04:28:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681298909; cv=none; d=google.com; s=arc-20160816; b=dBA9cTiueZhFN3mad9KeOtnQ8n7bTPmKcAqX2tG+MCJxQ48CqEaPPu8JhM8M0qoyfe h89i4Tswcc7RRsUa2RaXgWs697P2CxXEAf2aEhcV6u0nGYdSIgsOvDfsGR7Y/e2cqEZ9 xnG7l7ZcasjS176bpiZp7wYVbWAlkddZ0NLLYEJPCt2/ddbOQ1lH3knxR2l9jgKJH2+D D0gP211ivQKpf3WvEjUd98PcwMZSVxFiHBlTAtaCQvTa6xyeFbzeoe9Ap0w3BGYCZZVm EKu+CNctSZ/7+IbeN4Nq7yUIZUoN3lF05xyONaGQwNx8vPmyTO66BdGeI/6T82yL8Mj0 kQ0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :organization:from:references:cc:to:content-language:user-agent :mime-version:date:message-id:dkim-signature; bh=nCSXTF4XVSA+wnYR5OnBmbwxnANHNL0gZw+wB32qq0c=; b=L6Y5eYCGt3qi9+VdD1Prt8l2SrEqY5ctUuMA7mqHJPifLO/nO98+y6FhwZvDr4ahIG EjQh6xxVrnuGimnm9uWHGAukQOrVcDxxZ+tY6CDn+2fTLYE0BIZNSur2Y0Kzk/vDXuEr 0a+j7XbGPt4/Gq+bT+hzAECypY58R1HXU+yfmQsigAM+BTycSuL7kdwt5ZgNV3XrHKci 6ba2GNpvO2cVtqg3TPtJbB0JzlIUQI+/conP19jHmrk4D0fWRDMti7FqXiPi7H0JX5cq GWOEA/tN0zWMFxTXffH2bWzZcKKHR7rzGcraR4zoPiiA9+3kip9FMboz3A326Cl2WEN9 t+dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=S7fbPiHQ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id tc17-20020a1709078d1100b009311b97abe3si2276654ejc.112.2023.04.12.04.28.04; Wed, 12 Apr 2023 04:28:29 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=S7fbPiHQ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230215AbjDLL1N (ORCPT + 99 others); Wed, 12 Apr 2023 07:27:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230063AbjDLL1M (ORCPT ); Wed, 12 Apr 2023 07:27:12 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50D611FE0 for ; Wed, 12 Apr 2023 04:26:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681298736; h=from:from: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=nCSXTF4XVSA+wnYR5OnBmbwxnANHNL0gZw+wB32qq0c=; b=S7fbPiHQzOPDEHXWqwqnYS3LMq2tGx1Jq7wHfkHqTBytNA6nRU7oX/Kaus/xuxDsul9b6y Isxd3KO9x4z7Px/8m2TjQY6Q3d78ef9Qg3FbJ4tyxA+q1SYpAMpG/ut5/aU2WWz4IQGKGK dbplVZgvWWDZtZE0pMn5RLpY0b3DdvM= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-108-GZq_LYYEN2WuCDxkzim48w-1; Wed, 12 Apr 2023 07:25:35 -0400 X-MC-Unique: GZq_LYYEN2WuCDxkzim48w-1 Received: by mail-wr1-f71.google.com with SMTP id w3-20020adf8bc3000000b002efb4354084so1369888wra.10 for ; Wed, 12 Apr 2023 04:25:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681298734; x=1683890734; h=content-transfer-encoding:in-reply-to:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nCSXTF4XVSA+wnYR5OnBmbwxnANHNL0gZw+wB32qq0c=; b=FHKgAac9+LCGH5zkmgqNz1YE5gk23j3X+bjxxzd8K+HmwqZH6WFk26TT6e/UmGDJwR ttajDL1Zn9HeegC5Mrbi89Urq4Gzi8w8BW6O0Hp/ri7zTDqQd0Pa4g79lcW0YYHxgrbw kPe0SfcK6KX+NE4M+WUtZ//DYLJmdUDUQibJCa37t4pDBdcpaUhiFYCoUGzyQn0xn9wR 2K8vt5BwzjQbrGo8MOUmDle0p5oQK/0EndsI6kkOy/njxJAS9BLTn6EtzmFOFuoH3GTp P5qDxtDo62VblIkQf6k4grTZAUZehqg2PIQGi9FrFPqX+l1QOyniGcLGM1LNRYdgZ3Li 3NfA== X-Gm-Message-State: AAQBX9fyY0/Cn10/iV2c+w5IKQ1Uku/Hd+DIWpO1DG4PyuFOGhy4aQ3o q6E2tOKpFo2U4xcoyz/35tDaYpmB4ZON51U7/l6iez1nhhXgFvqvvmHJf+A23PG4SaqTuw77oVr JZAll3W6QSbdnaebUKLwYO3Z/pzvVKGHp X-Received: by 2002:a7b:c4c7:0:b0:3e2:589:2512 with SMTP id g7-20020a7bc4c7000000b003e205892512mr1658470wmk.21.1681298734150; Wed, 12 Apr 2023 04:25:34 -0700 (PDT) X-Received: by 2002:a7b:c4c7:0:b0:3e2:589:2512 with SMTP id g7-20020a7bc4c7000000b003e205892512mr1658451wmk.21.1681298733719; Wed, 12 Apr 2023 04:25:33 -0700 (PDT) Received: from ?IPV6:2003:cb:c702:4b00:c6fa:b613:dbdc:ab? (p200300cbc7024b00c6fab613dbdc00ab.dip0.t-ipconnect.de. [2003:cb:c702:4b00:c6fa:b613:dbdc:ab]) by smtp.gmail.com with ESMTPSA id n11-20020a5d420b000000b002ceacff44c7sm16944160wrq.83.2023.04.12.04.25.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Apr 2023 04:25:33 -0700 (PDT) Message-ID: <94bfa3cc-674e-25b0-e7e2-d74c970acef7@redhat.com> Date: Wed, 12 Apr 2023 13:25:32 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Content-Language: en-US To: Baolin Wang , akpm@linux-foundation.org Cc: mgorman@techsingularity.net, vbabka@suse.cz, mhocko@suse.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <62e231a8f2e50c04dcadc7a0cfaa6dea5ce1ec05.1681296022.git.baolin.wang@linux.alibaba.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH] mm/page_alloc: consider pfn holes after pfn_valid() in __pageblock_pfn_to_page() In-Reply-To: <62e231a8f2e50c04dcadc7a0cfaa6dea5ce1ec05.1681296022.git.baolin.wang@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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: X-Mailing-List: linux-kernel@vger.kernel.org On 12.04.23 12:45, Baolin Wang wrote: > Now the __pageblock_pfn_to_page() is used by set_zone_contiguous(), > which checks whether the given zone contains holes, and uses pfn_valid() > to check if the end pfn is valid. However pfn_valid() can not make sure > the end pfn is not a hole if the size of a pageblock is larger than the > size of a sub-mem_section, since the struct page getting by pfn_to_page() > may represent a hole or an unusable page frame, which may cause incorrect > zone contiguous is set. > > Though another user of pageblock_pfn_to_page() in compaction seems work > well now, it is better to avoid scanning or touching these offline pfns. > So like commit 2d070eab2e82 ("mm: consider zone which is not fully > populated to have holes"), we should also use pfn_to_online_page() for > the end pfn to make sure it is a valid pfn with usable page frame. > Meanwhile the pfn_valid() for end pfn can be dropped now. > > Moreover 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. pageblocks are supposed to fall into a single memory section, so in most cases, if the start is online, so is the end. The exception to this rule is when we have a mixture of ZONE_DEVICE and ZONE_* within the same section. Then, indeed the end might not be online. BUT, if the end is valid (-> ZONE_DEVICE), then the zone_id will differ. [let's ignore any races for now, up to this point they are mostly of theoretical nature] So I don't think this change actually fixes something. Getting rid of the pfn_valid(start_pfn) makes sense. Replacing the pfn_valid(end_pfn) by a pfn_to_online_page(end_pfn) could make that function less efficient. > > Signed-off-by: Baolin Wang > --- > mm/page_alloc.c | 7 +++---- > 1 file changed, 3 insertions(+), 4 deletions(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index d0eb280ec7e4..8076f519c572 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -1512,9 +1512,6 @@ 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)) > - return NULL; > - > start_page = pfn_to_online_page(start_pfn); > if (!start_page) > return NULL; > @@ -1522,7 +1519,9 @@ struct page *__pageblock_pfn_to_page(unsigned long start_pfn, > if (page_zone(start_page) != zone) > return NULL; > > - end_page = pfn_to_page(end_pfn); > + end_page = pfn_to_online_page(end_pfn); > + if (!end_page) > + return NULL; > > /* This gives a shorter code than deriving page_zone(end_page) */ > if (page_zone_id(start_page) != page_zone_id(end_page)) -- Thanks, David / dhildenb