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: 13221283 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 79E6DC77B7C for ; Sun, 23 Apr 2023 10:59:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68DF86B0074; Sun, 23 Apr 2023 06:59:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6650D6B0075; Sun, 23 Apr 2023 06:59:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 514F96B0078; Sun, 23 Apr 2023 06:59:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 25F2E6B0075 for ; Sun, 23 Apr 2023 06:59:49 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 049DE1A022D for ; Sun, 23 Apr 2023 10:59:49 +0000 (UTC) X-FDA: 80712360498.28.1825684 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) by imf24.hostedemail.com (Postfix) with ESMTP id 0F70F18000D for ; Sun, 23 Apr 2023 10:59:46 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf24.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.112 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682247587; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=64GR5p2l4Z02IYdj0MM9eN1KhH4FGFdVF8hApvUlZkI=; b=B7BmxFWoxHwTCNYpVzpwnqim8uSPCX8dKyj476E3jZDQiLJlxiWAmnHWGGW+/8wcpkJ46T sgqlYaz47xFHgRrFEq//HFCVBwIjEuolMzPzsPaMfDZYu9l40Xq8zVNs8FDvtYEjACIVsG l8+x58xJU2VYhe/61TACkD99+IHKHZM= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf24.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.112 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682247587; a=rsa-sha256; cv=none; b=M1cHfSLor6ui822K4vDAsn4wQsklSBItn7Y6Jffj1DGkWbfUURbtC2l+JMMKJRLd2h7yi2 0G8Fzter8VaW4PiaUaIxleIJUgb8OTp7+ttpBjbRzJX89mMiuikRpU16j1YDFPfVQtJBCk x3lkUKzpVltHV1Oso1Gx3U9uh2fwhLA= 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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 0F70F18000D X-Rspam-User: X-Stat-Signature: ifn3sods3trrnw7z1m5kiq31ys8ok7yo X-HE-Tag: 1682247586-879295 X-HE-Meta: U2FsdGVkX1+buwgIO4YHrQBTX9NATFdg8oNbnaeZiowjUT2vXBFb1J/dgWzSVCAb2Um5SAlRkrTSNikZUkiA51Z950pVS64lAVJGASEiWaM3wlEcwLZlomJhhiJIEQ9LpjNEtfHpqGgmneQXuQhHp35Azgg3M/sKBhN5iN8FcDzyanboAPKYaoXrcdDEmpfW/XNtOMH/9rec1zbd5uGgWmxBugOJH2V0PrinTyLtHodu7crJClbgGGukxlti8LeBploReB1eJDwUXDrQRk9ZxAJmBiRAM5M0LIY0hjvur967kla3Dlj4Eg7auP1D2yL9F+/2pqzPSXkXogpfPpDcVi7NMl+ILanV7X1ehNHS34xsrnNlUFoZYzKAZ+2fNBLmcnOQgqtvF9ZHnRiwRxwQNJRgeOWfh3hEPTRW9/JS/h10uqYV4gMvbWySj61BlEcONYe7O5jdiR1+h2Hr2MwGFDiwUKYm+N6U0pcVC8jLSI9Yy4my5fr4A19CTS+vyxGRaPG/l9Q5Le6rHxijC/CFOCrKGkMCwH7qfi3bOR24s7mLFgX6GMhTpuzQGeBcaJ8Oa36HhIzBsG1LxbUCr8PqRGe+GehpwHsoxdutlISIatQHI6ojNN45hF5fCjdpLvpFygvEQznl8p1QPTByHhOE6HQL2bkPBD/EY8ui/dZXhMddnPI8tZAH5pB/Enq9E0lBHu6V5M0XSpoKsJ8WJm2LVx7ueQ+vz2+SqRS0Z8OXooBF3Fiej3y5LjQGyEYTrBInFmFpnIsqYU1Ipg/eJe2rPKSldTO6UfycomEzFbMLTzXvbKuIVEPXxdqKz6o2yDWFghfl9DybITBaLiJw39mV7FE8IzCVeoEgFi/j1+u1wTnvoGCc+Qd7bnOrdcD/0JvCJyfmyJUf53kuhXkHB0uLe6QKe3yUnJGtG3kFn5zEqJjscR5R4gd7VgCNos7leoWBRLkpH6qyliKsfAvDzz2 lgZ+HVpr wJKAkTUKE+Ylf47cf1hS0mC0T/yxNXcshJCrLEHxS3zURhBDbx0RJHaDuT0uKEFxzvz9eXvBSGyGOZV6b50gvnAsQv6Fg+Im2s3MEDch0yIQLm44MSk6DiV1GEvniNLxMvXQAg3zblESMxMbb4qerO5aFjdd4T2qn/NUWFwJXxrUy/xhu8SME/3wApBtTSHhH6a7qT77RKjkmuLJYr3eW2OHibg== 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: 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: 13221282 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 C9853C77B76 for ; Sun, 23 Apr 2023 10:59:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 297F86B0072; Sun, 23 Apr 2023 06:59:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 21F3D6B0074; Sun, 23 Apr 2023 06:59:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 10F9C6B0075; Sun, 23 Apr 2023 06:59:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 02D086B0072 for ; Sun, 23 Apr 2023 06:59:49 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B6C7C1A0239 for ; Sun, 23 Apr 2023 10:59:48 +0000 (UTC) X-FDA: 80712360456.08.EC11420 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by imf17.hostedemail.com (Postfix) with ESMTP id 0F1F140004 for ; Sun, 23 Apr 2023 10:59:45 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.113 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682247587; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LIqsSOzpJnrF9Fm+xJnpVjcr3PBFv0oWSPLLsllAJ6Q=; b=iWDVTMxD+7n5JFgiz2uCzgXg+pHLmpqphfTvVIQ4looLLxFHR2ZxKG7wv2GZv0UVQ1qLzA JVoXrmo9K10lhjdTFNYaqBlBr0oYPgD2psgP8nQBAJTJP1q4uCu6TboEy+Co8LtmYaZ1TT d8Gn399dMaItssaq7TG+GC2zc0wYs5Y= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.113 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682247587; a=rsa-sha256; cv=none; b=A9ypcWqd4L2Ggd1wpt+4SATt0UgSkPvtlVajQDxEqO/Kk0Ne+WgkOUo/7RjHNKkOUM02Om C1/FmnAn07cuy+2LR8+7S+X7OeAYuk8ygibj7dXwOyHQF/COR1O+e8YSQ3ZKyHDux4fpWD aAeg6S53ES169z7t3My04R54emOSyBU= 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-Stat-Signature: c5cotcb9a9torcy6ew7sbdnz5ggrit4m X-Rspam-User: X-Rspamd-Queue-Id: 0F1F140004 X-Rspamd-Server: rspam06 X-HE-Tag: 1682247585-483341 X-HE-Meta: U2FsdGVkX1+gHkMoDHxq7vZXXoU5HZzFo1/NxaMz+6nT9V/Uhc01ybO+3Vt+Tqbtgy1yVN3OqSUn/mjjwR3OWn/JinqhrnIT9kGA/xEFajeW3co6iY/WNnHSgwWnBaRaW2Daf3g5Wqd+XNupzAjavBtZKNHjIxuZAs0uCSx4U1u4sVmMUv6hpzLElYs7cYVUp00U07HMeBZX0YCPlWDoYDcpCPF61R5+QUWT4cCzd9y3UDEFpYD4aOUp82KIjATWLsMwVEzfve34m6HjHFyllJ1TA/HJmIILs5+F7okyNb4eWo9fOZZjl8vUidUUZNB3k+skd7snuJMQsutxJG8PScWtHZYE53asZ036YuiHs6qfAvo+s+rdBB3E+b6PdbKI08qL2CdWr/zB8HulOyAeL677hmWJ2/Na0RAtLP2mB8aQOU2ZNNHnqJbbC9o4oduID64K0838lgzMtJyzUR5LNfNbfc85VKHp5756QjaSWfh9b/SV7Ud+k0EGcd1TBAvbYHDnAATbYu/Oq2K0xeVJyOoUdVVuOZoThHuYP9LfpZdTyrWcoQO5LaTuMCr5KT8/tHYhJYRK+6MvhNNnlqebIdNQMTM5app0bKLp5VoPUoOwFJVrm/duZSNlYxmMvFnrzBwUvT0cdWUJMpHnPkBIiUIDvQrR5ViV22uYJHwGmJFXSuh3uWQaz90NbuinvZGqj0u9av8f4g163SfEjKqRnyGVSmL5aD+jd0+hC2JJslI+pDPcz5ba7IeVvb2ia7trrhPGpS2J/cT/cuKn506F126ZNpapCTMlEvoVLFsuBPWfIMFEWJmWFqEMTg+LonxNocupL8Em83zO+K+jl0kESjbRN9c57V+WP3RLdcuuwiAy/0v3+KNbZuNoFfx4YBSEVkTQ3K/9fG/QnrSo5eyYZ2fxhgK34N4co5/1qmbfdha1IlAy6QruMWJ9F0/P4vRr38jo8e3fzsqlxZrUqOK Epfcp6/Z U0g8y+NJoiDYyVqZbYow27SgPLmKxzau8StMP+2NfdwQ5oqnAOXAhJ9i2gYU+4pwPww1Xn+sO0FGt6OBwhvtzXCmqpYldap0BCK6ilZRY+CBjofEcFZy4s84YvgSLLLp35OlhqykjWRcb5go009PPgYkwNnVr7bDi43qWArv3n3+JWLuaGbq7CoHZAkaldCI3bPrWiIV7vfMykKCvOkvG/XPZBqjPxS7AoBK9Winv1O4eleO+gHg7QaBoaR90XLd1oPTe 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: 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)