Received: by 10.213.65.68 with SMTP id h4csp3830378imn; Tue, 3 Apr 2018 11:20:06 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+Kzux7PtGlSjYBjUeie3b9hryRu9MdVVK+/gaYyNeZf4D6CaPklTlxK51Pw8cO6SfWGaN6 X-Received: by 10.98.226.23 with SMTP id a23mr11339853pfi.157.1522779606534; Tue, 03 Apr 2018 11:20:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522779606; cv=none; d=google.com; s=arc-20160816; b=qo42uSiPzqW/F3lNQN9gb2Cn2LtMR7B52skyLf8ztKOmazJkobSL+N7XClHnKnFJXC EryTHXu8Mka9spCR+7iIohy2mxriyC0pG6O6v1SYZVKUv/c9HZKGUjI3m+h1YidOcoAU hA56EjNMZ0WLrxHBM0TCEg4D+rxM6OCJLrA5035p3+1fxmkRmLanU5uswvjCYAr2/eS7 y6GvONIzLvv7tzDqy50/gP/CVMhRoqkUsnUJFgKeNyQ6LvBAW5jmMPuluRmecHG0N8vR cI5HSOD9EvR8X8gYcIDDVfcjC2S8t8nM9jPzHnF6w9c6pi6mTidPO8d62LrAvlK7DROR ES6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:arc-authentication-results; bh=y4OKo41vLpMXGdKQj+jpCawiErpHz39ACwhTxpnBZ+U=; b=g9iBBkIeaqCoPQtT3p3LE7pb4P0gRah89msgcLfStqKm5U8g5plWRkgzneW+Kzb47F Ke+HBd8bKe3iqYcyUzeDQtud97ooGLxFWNwaYaDzmacL5elaNSn95k6jC6fppzAQoicm wIqxCYGfO/DDq7WdU0rjNxP/NHJkgEd1AZK3uyVlLVa2OfgjqHK6KKlxmwVy3AvMRVhC 3BnTroFFsF+0eIq99r9R/6QjfX+csnTySvR4fmYfICiUd5ZaesmsRUVIls5fqtNgboak C6yktyPPPwq2d+ACpgedKdidNPLjwJjl8Og6T2v1XcUD6L8fxut/vJb2JW1AjcHNNcXv gwfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=q5JJYyL1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b124si2280476pgc.614.2018.04.03.11.19.52; Tue, 03 Apr 2018 11:20:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=q5JJYyL1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753225AbeDCSRy (ORCPT + 99 others); Tue, 3 Apr 2018 14:17:54 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:47867 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753133AbeDCSRX (ORCPT ); Tue, 3 Apr 2018 14:17:23 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w33IGrcg171271; Tue, 3 Apr 2018 18:16:53 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2017-10-26; bh=y4OKo41vLpMXGdKQj+jpCawiErpHz39ACwhTxpnBZ+U=; b=q5JJYyL1Bn3ahuRXZUrJ/nmvybBUK2nMIdS/Ik/VAfQy/LzYfrjP+PMfjH9mcmiKGXt+ RDqCQXWB98Z+0mYR3pwH92Cvry7yHxGhU2dj1XT4pDfOlXF3F+xjrvgxIk2dfmZkQ30f zt9AMp+YovAClLQUm1Uh51mNOKSMiKvqiF5j+F9HkwlCMosGUEc72qDnK4+TZHklq0kB eKz2rzyG0TAUHl3wDcP9K6RISb+9aVS9tQOoknSnHzDEun+tr3wvwc5wMjoXXth8KYhd HDqnlpnCf9yQlTK1KLNkg9EFBEteryzcuNjrydbMYnfzdjhJKm1tHgPiJ8sSXWoN6WnY vQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2h4erm000e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Apr 2018 18:16:53 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w33IGqkp015439 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 3 Apr 2018 18:16:53 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w33IGqmv028832; Tue, 3 Apr 2018 18:16:52 GMT Received: from localhost.localdomain (/98.216.35.41) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 03 Apr 2018 11:16:52 -0700 From: Pavel Tatashin To: steven.sistare@oracle.com, daniel.m.jordan@oracle.com, akpm@linux-foundation.org, mgorman@techsingularity.net, mhocko@suse.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, vbabka@suse.cz, bharata@linux.vnet.ibm.com, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, dan.j.williams@intel.com, kirill.shutemov@linux.intel.com, bhe@redhat.com, alexander.levin@microsoft.com Subject: [v6 2/6] x86/mm/memory_hotplug: determine block size based on the end of boot memory Date: Tue, 3 Apr 2018 14:16:39 -0400 Message-Id: <20180403181643.28127-3-pasha.tatashin@oracle.com> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180403181643.28127-1-pasha.tatashin@oracle.com> References: <20180403181643.28127-1-pasha.tatashin@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8852 signatures=668697 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1804030185 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Memory sections are combined into "memory block" chunks. These chunks are the units upon which memory can be added and removed. On x86 the new memory may be added after the end of the boot memory, therefore, if block size does not align with end of boot memory, memory hotplugging/hotremoving can be broken. Currently, whenever machine is booted with more than 64G the block size is unconditionally increased to 2G from the base 128M. This is done in order to reduce number of memory device files in sysfs: /sys/devices/system/memory/memoryXXX We must use the largest allowed block size that aligns to the next address to be able to hotplug the next block of memory. So, when memory is larger or equal to 64G, we check the end address and find the largest block size that is still power of two but smaller or equal to 2G. Before, the fix: Run qemu with: -m 64G,slots=2,maxmem=66G -object memory-backend-ram,id=mem1,size=2G (qemu) device_add pc-dimm,id=dimm1,memdev=mem1 Block size [0x80000000] unaligned hotplug range: start 0x1040000000, size 0x80000000 acpi PNP0C80:00: add_memory failed acpi PNP0C80:00: acpi_memory_enable_device() error acpi PNP0C80:00: Enumeration failure With the fix memory is added successfully as the block size is set to 1G, and therefore aligns with start address 0x1040000000. Signed-off-by: Pavel Tatashin Reviewed-by: Ingo Molnar --- arch/x86/mm/init_64.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index 45241de66785..dca9abf2b85c 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1328,14 +1328,39 @@ int kern_addr_valid(unsigned long addr) return pfn_valid(pte_pfn(*pte)); } +/* + * Block size is the minimum amount of memory which can be hotplugged or + * hotremoved. It must be power of two and must be equal or larger than + * MIN_MEMORY_BLOCK_SIZE. + */ +#define MAX_BLOCK_SIZE (2UL << 30) + +/* Amount of ram needed to start using large blocks */ +#define MEM_SIZE_FOR_LARGE_BLOCK (64UL << 30) + static unsigned long probe_memory_block_size(void) { - unsigned long bz = MIN_MEMORY_BLOCK_SIZE; + unsigned long boot_mem_end = max_pfn << PAGE_SHIFT; + unsigned long bz; - /* if system is UV or has 64GB of RAM or more, use large blocks */ - if (is_uv_system() || ((max_pfn << PAGE_SHIFT) >= (64UL << 30))) - bz = 2UL << 30; /* 2GB */ + /* If this is UV system, always set 2G block size */ + if (is_uv_system()) { + bz = MAX_BLOCK_SIZE; + goto done; + } + /* Use regular block if RAM is smaller than MEM_SIZE_FOR_LARGE_BLOCK */ + if (boot_mem_end < MEM_SIZE_FOR_LARGE_BLOCK) { + bz = MIN_MEMORY_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)) + break; + } +done: pr_info("x86/mm: Memory block size: %ldMB\n", bz >> 20); return bz; -- 2.16.3