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 CE539C77B6E for ; Fri, 14 Apr 2023 14:38:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 587AC280001; Fri, 14 Apr 2023 10:38:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 510BA6B007D; Fri, 14 Apr 2023 10:38:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 36445280001; Fri, 14 Apr 2023 10:38:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 1AE366B0078 for ; Fri, 14 Apr 2023 10:38:44 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E19F61201D3 for ; Fri, 14 Apr 2023 14:38:43 +0000 (UTC) X-FDA: 80680252926.12.34B1875 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf01.hostedemail.com (Postfix) with ESMTP id A607640024 for ; Fri, 14 Apr 2023 14:38:40 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="CD/AS2yP"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="uqW/sUzj"; spf=pass (imf01.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681483121; 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=fKkcRNPVtLEhv1N06+iXT1LK1bajNyNsHds/Gh6DN38=; b=P9aASz2BSyeQfg6A8xQMk4bKFeL15IWYXdssk6uZ0/D+e9e8VlmZos1ZuLplZI5L/JD4m5 oS66i21/XJLPZEXWN4O51MnunmXWrwXy3P6JUXU3bQ/aCrH8LNkXdcqK4QZTb/oEafuaGd k2ABlNFUlPVjsNNzLTbKr+aEoHeIbvc= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="CD/AS2yP"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="uqW/sUzj"; spf=pass (imf01.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681483121; a=rsa-sha256; cv=none; b=s0iJ8QLaHzJGNFqzv2MyRgOQBgGSiDM7HYXxftBHmjZzGNm6HgbErVGN6cy5sGz1xDsoO3 /GXGYY32CV4qcv9QAYgd73OWc7H9hs315GOnbxfKKUqVSUasXmDuzuT94fQaPfD9FveE5T 3/mBdSBBW7BIPO32fCWwM6G1CrIg8Ts= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E8A2C219E5; Fri, 14 Apr 2023 14:38:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1681483118; h=from:from:reply-to: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=fKkcRNPVtLEhv1N06+iXT1LK1bajNyNsHds/Gh6DN38=; b=CD/AS2yPJh3gAuVMWrOPga9JpzsCFANVwlPWxflhq0w2c61fyOiIU4uK8PI4Xcbbh05UAQ 3O4hvOwxtlK21bJ1eJtjDUhx0HkOzHbbyOU2jFI4a8zl2aSE96Cuc4O3U7IdT/FOcDLJbB BmS5clZB9aPSofxoNOY1Poni85ELTUg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1681483118; h=from:from:reply-to: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=fKkcRNPVtLEhv1N06+iXT1LK1bajNyNsHds/Gh6DN38=; b=uqW/sUzjDdM4r1S2Mc88t/ovdq6QEKlBmSWk1KSsb+D3eKGQu42LScS/Vi2bVvbzztOaUt 9wBnJLAtQ9A/NoDQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id BC2E713498; Fri, 14 Apr 2023 14:38:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 3EARLW5lOWRTLAAAMHmgww (envelope-from ); Fri, 14 Apr 2023 14:38:38 +0000 Message-ID: Date: Fri, 14 Apr 2023 16:38:38 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH] mm: page_alloc: Skip regions with hugetlbfs pages when allocating 1G pages Content-Language: en-US To: Mel Gorman , Andrew Morton Cc: Michal Hocko , Oscar Salvador , Yuanxi Liu , David Hildenbrand , Matthew Wilcox , Linux-MM , LKML References: <20230414141429.pwgieuwluxwez3rj@techsingularity.net> From: Vlastimil Babka In-Reply-To: <20230414141429.pwgieuwluxwez3rj@techsingularity.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: A607640024 X-Stat-Signature: tpm6wkxcutyqimehdz6k9xhwg9hrfm3c X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1681483120-650066 X-HE-Meta: U2FsdGVkX1+7WQq7axzocY/iaVrHsKDci1L/Zu30P+xZxsheS17H1HP15ZezOWf2CkbQHeXzYHVkbd39atbmLuBRf4nsdCNf1ymboC4xuUg2GG/tireKQNb9tc2KDPJqy5ls5/UckYJiT1DIksnSgZAR3DfElmT2s8inXq99/OVH5UDk0cJb90o5U/MuJsxEjQacXlH6Yo8HvuEfWbYvXNMCCiNeuo+FcAys8QpC67D0YJoO426zjiboqVCBgSEcfIc1BkNEgTRboPfNhBh34yqwHLMIy9lIxOSqv5SpuSgr43LCQCDbwxbLM/Xg22Ou4bdkQZU0+fMpYbPubSO+nYEEq/OgXY1z4KLFpoitrjEfXDBG44G8Zt31NDf0JZphcs8+ebtVOsC/QeEV7Z2QqruQ6EiLP9++jqi5+Q54gIn9Jtxu4ry7VYwOEYmNpe50z4KCLz+l3vh/gTQ0USi5RV3lqwaVcbnvnfgEHzoQhUn76IHGiFRs5dQ/cyq+ltqYFP797Nh2q96ptKiZo71A2w5Zy/rtRtkXw1hoOxRSBKQ0aTTvywtHlWl0gvqnWg8UtuzisKUCtEE0q49zPLuL4QV6mUNGbgU6GdA1s9jZZlAe9lpevmPITPgzOXnf6Q6Si6cqJZf/PPjK32wuYAXr9nRorSzqTM9oHxdBzt/TUt4otYXDb9tcP+ztKG8YI5WfA01wyivCgQdwyvPKuTQ1C/L37og/tbG72QnI4PmUdX3bRFy8GiulQ3WY8WKW+V1unGaHAW0IkJgx8dO9qZL1G7jyB+cPxiJoo86FeueuQ6VvWW4yUlGUByOtI8JxUXJzH/xstrbOWZHarKE9TCG1HPbg+bohaVagK6whS3SXeHta4CSv5TDt/gj/3fA3dw7602KcOIybrc785SAWvtWKJ3UA+ReveJNjRTmcqsLrDYfsHEuMX7Vns2nh8Njwsk3cCQXYdKM9vwjMcG7BJHW XU+bzrtn 3UY2PsHecqpn65AqSvlMKZZNF5ojIpYc6c36yr3+66q6NRLUwYzbawTQJX5lJTV5C56E0pKL6fm1BzDFQSVr3kpwJL2F414YJT9t+Wx1cAzdvnl0uoRneljVa+1AiYNh3boN+4XZ4AuOVkuBE9K0FGKYYM0HjI16q9UAO320R8wX8SAP/jxB6YY++tlh3D3vHCR1bAedLIYb2GkFG+GvHzPW9u8B+b0Y5BUfJO7UMNZHB150YnUy0j/Ag6GmnFi6Hli1Go5RPlwxvSwHIieJ34PBCNyNyYa4vEgXqki4K0G1eN1TlvqdF+f2V4+dffHWX/US4TKLbiGMIidytG8VvMCmuxGetY0MpVko6MSpAgTRHZ0cmZJkB/Ed1KESpfKu5bJA9kdO+KtPDcUeolebevTU5Vhtt7uNg3cmuXutRq8m+1Yjy9ntv4R9qmQ== 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 4/14/23 16:14, Mel Gorman wrote: > A bug was reported by Yuanxi Liu where allocating 1G pages at runtime is > taking an excessive amount of time for large amounts of memory. Further > testing allocating huge pages that the cost is linear i.e. if allocating > 1G pages in batches of 10 then the time to allocate nr_hugepages from > 10->20->30->etc increases linearly even though 10 pages are allocated at > each step. Profiles indicated that much of the time is spent checking the > validity within already existing huge pages and then attempting a migration > that fails after isolating the range, draining pages and a whole lot of > other useless work. > > Commit eb14d4eefdc4 ("mm,page_alloc: drop unnecessary checks from > pfn_range_valid_contig") removed two checks, one which ignored huge pages > for contiguous allocations as huge pages can sometimes migrate. While > there may be value on migrating a 2M page to satisfy a 1G allocation, it's > potentially expensive if the 1G allocation fails and it's pointless to > try moving a 1G page for a new 1G allocation or scan the tail pages for > valid PFNs. > > Reintroduce the PageHuge check and assume any contiguous region with > hugetlbfs pages is unsuitable for a new 1G allocation. > > The hpagealloc test allocates huge pages in batches and reports the > average latency per page over time. This test happens just after boot when > fragmentation is not an issue. Units are in milliseconds. > > hpagealloc > 6.3.0-rc6 6.3.0-rc6 6.3.0-rc6 > vanilla hugeallocrevert-v1r1 hugeallocsimple-v1r2 > Min Latency 26.42 ( 0.00%) 5.07 ( 80.82%) 18.94 ( 28.30%) > 1st-qrtle Latency 356.61 ( 0.00%) 5.34 ( 98.50%) 19.85 ( 94.43%) > 2nd-qrtle Latency 697.26 ( 0.00%) 5.47 ( 99.22%) 20.44 ( 97.07%) > 3rd-qrtle Latency 972.94 ( 0.00%) 5.50 ( 99.43%) 20.81 ( 97.86%) > Max-1 Latency 26.42 ( 0.00%) 5.07 ( 80.82%) 18.94 ( 28.30%) > Max-5 Latency 82.14 ( 0.00%) 5.11 ( 93.78%) 19.31 ( 76.49%) > Max-10 Latency 150.54 ( 0.00%) 5.20 ( 96.55%) 19.43 ( 87.09%) > Max-90 Latency 1164.45 ( 0.00%) 5.53 ( 99.52%) 20.97 ( 98.20%) > Max-95 Latency 1223.06 ( 0.00%) 5.55 ( 99.55%) 21.06 ( 98.28%) > Max-99 Latency 1278.67 ( 0.00%) 5.57 ( 99.56%) 22.56 ( 98.24%) > Max Latency 1310.90 ( 0.00%) 8.06 ( 99.39%) 26.62 ( 97.97%) > Amean Latency 678.36 ( 0.00%) 5.44 * 99.20%* 20.44 * 96.99%* > > 6.3.0-rc6 6.3.0-rc6 6.3.0-rc6 > vanilla revert-v1 hugeallocfix-v2 > Duration User 0.28 0.27 0.30 > Duration System 808.66 17.77 35.99 > Duration Elapsed 830.87 18.08 36.33 > > The vanilla kernel is poor, taking up to 1.3 second to allocate a huge page > and almost 10 minutes in total to run the test. Reverting the problematic > commit reduces it to 8ms at worst and the patch takes 26ms. This patch > fixes the main issue with skipping huge pages but leaves the page_count() > out because a page with an elevated count potentially can migrate. > > BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=217022 > Fixes: eb14d4eefdc4 ("mm,page_alloc: drop unnecessary checks from pfn_range_valid_contig") > Reported-by: Yuanxi Liu > Signed-off-by: Mel Gorman Acked-by: Vlastimil Babka > --- > mm/page_alloc.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 7136c36c5d01..b47f520c3051 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -9450,6 +9450,9 @@ static bool pfn_range_valid_contig(struct zone *z, unsigned long start_pfn, > > if (PageReserved(page)) > return false; > + > + if (PageHuge(page)) > + return false; > } > return true; > }