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 F3F6FC77B6E for ; Fri, 14 Apr 2023 13:29:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 444A2900003; Fri, 14 Apr 2023 09:29:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F4D3900002; Fri, 14 Apr 2023 09:29:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E5D2900003; Fri, 14 Apr 2023 09:29:47 -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 1F67A900002 for ; Fri, 14 Apr 2023 09:29:47 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BDF3AAB42F for ; Fri, 14 Apr 2023 13:29:46 +0000 (UTC) X-FDA: 80680079172.14.B743B6B Received: from outbound-smtp15.blacknight.com (outbound-smtp15.blacknight.com [46.22.139.232]) by imf11.hostedemail.com (Postfix) with ESMTP id BE73540028 for ; Fri, 14 Apr 2023 13:29:44 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of mgorman@techsingularity.net designates 46.22.139.232 as permitted sender) smtp.mailfrom=mgorman@techsingularity.net; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681478985; 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: in-reply-to:in-reply-to:references:references; bh=EgKSHp1GDdcxsHFSeY4I4nyap4KqJegeD1mmI+AMYvM=; b=eimJDOaFnjWrtFcQA18UeGz3lzyzkTcNqQdRpjCxh2CBcX7dOSB4NgWG0RqgcVh+cHQvib D58v3aP/1mXpXET5Ft0LS13kiTrsFCyosWA/4bwtnNo8dG1vhQwqc9M7+3p6xhPwpL3Td9 +TQ8IRZZcH/JQ9jZwdbR/63AufNUxbc= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of mgorman@techsingularity.net designates 46.22.139.232 as permitted sender) smtp.mailfrom=mgorman@techsingularity.net; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681478985; a=rsa-sha256; cv=none; b=03MeASQnZxDC0Ce+oQXrqxm888/lxWYG3JfBJsGYZ8JZXxm2+QE8DHYGfUqPWhfyjFQMb2 ik8TpXz9R2799eplm5iR88qZ/I5nDzrzgBeNwGZVCVHuW4sz4Tz4eH4q00tON9TDJlnAuJ e3a2qAQWkCgh7Sy0mNiUwkQsmduH86c= Received: from mail.blacknight.com (pemlinmail05.blacknight.ie [81.17.254.26]) by outbound-smtp15.blacknight.com (Postfix) with ESMTPS id B4FA21C403F for ; Fri, 14 Apr 2023 14:29:42 +0100 (IST) Received: (qmail 17515 invoked from network); 14 Apr 2023 13:29:42 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.21.103]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 14 Apr 2023 13:29:42 -0000 Date: Fri, 14 Apr 2023 14:29:40 +0100 From: Mel Gorman To: Matthew Wilcox Cc: Andrew Morton , Vlastimil Babka , Michal Hocko , Oscar Salvador , Yuanxi Liu , David Hildenbrand , Linux-MM , LKML Subject: Re: [PATCH] mm: page_alloc: Assume huge tail pages are valid when allocating contiguous pages Message-ID: <20230414132940.chjmsuiurnygajxs@techsingularity.net> References: <20230414082222.idgw745cgcduzy37@techsingularity.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: k9fg6kx4cp39q664pmesj9mjj7pb41s6 X-Rspamd-Queue-Id: BE73540028 X-HE-Tag: 1681478984-178980 X-HE-Meta: U2FsdGVkX19NhdvAr67gcCdpJH5W2df1A497GAqBuVkj36YTYFzoMoaUk1tOr8CsyA398VLyYvGENrgjJ6PiaA2FOdor3G/KTb3fwk0vPvtIWBflBYeTxU4dIJoRBi+2N+wY8zKXCQyv6loUd5zUeYUpHlneT9m/aTSvWRrf9A0hG5XY2ny5p5xhM/3LZJAI1SDV+X5fB5nSW0fup95MQ++c+iAaj0KI6pJYO6SdXCD/n2ctA+XGiI4wEETHXlEqv5P8s1g9LL+ICsJnC7zX2fR72PkNc+m4wf5tZlTsdee0EG8rbHKA+uahEx0Wq0ndJafUcaryLSvZEDoEZY/4OqTxGrSNm6VGfA+BJYbcwpei6QiuMzoccRBrfp8TV9Uz5+vCfUkR9lNVMW1+s1vi27NhflTFCZLHpoL9XGfD42Cq5SNjtJHeknysazBOET18MERL1xdb541EyW6+NPl8Dx9ZjDJ9DkMlRRCDAIy3qLIEYFAdHD7aKC4H8GASy0ead2FlkCJAyzxnZEjWn0HBRio7zk9rgRYrPoy/DZlobUXXJ9XXqla4peKtWvEag2VyJjMEyiipT/it381p2KyWWwDEEVTi/xVWoOrOg2BZagIwycuCI0sMUi+KR259TL7LnbTrwoVMiK54ftMxVlmAFwdobm6j/ugBXKP54OAQHJv/idbEQJsO+6J/ivFeQ8YPOd22EcX0NgDUm/0GVxAgF93JmDJPj9r59taF5LEvJ6UgTM14QyuSbyHaFrAvNUAZLFnZbKvijl4uY6NL055pmEzTg2bHTK4evi/3skcGOaGn2mg8eyL7mhJs+oWfWtLI1Zp7UWp4HiBieEaZQnpdys5eK55RpExeJDGkrzK2pYqH/xMcrU3LBCltcUKpm4tL7VwGGoNwUcndE3WICDfNW2CdTJAm65OadP87kOTThWxCJ+aKq3T7Z78r/KDjjfErMeteCsDJGaFmwbRldXT Uqxb8SUH FL7grP4SDSWHyOQHcU3ac9OMLu1UEuDB75yBoDcvDDlJzL9+7hFD2+7Z8BVNv2ZNM3UNyawNP4ACRhOWqTelrZXRsD3Inj9/Zd4iFrXtBrkvzh5OVqdd3pNLWuChu8abMnDH3hwwetNTVzS1/SC2VtDFEXY/vRksTyHCVLoXMm7GInq7tLM/RAW/HeL87vDtGUYnpaZDpnVL1A2y2kKCfIdscwlDEBvV35ABockePqjWglwI= 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 Fri, Apr 14, 2023 at 01:22:06PM +0100, Matthew Wilcox wrote: > On Fri, Apr 14, 2023 at 09:22:22AM +0100, Mel Gorman wrote: > > + /* > > + * Do not migrate huge pages that span the size of the region > > + * being allocated contiguous. e.g. Do not migrate a 1G page > > + * for a 1G allocation request. CMA is an exception as the > > + * region may be reserved for hardware that requires physical > > + * memory without a MMU or scatter/gather capability. > > + * > > + * Note that the compound check is race-prone versus > > + * free/split/collapse but it should be safe and result in > > + * a premature skip or a useless migration attempt. > > + */ > > + if (PageHuge(page) && compound_nr(page) >= nr_pages && > > This confuses me. PageHuge() can be called on tail pages, but if > compound_nr() is called on a tail page, it returns 1. Given the calling context is a linear scan, the head page will be scanned first so the value for compound_nr() called on a tail page shouldn't occur. > So I'm not > sure why this works. Also, do you really want PageHuge (ie only > hugetlbfs pages), or do you really just want to check PageCompound(), > which would also be true for THP? > For now I only want hugetlbfs pages as the fix is for a regression when allocating 1G hugetlbfs pages and previous behaviour avoided existing hugetlbfs pages. THP pages can be split+migrated of course but the cost of the 1G allocation attempt may be excessive relative to any benefit. -- Mel Gorman SUSE Labs