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 DDB60C77B6E for ; Wed, 12 Apr 2023 11:25:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C0AF6B0075; Wed, 12 Apr 2023 07:25:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 770586B0078; Wed, 12 Apr 2023 07:25:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 63A0B900002; Wed, 12 Apr 2023 07:25:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4FCC06B0075 for ; Wed, 12 Apr 2023 07:25:42 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id AE5208012E for ; Wed, 12 Apr 2023 11:25:41 +0000 (UTC) X-FDA: 80672508882.29.3818196 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 47FF3180003 for ; Wed, 12 Apr 2023 11:25:39 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CjYQp+vJ; spf=pass (imf24.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681298739; 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:dkim-signature; bh=nCSXTF4XVSA+wnYR5OnBmbwxnANHNL0gZw+wB32qq0c=; b=A0BtvG7/pGPYfjx/WunqyoQFN7K/1daJy6+Vq/lvWlCpUFqMAOntKQRFc3yIMBdVvY5ltr rygr3VvFXb/W97f4Y5BkA3kVZSfmNQ/EjYl4zPKjczBhUa/YwBJmhaO/kR6PyDe3FqkCFj +kzhM18/vFI+KvshDWCrIi9r+bUOmTs= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CjYQp+vJ; spf=pass (imf24.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681298739; a=rsa-sha256; cv=none; b=oqz6VK1UiMMKcz6QF492XvUWn+M9F55RhgauYJers08Iw/sQxlhGrJKksXI+J1ALxuKEg4 NDpKVzQ8fiHC3BkE1+AMOMWLNdLc9vAkR6NLzYOvyBmvJlkQ5NKw9b81DhP6uyZbmTFXmb qDJ9mSlKEV1WIgyRsx/Lqa6/HJ27qmw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681298738; 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=CjYQp+vJdbsbrKCzLnTvYvNeC8cXjilXRLqCmJFWQb1NppXzv00V2A5kJLh8ANQZUU3F+K RY7ZqkN9eASQw4ygouTH9NluTjb3fAD3dA2j2ZW4baFKdbe/hv2iSfefzkhe8S3iHK0Asb cqnCMkzm7wCuScDCmURJZcc5AtEcS7A= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-495-EG5fsWkJOGClaf7wlVps5A-1; Wed, 12 Apr 2023 07:25:35 -0400 X-MC-Unique: EG5fsWkJOGClaf7wlVps5A-1 Received: by mail-wm1-f69.google.com with SMTP id l20-20020a05600c4f1400b003f0a04fe9b9so272422wmq.7 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=fUflsEplmD1w/jB1EguKeiELJq8oG9Rm/cfdn99hsxQDMeplExDrFSBrhllS10952r 7bK1hhKbaUAv4J38xmaiXMiNYW/muk5wgK19ZP86pbgQ/q/xiUkyKCC3+z+a7n+d1pYh YXQDryxR86mRNwG7ZaGQ4KmSm/+FqANE2tznqevxZkjsFhNbZi9QCH9sRK1No9vOuJ7O EiZEfFAO7x0tC9ldaSK9Kw0sQ7pQczMLyga1wTn9UeKRJWCuTL0hdukrG0g0i0uFlDkF fi7l3Worve98wNB7w90e1Npbgz6aEAOJKB9QD7Wvma5nYlSoRmKFUtisGIUKgnuIQnTB GDtw== X-Gm-Message-State: AAQBX9cFEiKRItwJDNVpsDVByaa8GppHoBtOgogNrtq1ML2Pp1JZc6A9 4rw3mYej8pkZsCe71y61JrwBOfy4jqTKTZMwBJcfdImIzGina8DYlhU3qioyH+md+h1rj57xmMc Zd+WJ9uHh6CI= X-Received: by 2002:a7b:c4c7:0:b0:3e2:589:2512 with SMTP id g7-20020a7bc4c7000000b003e205892512mr1658472wmk.21.1681298734150; Wed, 12 Apr 2023 04:25:34 -0700 (PDT) X-Google-Smtp-Source: AKy350b/SiLavUkrvwZgIj2TJWW+TQt7NrOH6hxC/XCMk5hAWGy3BRFgYcoxYNV6pNUr8efUGpf8Kw== 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 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> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 47FF3180003 X-Stat-Signature: s1aotempod1cenuzkunwr9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iQ91EAGTotZ9ru98ZICUeFzEQ/cgnDU6mCCYxdDh/Ynig9x25m4S45G3Rhevxu9+gLrmWLUUZ3Y4HPQczwouKxQJ+Lh8R3b4fAqdpqtARwpXK9f0E1g0WEsaVc9ARYcu0Nf9bcHJgdQncs2u5tZoaOufWJrsuEpgfSo87vOMViQiaqoqfW/B1ps4gSAflXHuAsUDGX+Py2kRvgyBXK84DouhpymBtza2fcf5RcDm0c1H6PxN8qEBw/AxKMp4I7qKeIkNEOdpJsGxHfrNKQywIp3wcuPx9skMP8f+F8Ub+UW/t2x0N8gOqclBH2URu4PcM8F4Xs+wNK5RG5b8IzrHQXKgye410spoK0g314TSoo+yqVsX36zCnrpEkCOuLEI+Nmm7u6O41jyKR8tTvoMGcIzIMR4CSOyIqKMbsGIGbmoD2LRL2O7bCFIpy6tPuVsYA== 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 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