From patchwork Tue Jul 14 20:54:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Jordan X-Patchwork-Id: 11663545 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B969260D for ; Tue, 14 Jul 2020 20:55:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 86195206F4 for ; Tue, 14 Jul 2020 20:55:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="NW03zk8D" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 86195206F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 875D66B0002; Tue, 14 Jul 2020 16:55:12 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 826716B0003; Tue, 14 Jul 2020 16:55:12 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 715C56B0005; Tue, 14 Jul 2020 16:55:12 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0071.hostedemail.com [216.40.44.71]) by kanga.kvack.org (Postfix) with ESMTP id 5C9776B0002 for ; Tue, 14 Jul 2020 16:55:12 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id D2B822DFC for ; Tue, 14 Jul 2020 20:55:11 +0000 (UTC) X-FDA: 77037886422.15.alarm37_510b2bd26ef4 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id B9B731814B0C8 for ; Tue, 14 Jul 2020 20:55:09 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,daniel.m.jordan@oracle.com,,RULES_HIT:30001:30034:30054:30064:30070,0,RBL:156.151.31.85:@oracle.com:.lbl8.mailshell.net-62.18.0.100 64.10.201.10;04y8h5bc1z86b6durbrkmur5zqyhiyp764f8reiea7qcwmyrzy53i8jduhnysn6.uu3trseejerne8dj4z18g9dipc36uu4r5gnqfi1hs9patcdauggix5gfr1aokmw.e-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: alarm37_510b2bd26ef4 X-Filterd-Recvd-Size: 6259 Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Tue, 14 Jul 2020 20:55:09 +0000 (UTC) Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06EKqujA008190; Tue, 14 Jul 2020 20:54:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=9gAydN9tkf7vqIv4AFRYx4WuisnKrEAgHU9j5Ph1rdU=; b=NW03zk8Dwv+MsKoWXK123RITG7VK0dHlNAjHPxyU/x1WQFR8xZ7jozc3/rC5RYBG414u 6o9WCHjV2K+Ln9hLFSoxiR4xH5ewupyQ2Yaln4vxgPiFBWvxLVfhbRb83QlMjrOnTaUU xBM3GYEfUqjKOnQV1Pf2YQSkHK18sGZx6/UFlwYZCeY2B3SDW7EJq9i22IrultOM55EW uhMO9a7HnXQ1rwFcshjia+7acrTbDEEoQ+t1WiQxzIkhR8DVl+8U0sM6A0yOXzxgmLxj iIVoYQHmgN8ROjp2LQhk3bkmSeE5BQHURuhwk25hFGdKYY5PJaY+bMe+Sw0kv8nF8foq uQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 32762nfnt8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 14 Jul 2020 20:54:58 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06EKrcTG184155; Tue, 14 Jul 2020 20:54:57 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 327q6t1en1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 14 Jul 2020 20:54:57 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 06EKstaL032357; Tue, 14 Jul 2020 20:54:55 GMT Received: from localhost.localdomain (/98.229.125.203) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 14 Jul 2020 13:54:55 -0700 From: Daniel Jordan To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , Andy Lutomirski , Dave Hansen , David Hildenbrand , Michal Hocko , Pavel Tatashin , Peter Zijlstra , Steven Sistare , Daniel Jordan Subject: [PATCH v3] x86/mm: use max memory block size on bare metal Date: Tue, 14 Jul 2020 16:54:50 -0400 Message-Id: <20200714205450.945834-1-daniel.m.jordan@oracle.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9682 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007140145 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9682 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 spamscore=0 clxscore=1015 priorityscore=1501 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 suspectscore=0 phishscore=0 adultscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007140145 X-Rspamd-Queue-Id: B9B731814B0C8 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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: Some of our servers spend significant time at kernel boot initializing memory block sysfs directories and then creating symlinks between them and the corresponding nodes. The slowness happens because the machines get stuck with the smallest supported memory block size on x86 (128M), which results in 16,288 directories to cover the 2T of installed RAM. The search for each memory block is noticeable even with commit 4fb6eabf1037 ("drivers/base/memory.c: cache memory blocks in xarray to accelerate lookup"). Commit 078eb6aa50dc ("x86/mm/memory_hotplug: determine block size based on the end of boot memory") chooses the block size based on alignment with memory end. That addresses hotplug failures in qemu guests, but for bare metal systems whose memory end isn't aligned to even the smallest size, it leaves them at 128M. Make kernels that aren't running on a hypervisor use the largest supported size (2G) to minimize overhead on big machines. Kernel boot goes 7% faster on the aforementioned servers, shaving off half a second. Signed-off-by: Daniel Jordan Cc: Andrew Morton Cc: Andy Lutomirski Cc: Dave Hansen Cc: David Hildenbrand Cc: Michal Hocko Cc: Pavel Tatashin Cc: Peter Zijlstra Cc: Steven Sistare Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org --- v3: - Add more accurate hypervisor check. Someone kindly pointed me to 517c3ba00916 ("x86/speculation/mds: Apply more accurate check on hypervisor platform"), and v2 had the same issue. - Rebase on v5.8-rc5 v2: - Thanks to David for the idea to make this conditional based on virtualization. - Update performance numbers to account for 4fb6eabf1037 (David) arch/x86/mm/init_64.c | 9 +++++++++ 1 file changed, 9 insertions(+) base-commit: 11ba468877bb23f28956a35e896356252d63c983 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index dbae185511cdf..51ea8b8e2959d 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1406,6 +1406,15 @@ static unsigned long probe_memory_block_size(void) goto done; } + /* + * Use max block size to minimize overhead on bare metal, where + * alignment for memory hotplug isn't a concern. + */ + if (!boot_cpu_has(X86_FEATURE_HYPERVISOR)) { + bz = MAX_BLOCK_SIZE; + goto done; + } + /* Find the largest allowed block size that aligns to memory end */ for (bz = MAX_BLOCK_SIZE; bz > MIN_MEMORY_BLOCK_SIZE; bz >>= 1) { if (IS_ALIGNED(boot_mem_end, bz))