From patchwork Tue Dec 10 22:05:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13902355 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 A0EA8E77182 for ; Tue, 10 Dec 2024 22:05:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C6468D001E; Tue, 10 Dec 2024 17:05:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 275A88D0017; Tue, 10 Dec 2024 17:05:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07AA78D001E; Tue, 10 Dec 2024 17:05:50 -0500 (EST) 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 D97628D0017 for ; Tue, 10 Dec 2024 17:05:49 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 95DBCA0F8D for ; Tue, 10 Dec 2024 22:05:49 +0000 (UTC) X-FDA: 82880432166.28.07214DA Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) by imf13.hostedemail.com (Postfix) with ESMTP id 78EC420008 for ; Tue, 10 Dec 2024 22:05:25 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=YBt1OE8b; spf=pass (imf13.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.44 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733868330; 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:dkim-signature; bh=60R1hVTxsjiamUbrEoUH7TiaG7L9jG3XfbmxuhEpKo4=; b=SVZFiHtF42Y6eTP1/LbOC38BB+li2tJK7y14OvDlNrpsefH1ZhLovMQobVwSaSlzvUAZJM BaPI56EDl7zb750dgBABIKZyDkU43AUJg/RtWAI6AuN7x2PBQ49TGeWVOymRW+d/s2BnSs ibL9N2Jq9dl3ncI/36/UvIhMZiElOog= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=YBt1OE8b; spf=pass (imf13.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.44 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733868330; a=rsa-sha256; cv=none; b=4zfSKGO+VOR8EEsQJef+Ao6/CbALEhN4qubnYxLkfMBHxYK9BDzi5/t8URUQnHXgETJF2i 5Q8oY9dYzjxuJCD+jP2p9Hn/aWCoymLm4AFzY7fu11I0V830qcCSaXpi0S5oekWs+Lhms0 xe8Iyn4d4aSmzsBNwtFxZZfSumQgkp0= Received: by mail-qv1-f44.google.com with SMTP id 6a1803df08f44-6d92cd1e811so766506d6.1 for ; Tue, 10 Dec 2024 14:05:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1733868347; x=1734473147; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=60R1hVTxsjiamUbrEoUH7TiaG7L9jG3XfbmxuhEpKo4=; b=YBt1OE8bRC2ztawaeiBZ+uy5wLr9A8RGILb+TNYwhDWYjUTRSqSN/Bj4lzbkak3poz fGUMWP9MvfAHaVcpY26dyuFnIPGJLtIt/9LVaYZMkNv7PifUiNGR23JREn7ck1RFaQn5 dAPL5jboW/4347aTcMUvMIuiMqV3hXGm/3wTRrAItNICPoUF2ucYTOn6xddTKLK5cs9+ vpm0vjf1cEG1uK9YFevetA32Yn7cuDh1X42QYay5rXcmDV9tp3TmCw+ZoAWRbxDYbR7M 0/jduRBlqghGAhhACWE+oU4FTi4pPa2DobsSK39e3Rwa1Za6xugBaBl4qlXyKl8aTjih a/Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733868347; x=1734473147; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=60R1hVTxsjiamUbrEoUH7TiaG7L9jG3XfbmxuhEpKo4=; b=fzDtXHq2xWvHisM9MB9K2xbgshThFhQJOU+cSVXkKVl9PD1Wi2STpwnba6kX4xnXg3 tOomf+e3lqcsQTHoLvpsfha6kMa9ipT7sMnAGZPzYyvkvL03j/VfIVr7fMPbUSP4HHLm IABJVTEb1l0IowRcTd3fqW3dMafwp+q44lxvNMBeK0i1nIJKMKOSIlG9wGRPzABsNGmA pyGMU2FltrE49AxPvuPTwIaOCy/cX5AZ4NA1qGVyRJToLpSQiOrJJvDRKX8sp3+6Qdt/ gjCuMa61uJ5f/HO3VcXwwvE/1xBh1WKaW8RvPQ6JO4TlIqRqZC8QFSDav/6BodHOgywy sfKw== X-Forwarded-Encrypted: i=1; AJvYcCWVL0p6Zjn8pFQGx2T13XfEklmp6BhJ9tHyMTlsUq1WRxqm6Dtv82tzsOjCNVZ5C2JmkyjjJ+BiFg==@kvack.org X-Gm-Message-State: AOJu0Ywny3+aZNaL7a3YsEzo+IJwiHyQHo5z5dZky/NzJt/xVgnY3IfK xXq8A7AwtbtptFRV+22oRNw+1HBUeM3gtvlXW8XaVtJt33uR7qLVG2mCxkbwaYU= X-Gm-Gg: ASbGncsN6Zg873vMkGiqOYLSoRA2mQhNHv5Ftzkb6Jn/lA8bjyeuJDaGmYgi01iVGXJ MPNIFsEA906XbDnKJ4mFbdD2+LbqHa7zN1T5jmc67VA+XqBgWETonpHBy4+iCCWGTF5wNQLMdyx s4C9XtZ4vmar+ChR0dKexd4tPj74kq/KSAtFPhMQSo/oE/fd1fctrbgDrHV5KAcWJwk7MoCccmi d7TJVg5ab8KrTo8hVAc0cATr24OHvCglWCv4+BYrTqxpH8SIOg87B9Nylkd69ExR6Ghib9r2Fo6 Bf1ZfpNqVIHQ3SwbJDoFTSLb6ro8JWvYUjeNM9Y= X-Google-Smtp-Source: AGHT+IHc57rNPDT3ETou4ayUZZMOYLv4oTDJ4vzRb5FMnCPekUkkWfUgKrPMA1hVHVlHX0Bm8hfnCQ== X-Received: by 2002:ad4:5de6:0:b0:6d8:f50e:8036 with SMTP id 6a1803df08f44-6d935314e21mr9170026d6.20.1733868346746; Tue, 10 Dec 2024 14:05:46 -0800 (PST) Received: from PC2K9PVX.TheFacebook.com (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d8eeb132e1sm49707756d6.35.2024.12.10.14.05.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 14:05:45 -0800 (PST) From: Gregory Price To: x86@kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-mm@kvack.org Cc: linux-cxl@vger.kernel.org, kernel-team@meta.com, dan.j.williams@intel.com, ira.weiny@intel.com, gourry@gourry.net, dave.hansen@linux.intel.com, david@redhat.com, rppt@kernel.org, akpm@linux-foundation.org, luto@kernel.org, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, rafael@kernel.org, lenb@kernel.org, osalvador@suse.de, Fan Ni Subject: [PATCH v7 1/3] memory: implement memory_block_advise/probe_max_size Date: Tue, 10 Dec 2024 17:05:15 -0500 Message-ID: <20241210220517.3744-2-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241210220517.3744-1-gourry@gourry.net> References: <20241210220517.3744-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspamd-Queue-Id: 78EC420008 X-Rspamd-Server: rspam12 X-Stat-Signature: btrntw3knbp1tykma9p43oi7a6bb7876 X-Rspam-User: X-HE-Tag: 1733868325-510959 X-HE-Meta: U2FsdGVkX19Okw7kZBBxwhAd9gPy0XQfCv7BKDiLZrWI/Ycep5k5Gc4bx6vJD6xyW/Z0eGUftyd9/DPaTuNyoIW+dogOedODC8bjpk6CQKWuz+57sD7bquYRt40vuDkQVsw9++gmJKaZeaouTDIA77Ds9ncsn6njCyFQnaxeFpn40IzWdWT5n0AtYIQFP3TyJxkfMFF4fEGgFvcmRxvMvm9LDLTQFoaYU1QZUnvTcprya2TslQoo3cNraiWP5vWy+F+gOvUQdcJU+xOpSzXzqe86bpWlx7HXOR0fdlrANZf2AdANqxUJpk0Y6Df4KoAeY8tPKi87nDewl/AQ/JdURbNhFuvGFoG5E8qdMR3N36n9rwvaGsxYLwVab2MeRw5QgnOA/sK+EFGqyce99bxucUC45pkhYTpawY+jJcFsDFdRU6vCMNwuSqdUwZ0xLScVUq0AZnHdfVWoq+Ev554cA0fLWQHqoujemq85y7RQhdqcPDojMuZxGsjo5Bipmi/GkJ+EfvXXYjFGKvk8vWds/8VMbXr/k0hbZrH1F7nn/tkCAhARBSu3EDLYqTd0AyBbqsNgJySMMxfkXTQRxWcJuJRkmOCyBpK3Kgm83ZAKq1AaQJJJ8cXy8mMn2ZIr9i2RN/G4n1Aa6fel7A+pxMtV5zEfQNRPdmmWBM0Y3KU5z2I2zNSXleR+whqcSgJtfVqtjmsqBXCmzjIUQhoOEj/Q6KbSpJNfre06Clpoadw3KuMdhAxS8aR8LidULpzcC1yVP30vEPRS7/YwIMoYT7/XgOxu0pHP88s5z2Metgh4Y6JAE1/Uuh6P8Te7lxwib47a/IP4Ddnn4heZ90znwVDzwTm9lgZari2Q9rbIkZyUVLR3eN3DNmzKxF/ePQYGoeeUrqjjd20Qc0UYG1dA0+8LysEIoDIGnXAY/FbdEnxp3odrjtBkgk0X+fEegKy0UPtuqowNZEozXhMDWBQM3lA 3u5pCF8t xGVI5Ylnn+Kn3lafLUnu3d+bpGsPK34G2kNbRae1w9b/qKVzhTxLXWpIRHwwo77PAXgV5kT1V5mRVBaMQpdV6VSnlUh/8taZdRVuP4wvd0SYzy9vkHunXwRYgdYMdNNNkwBldq8KWXaSiiK2CTnQ9NTXGvZzDyjAYdhMHcSf89X3kt5/FaaXebD9uVgwojGsCwinrVy0eEO38jVbZaawPf1+MRQdvIJXsyCiXJiQXPL3jagXfd+2IyEHMjL3OfknMC802kMKqoRWohP1E96ADxO83LznIDBCx1uCouZIetyp/RdrGj6AETLC5n/eSiXf74dnwK57FrIirJw+AdMzgxAWVtxa04aSUrUCus7ll5ZQUKx9HdYTHn85WH7jLmnLMGxBfK4Ow1F6CM8oKOtclxLypb6g9x4D+CuXxsD4JlCQqX7F3i9Bij0TSyvQXsT1ysrDs 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: List-Subscribe: List-Unsubscribe: Hotplug memory sources may have opinions on what the memblock size should be - usually for alignment purposes. For example, CXL memory extents can be 256MB with a matching alignment. If this size/alignment is smaller than the block size, it can result in stranded capacity. Implement memory_block_advise_max_size for use prior to allocator init, for software to advise the system on the max block size. Implement memory_block_probe_max_size for use by arch init code to calculate the best block size. Use of advice is architecture defined. The probe value can never change after first probe. Calls to advise after probe will return -EBUSY to aid debugging. On systems without hotplug, always return -ENODEV and 0 respectively. Suggested-by: Ira Weiny Signed-off-by: Gregory Price Acked-by: David Hildenbrand Acked-by: Mike Rapoport (Microsoft) Acked-by: Dan Williams Tested-by: Fan Ni --- drivers/base/memory.c | 53 ++++++++++++++++++++++++++++++++++++++++++ include/linux/memory.h | 10 ++++++++ 2 files changed, 63 insertions(+) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 67858eeb92ed..835793150b41 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -110,6 +110,59 @@ static void memory_block_release(struct device *dev) kfree(mem); } + +/* Max block size to be set by memory_block_advise_max_size */ +static unsigned long memory_block_advised_size; +static bool memory_block_advised_size_queried; + +/** + * memory_block_advise_max_size() - advise memory hotplug on the max suggested + * block size, usually for alignment. + * @size: suggestion for maximum block size. must be aligned on power of 2. + * + * Early boot software (pre-allocator init) may advise archs on the max block + * size. This value can only decrease after initialization, as the intent is + * to identify the largest supported alignment for all sources. + * + * Use of this value is arch-defined, as is min/max block size. + * + * Return: 0 on success + * -EINVAL if size is 0 or not pow2 aligned + * -EBUSY if value has already been probed + */ +int __init memory_block_advise_max_size(unsigned long size) +{ + if (!size || !is_power_of_2(size)) + return -EINVAL; + + if (memory_block_advised_size_queried) + return -EBUSY; + + if (memory_block_advised_size) { + memory_block_advised_size = min(memory_block_advised_size, + size); + } else { + memory_block_advised_size = size; + } + + return 0; +} + +/** + * memory_block_advised_max_size() - query advised max hotplug block size. + * + * After the first call, the value can never change. Callers looking for the + * actual block size should use memory_block_size_bytes. This interface is + * intended for use by arch-init when initializing the hotplug block size. + * + * Return: advised size in bytes, or 0 if never set. + */ +unsigned long memory_block_advised_max_size(void) +{ + memory_block_advised_size_queried = true; + return memory_block_advised_size; +} + unsigned long __weak memory_block_size_bytes(void) { return MIN_MEMORY_BLOCK_SIZE; diff --git a/include/linux/memory.h b/include/linux/memory.h index c0afee5d126e..8202d0efbf46 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -149,6 +149,14 @@ static inline int hotplug_memory_notifier(notifier_fn_t fn, int pri) { return 0; } +static inline int memory_block_advise_max_size(unsigned long size) +{ + return -ENODEV; +} +static inline unsigned long memory_block_advised_max_size(void) +{ + return 0; +} #else /* CONFIG_MEMORY_HOTPLUG */ extern int register_memory_notifier(struct notifier_block *nb); extern void unregister_memory_notifier(struct notifier_block *nb); @@ -181,6 +189,8 @@ int walk_dynamic_memory_groups(int nid, walk_memory_groups_func_t func, void memory_block_add_nid(struct memory_block *mem, int nid, enum meminit_context context); #endif /* CONFIG_NUMA */ +int memory_block_advise_max_size(unsigned long size); +unsigned long memory_block_advised_max_size(void); #endif /* CONFIG_MEMORY_HOTPLUG */ /* From patchwork Tue Dec 10 22:05:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13902356 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 5FDABE7717F for ; Tue, 10 Dec 2024 22:05:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B08588D0020; Tue, 10 Dec 2024 17:05:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AB2B48D0017; Tue, 10 Dec 2024 17:05:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92E7B8D0020; Tue, 10 Dec 2024 17:05:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 73FE28D0017 for ; Tue, 10 Dec 2024 17:05:51 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3BFAE120F49 for ; Tue, 10 Dec 2024 22:05:51 +0000 (UTC) X-FDA: 82880432292.14.DB5EA7B Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) by imf08.hostedemail.com (Postfix) with ESMTP id 554E516000A for ; Tue, 10 Dec 2024 22:05:34 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=vLcP42KJ; spf=pass (imf08.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.48 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733868338; 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:dkim-signature; bh=oErJky2BLU9Af7jLve7daZWId/j12r2NaH/TqvsN93M=; b=cA6q3S0Iw4wPOGAoS5azkXYMYi3uq8FbBHBSEmXa68m2vKwjGhfpv0nt0WgH63f0IF4N9y RS59IwBbWiWHhzENQ3FhvzdzFdyrxou3Q4yWzRPmTfXrGmh4OVhTwmLQnICOWeQzmp/Jtj /D3myApk23izfb36dH8BPUWeoc+s3D8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733868338; a=rsa-sha256; cv=none; b=i6xS6tTOANByOq2f5ZZvC/tzaR+KkZwNT3z/yMOF1VQrdfDWu/ij7vbCkOwg3hGsZAjyeb Z5j+8M8B8BtYYVNr4NLthXH2aBycaYG0yuCokazjyZxXZ3DlfR5pxR8zZE4yTv21U6SJl2 whaTKoI3Z5m1dxSfhkuM9J4GGYzhPas= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=vLcP42KJ; spf=pass (imf08.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.48 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-6d888fc8300so32758566d6.3 for ; Tue, 10 Dec 2024 14:05:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1733868348; x=1734473148; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oErJky2BLU9Af7jLve7daZWId/j12r2NaH/TqvsN93M=; b=vLcP42KJhZKzo54P+8HeIX4Q8/3lBLGf0VD3CC/1TzIU0p0cycHd1mkNhh5dWoVGXA Tfl8E3RSuGEY6UO8Ruajb9ADec0ghPX163QdaF0aXtVvZAkkdCRT2lLhzGwXgAZSw1Yi lDeLPpJmaufg9YsYdURxcCpFoWEgPWNVLW5r+0zVP8P6b0R4PeTSvEPchiDKzqI1gEUH Pvu83DVwu5xDBOChpXVEq4X1+8JOoem/ojoulp6DVZhdzu7pByKMhcfWK7/FlH5Rgtdc PYdTbnOR3fnOsIB91PH6f6rE681nCXDTWDw/O2/3792dg2pMTocjZ+58/4wXa6S2fCsK Grqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733868348; x=1734473148; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oErJky2BLU9Af7jLve7daZWId/j12r2NaH/TqvsN93M=; b=NoVca6zxl4aZiBhPBIpCD6Jn1B3a1+7kQqLLG2MwvnXQjOD4sl4ZKDCiokiMntLVjs yYp2Jw75z7tVabv6eCA0xsiYoVjI+0WXC677BZTJ1WdtqVoxSbyhJVGDOj/oUCPuL6q7 qo/GbbP+LdmJxIX++DCBbbXmiIAc+WaCU4C4Sl9RYpKII5WwfwZjq1ncrB3M5YVggm29 EPThBjuZziQrGTfbED13eST46FVbpkCQLVq6ALZgfpZfFL9WfvSRLlDm5A0XuSSmOoAD +wqtl7HjT0GMZKaJnq4wZGdkAgUqNm1OzdlFWtxLtVn5dYtWezTku5oUyTFpYTlxNikT Vq/Q== X-Forwarded-Encrypted: i=1; AJvYcCXgMy9HoRAZMyzHwY281m8op6V/bcLkDJdcwexAbGuCgSuhh0fxsZZ+0Y5kx2o6TbbBxxOPMRNFdw==@kvack.org X-Gm-Message-State: AOJu0Yy7V+DXlhzP44KH8xQsjBtgqzhvm3PyQde3IVv/FKPMddmRnQRL r53hi+JPSTBekdd0spzD7hVA3TW6DeGOgs9fF6BBem4N3OK+Rct4O075pWF8+M0= X-Gm-Gg: ASbGncvd0zkz6rT1qXqAhfBHau1HeS9FvkCo6zwC/ji4vp3NOjnb9UgxD13AWcuo2p0 amA2NU6s8kqDBPMNL/5lxTHy54iRBfP6RL72yd1MDyN2kba2sA7pMzQbiVIVeFgH07sw5E37f54 aRNNkIojNCO7ODmaMtc4707EYVePP2FW8NgXsgPCxeULj4qy/4cWwNag2Uz1DbAb4uzbdcWoWae vQJ4ipI/hXvCOTDqtMLyJTllcTjrDMkMDRcJoaL4DX1/DNkPK3ncG8t824V6JTPU2QruHT7nrZE YMzM4aEh42cT5b0Lq4KaSWmxzXVmsBH4Ja5qS2s= X-Google-Smtp-Source: AGHT+IENYQ0oAKQ+kT8P0UCH8ySBpUYpnMabT5K76y4L5ld+Nf2r6CwojmMzmHyhvdr+kBpYd1jW3w== X-Received: by 2002:a05:6214:2682:b0:6d4:254f:1c8e with SMTP id 6a1803df08f44-6d934b7cc2amr10515796d6.37.1733868348294; Tue, 10 Dec 2024 14:05:48 -0800 (PST) Received: from PC2K9PVX.TheFacebook.com (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d8eeb132e1sm49707756d6.35.2024.12.10.14.05.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 14:05:47 -0800 (PST) From: Gregory Price To: x86@kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-mm@kvack.org Cc: linux-cxl@vger.kernel.org, kernel-team@meta.com, dan.j.williams@intel.com, ira.weiny@intel.com, gourry@gourry.net, dave.hansen@linux.intel.com, david@redhat.com, rppt@kernel.org, akpm@linux-foundation.org, luto@kernel.org, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, rafael@kernel.org, lenb@kernel.org, osalvador@suse.de, Fan Ni Subject: [PATCH v7 2/3] x86: probe memory block size advisement value during mm init Date: Tue, 10 Dec 2024 17:05:16 -0500 Message-ID: <20241210220517.3744-3-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241210220517.3744-1-gourry@gourry.net> References: <20241210220517.3744-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 554E516000A X-Stat-Signature: f7hg71dt5ah515446r7r1ez1iha1en6x X-Rspam-User: X-HE-Tag: 1733868334-248366 X-HE-Meta: U2FsdGVkX198dQF8Vg57Z2MckxGIEu3n9yzpNd7aYYpD9ZQPB5WMJK4BBoJcmjr93LgBUjUyWZuNuETVxkxuPBrRbFoqiwpCgCIwL+IBGxJafokO19yZWC6CAYPCvD9nLm67M+SjDMCbEC6LiWLBCH4f91F6p2X0WLXxiUw2YPFn2gz2E7+5POJHoR5q5CsJ2lOxs3sY8+sHXWtyceLkDVIKRTKF2XLGxBYH+Zd8NpT78ovWXaaUEx3ugQciMNpw5cwI92QReOZL5sOqbGxQYqhtLGGYJMSr1coIgE3v0XVsuPzcvk1e4O7CbUTNHTosdt7Eoaagv5p9nDU6oJZwmSy4id7bne1oLrm8/SBmTXRQxCsOGLK2Rhxz3x6VxDUQnOKxO0HA0msQRJo/Scx0NPKKgih4OUlLLrPgYMO+BiwYcluwxhx1GbOQ9+O0CQnd0V5qqz+MaKYJ8pUU5q1SWgGOMmfmca4/F3RVxWvVNuq7LNKjbFmI8Rc0ZJAXpIJCc3mniUNa9xtJ4IufLq3jsh7wH8gSBgdc+VgV/XH6pBnGEIw0TqL9XH+/zCpDZTtVAiyeomrPKi2sBm6ttAY5E8sRutLwkasoVXIL7raCjzXKkVDBT+FAxeXNY5kXIom+s9pje7qPT29ku65yBgO60Bw72pRRFdYDXX1wmvsMaXFD6taDgvILOuoQ7RyycUrY9YYisHqVxrtd14e2lgSlPqM7He83yLkVbZ1ef5ZBUH9hWUbH+y4HSGZH7YIBPK7qIIhG3ZGJhlrSfh5H9F6o0Y58mQdwPPIK2KVo6NAbdeQXgnhVX+QLzgza/jWnh75L998WjY5B73MzPN5pC2rWXJO26LSSdqP3cKtfI7wCRVhJTIuWUAllf3HpsDK8tE4POITvE8OurY+blSOo6NUCMgg6NcKEqch0FvwhD7Jk1+O/FnZ+ERUaJIpU0MrhURZ7kq3nWCejwTQF/gU6Ro4 n7rWTcrL nIBr/6qrjFs/h2Qp7w+r9v3vH0K2duH9lLfyfX6/enGJ2RjYZNdwZU6psIGNAZFwiaElZmSqJKlBlbZhoVYPrBu+oPZTf+ElTYHBcBAAD6DsWViXPeKxKZUmECSZS5Ar+VidjD5oW+xvk4IEnbK5k9TPpmprjkvk49rFHqDlF4Iqpvj5CKo5ldsFew6ZxTtJ68xUKsKjyBo2n44ETE/i8lmipxiu9RdCgYG15cUNdQs9s9QeUMYQMeCE/Jmsp/Kb5qRVikyK6+Q48QYYsSyv/WkmI7hmG8FAk2/+OzgEc/Gm7dS2CnPqbieZZbwYEJgchmTXhUdq7Grm3Zl2MWw+5LAmCd80QckijDiEAJ1Ps9QM+smhJZgQR8EXlBDQmdb9XpNTLPdepzSgK8M/WkuD+B988tQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000013, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Systems with hotplug may provide an advisement value on what the memblock size should be. Probe this value when the rest of the configuration values are considered. The new heuristic is as follows 1) set_memory_block_size_order value if already set (cmdline param) 2) minimum block size if memory is less than large block limit 3) if no hotplug advice: Max block size if system is bare-metal, otherwise use end of memory alignment. 4) if hotplug advice: lesser of advice and end of memory alignment. Convert to cpu_feature_enabled() while at it.[1] [1] https://lore.kernel.org/all/20241031103401.GBZyNdGQ-ZyXKyzC_z@fat_crate.local/ Suggested-by: Borislav Petkov Suggested-by: David Hildenbrand Signed-off-by: Gregory Price Acked-by: David Hildenbrand Acked-by: Dave Hansen Acked-by: Mike Rapoport (Microsoft) Acked-by: Dan Williams Tested-by: Fan Ni --- arch/x86/mm/init_64.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index 01ea7c6df303..58ace82874eb 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1462,16 +1462,21 @@ static unsigned long probe_memory_block_size(void) } /* - * Use max block size to minimize overhead on bare metal, where - * alignment for memory hotplug isn't a concern. + * When hotplug alignment is not a concern, maximize blocksize + * to minimize overhead. Otherwise, align to the lesser of advice + * alignment and end of memory alignment. */ - if (!boot_cpu_has(X86_FEATURE_HYPERVISOR)) { + bz = memory_block_advised_max_size(); + if (!bz) { bz = MAX_BLOCK_SIZE; - goto done; + if (!cpu_feature_enabled(X86_FEATURE_HYPERVISOR)) + goto done; + } else { + bz = max(min(bz, MAX_BLOCK_SIZE), MIN_MEMORY_BLOCK_SIZE); } /* Find the largest allowed block size that aligns to memory end */ - for (bz = MAX_BLOCK_SIZE; bz > MIN_MEMORY_BLOCK_SIZE; bz >>= 1) { + for (; bz > MIN_MEMORY_BLOCK_SIZE; bz >>= 1) { if (IS_ALIGNED(boot_mem_end, bz)) break; } From patchwork Tue Dec 10 22:05:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13902357 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 A22BAE77180 for ; Tue, 10 Dec 2024 22:05:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B7B9B8D0021; Tue, 10 Dec 2024 17:05:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B29DD8D0017; Tue, 10 Dec 2024 17:05:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B9FD8D0021; Tue, 10 Dec 2024 17:05:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6A8458D0017 for ; Tue, 10 Dec 2024 17:05:53 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1E1E54293C for ; Tue, 10 Dec 2024 22:05:53 +0000 (UTC) X-FDA: 82880431704.06.6A232AE Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) by imf11.hostedemail.com (Postfix) with ESMTP id BE0C840003 for ; Tue, 10 Dec 2024 22:05:30 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=sBRgcb0S; spf=pass (imf11.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.46 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733868328; 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:dkim-signature; bh=EAbRT3t6URREoSf/WrSmqWIQoci4Yw7h23phPh/fk7k=; b=aSXoZ2OpIx2VajGAs3Dn0oniYmnzCMr4BJCuP5j63NpBhudGgBeDvxavqakwzNIB7rY2PZ JOmavlQLNCw6mt5fkn00aroB1VRlgPyBo2fGREn9WBhwrQKeUHGE2Rneb3NBVMfY1iA3eq +eLXZYOA/aYZMBCvlOqih9qJ1poaGEs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733868328; a=rsa-sha256; cv=none; b=i5oOFOi2PJSrbHc9KGgnAJ+MBE4GJUKIV6ASyflfhzMIyFP2bZ7O/0B1/0uQD2kQPFRw3Z Cr4b383TvliWtC4oZvjPqtS1jvQqxmdWmN7IWpNgRMfXqiUrm+QvcXXHmFd4OouUac/2rT sB/BQB3fR8vmI0bse7umFREXpi6IMj4= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=sBRgcb0S; spf=pass (imf11.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.46 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-6d89a727a19so905736d6.0 for ; Tue, 10 Dec 2024 14:05:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1733868350; x=1734473150; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EAbRT3t6URREoSf/WrSmqWIQoci4Yw7h23phPh/fk7k=; b=sBRgcb0SVplwpgA2DkgFCEi1fq+xJBdl67854S6LIn+ZFVwJh/9liiMgeCKJt4YE74 JPehmjjqvwsmM7ppavTZPGBY9mY8ANXhdQB2f3rNVd5QcsUVY4xoufGpjejpk/qgspO5 j6omf1Oh+LX1wYMTHaBugsY8AUp/ngOBLfoTabCiied+xOWcSSbBExdfVPyjzrkr8dU2 ABPNXHex55RK5qBpfreOThzr5fauWzQmI+d4Rhwsdfw4adkrVjyRt8FuacI0JOWvMmyu /CrtZSDtrmCfaKT0CAhQeXu9qQHun3K5JhQZMXH/ruE8jblKiYYrFXX1wMbSEM6Sg4nP oE1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733868350; x=1734473150; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EAbRT3t6URREoSf/WrSmqWIQoci4Yw7h23phPh/fk7k=; b=X4O8YcYoqfM/PY7oMPCylEEcLGoiIw751Avj2yi2niH5jJsmesioaaPu/Qs962k2kF 6pzpBF7Oc7RcKUZ7LFzFaa8zFRKJPNWN+7QBmaciFY2HUv0eJ8SXryEc6sEgNppf3ol3 nLcoCxp3nbiEP+ymfV5SBRWRkdu171S1C1oG9gAy8RbhSMkPvrBinpq+yh716Ys+fTEs nU6EHDeqS/3Ss1ljC0XeHp/1hjaIU9slGDVBvMh+3a9ECd0ntIksForsKJFF/c/0rQ7H k2bgN614dbTofXJRjgVgw6lKvw3RnFyY63/NGQ4Rkg26q7Oz26VZRz6DcN3EPsrLdWnI TCow== X-Forwarded-Encrypted: i=1; AJvYcCWinmgklHdE25Jqa1ghAjh4bejcjbzT8K5hD1cGwNqP/iVupke+o3Dt+4SMMnOqCid41jWHbnc8jg==@kvack.org X-Gm-Message-State: AOJu0YydftyKNdRBJe9PLVaqomWOeeZU9ZRSnyOiSwKmUL5uNox+BPBf NPBaVw6zzAB/NSlwRTRpGM+dGjKNh8zHTuix2KF7X7U3DT9yYIf9MRpOjwFGa3g= X-Gm-Gg: ASbGncv1wAsx1XJnBEtg1m7+BK/Uaw34FTAWsnMfJzWKtcG1eYrv+GbMq3/dX4AxWOs U9teOHvMACNAl+cc6CYHACZD8Gp11aUpB9CK4MGAv9DNjCWg7kFcXNpQE4+D5s9eh+Yuny7DbZZ GQhcwELuNGu1fgyRClIVtZPE2HZYhQD/Ya6WPhKvtIVDxU/mQaYFb7A6WIYoA1gtFuMRUO+244K 3VeLRKb8AWpgR1M9+2Fcdzt3nmN5CyBvdOG1iBTB/MGJZATZpAus57F0jCvrCX+8Da2oUEQaY3E Koxq657k7gN0WJl8UHBDGlB/QKVGQrAXZFAVnOg= X-Google-Smtp-Source: AGHT+IFa401/2CB5gCylFx+OUusnw00jP99YqBV6GuTzUiOFDtq2M92ekuKX3e9+dJid45ADWSbIGg== X-Received: by 2002:a05:6214:260f:b0:6d8:98a0:23b6 with SMTP id 6a1803df08f44-6d9351fb640mr8120916d6.4.1733868350323; Tue, 10 Dec 2024 14:05:50 -0800 (PST) Received: from PC2K9PVX.TheFacebook.com (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d8eeb132e1sm49707756d6.35.2024.12.10.14.05.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 14:05:50 -0800 (PST) From: Gregory Price To: x86@kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-mm@kvack.org Cc: linux-cxl@vger.kernel.org, kernel-team@meta.com, dan.j.williams@intel.com, ira.weiny@intel.com, gourry@gourry.net, dave.hansen@linux.intel.com, david@redhat.com, rppt@kernel.org, akpm@linux-foundation.org, luto@kernel.org, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, rafael@kernel.org, lenb@kernel.org, osalvador@suse.de, Fan Ni Subject: [PATCH v7 3/3] acpi,srat: give memory block size advice based on CFMWS alignment Date: Tue, 10 Dec 2024 17:05:17 -0500 Message-ID: <20241210220517.3744-4-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241210220517.3744-1-gourry@gourry.net> References: <20241210220517.3744-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspamd-Queue-Id: BE0C840003 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: icn6tx5dqntse86sqi94gzbs864dbdi7 X-HE-Tag: 1733868330-335323 X-HE-Meta: U2FsdGVkX1/vhP1wtPYjnF4oQI5b9WIdYBjged2V/b7DVC7ls8F6zPYbjOAbvKZOeonKnfTzxXxr2RkmITOck/KTYrVtkutALvjWbH0ML5QKjJEDWlfFDY6DTzllzpT43oylOB4BgpPWK2tjo7gCwe0iB4puLgcsgy6tJO6fA+6As7PENYxGWnPyorgEl0c6NTCMhEWPAsFSxgrEOt7NP8K37QJ9EmRTJOUQV9b9V6GbMLY3aaT4hGKrULFVTDWs9cQBdzY0V66oHTmmaDzkBoAQovouEofQvQItiqk5m1+DRjwbFbYFlsx+BH4Nwj6kDOIuqyx1bqUDCVZlarr/gHue/BoXOT+7RvpxjVLtMphMsEgEW0Feod8ZA3YjvnllSZa1DYMWtHZLQtjPTOIM4jZW1AuDRGOI1FhfVG1B6ZB3kjgYg8KEx/4UKdzWp9gY3UuOZP6Pktb6Ex7TQY1sal1Eg/YMu+f/BNWPJ4h1rFe8tHc+LkSD5N2stFFZHEGk3iTtEaQ4KZQ6CRC7H79nUseXztk13RrH5SdEdWXrgxtVas+09S+xce8hMHEjMJ+UkTXTlrpZZ9DnVhpQp38rjEi9/YT/aLExW6b8Ig7o4NivG3lGz8omboMEH6OfRum54tCuxPqo/vT0XeM2ebfNsGPts4RIFuX1zeHIduX8xJ/DfAqAoQ0VnhURuzE1vEAigvKF1lOAeV7ZrgRcefa/I3qjuTKvgD4WTIADab0nsL3rLLne7bNIZyYZEjDUL4y+41R9oN4ixT8xG13GGnvcuvn/2hUmhEvqzP0Z9OPuZwlGLlnvY04qrXX+JYeEoptxPrXGENKQjr/aOgw7rJlLmOyzFCdapF3joQYe/TvmXUN8f49HfXo4JlnexKFTVsezHtCcnsRSFib206dCa+S4zbSsw5gyorlBLQXivRLDg4Obimks1hPxvqC+q7/h/N8jSeJr7zz9DVanq22BlYJ aVHeNyCk dhIsF07B47g2HzpIEAlHOS6sH02f/hZJ4NUVPO1hniNBvXh8smz0I2L/1xMeT+O6NEEwqb3yPwWXbnAeGURFbQNQqfTkJE2T3idgDKfi6ZfAV+dLtPpObYhiBIFRXEC7ONwl+GS9mhfIyUUcHblBrOYsx2XumAfY7wrJ3OdjReLqDZaZ25tqcd9N0csgRv37TDwPmBEOreD3R9lM6uFvtw2Ra4JcTk+1NiTdWPEJGcFX/a4UG+cziq2OeWINTlqbQ4czupdAetsLS21vTopwj8sraDjKwTT9tUOKnMisxHVN7Qh17fEYHDCsEkypB84TNoLNCoLinMWpTXtEuwcu7duA4yMXFtsLKoXCURS/kbX68Y8u2Uejxi/13xIMzmhYbDG43p9A7k+urDUKoFTEqs6Brcw== 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: List-Subscribe: List-Unsubscribe: Capacity is stranded when CFMWS regions are not aligned to block size. On x86, block size increases with capacity (2G blocks @ 64G capacity). Use CFMWS base/size to report memory block size alignment advice. Suggested-by: Dan Williams Signed-off-by: Gregory Price Acked-by: Mike Rapoport (Microsoft) Acked-by: David Hildenbrand Acked-by: Dan Williams Tested-by: Fan Ni --- drivers/acpi/numa/srat.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c index bec0dcd1f9c3..af7d51222933 100644 --- a/drivers/acpi/numa/srat.c +++ b/drivers/acpi/numa/srat.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -339,13 +340,22 @@ static int __init acpi_parse_cfmws(union acpi_subtable_headers *header, { struct acpi_cedt_cfmws *cfmws; int *fake_pxm = arg; - u64 start, end; + u64 start, end, align; int node; cfmws = (struct acpi_cedt_cfmws *)header; start = cfmws->base_hpa; end = cfmws->base_hpa + cfmws->window_size; + /* Align memblock size to CFMW regions if possible */ + align = 1UL << __ffs(start | end); + if (align >= SZ_256M) { + if (memory_block_advise_max_size(align) < 0) + pr_warn("CFMWS: memblock size advise failed\n"); + } else { + pr_err("CFMWS: [BIOS BUG] base/size alignment violates spec\n"); + } + /* * The SRAT may have already described NUMA details for all, * or a portion of, this CFMWS HPA range. Extend the memblks