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 F136DC3DA59 for ; Fri, 19 Jul 2024 16:29:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84D486B0082; Fri, 19 Jul 2024 12:29:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7FCC36B0093; Fri, 19 Jul 2024 12:29:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C4B26B0095; Fri, 19 Jul 2024 12:29:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4E2486B0093 for ; Fri, 19 Jul 2024 12:29:00 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id DAE3C1C10EE for ; Fri, 19 Jul 2024 16:28:59 +0000 (UTC) X-FDA: 82357036398.26.0422EFC Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf11.hostedemail.com (Postfix) with ESMTP id 90F6440015 for ; Fri, 19 Jul 2024 16:28:56 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of jonathan.cameron@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=jonathan.cameron@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721406516; a=rsa-sha256; cv=none; b=pZfU6yZbhSncOO1iw6WMm7gRaYixXWeElXtkR0tze/EFvCaFrzMZhRQhYny2mnWiTTZf0n 1n92d71WMjMgr5rVdvsS3dQRIsvFlYm7YJB3XH0DEVA4aqbVyydSl2/30ObhnyYnjg320e dFTKekSwCh5awGsEcgL+b9OveBTa0b4= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of jonathan.cameron@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=jonathan.cameron@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721406516; 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; bh=rLd8GnlDRrDOlqhZQ/udM6MhxXwdFA99qUkg3Cpwry8=; b=5K0wW1xrd8IyDKtFbUos6Qp8GuCNzLpXvNA6jkUeG8SeLNlkAHdqzuG227UnV00WuARKA5 eTSc7aemxCdm21fMwBBlHhbHNclKoQs7o6PcM2311nHyedweQyLyzC3XN+Q3wr6wT5mv+X RiEvWgxvVlL7VaA6KnD0LKc3a6LlEns= Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4WQZn61R1mz6K7Fc; Sat, 20 Jul 2024 00:26:34 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 9E616140517; Sat, 20 Jul 2024 00:28:51 +0800 (CST) Received: from localhost (10.48.157.16) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 19 Jul 2024 17:28:50 +0100 Date: Fri, 19 Jul 2024 17:28:49 +0100 From: Jonathan Cameron To: Mike Rapoport CC: , Alexander Gordeev , Andreas Larsson , "Andrew Morton" , Arnd Bergmann , "Borislav Petkov" , Catalin Marinas , Christophe Leroy , Dan Williams , Dave Hansen , David Hildenbrand , "David S. Miller" , Greg Kroah-Hartman , Heiko Carstens , Huacai Chen , Ingo Molnar , Jiaxun Yang , "John Paul Adrian Glaubitz" , Michael Ellerman , Palmer Dabbelt , "Rafael J. Wysocki" , Rob Herring , "Thomas Bogendoerfer" , Thomas Gleixner , Vasily Gorbik , Will Deacon , , , , , , , , , , , , , , , Subject: Re: [PATCH 06/17] x86/numa: simplify numa_distance allocation Message-ID: <20240719172849.000019a0@Huawei.com> In-Reply-To: <20240716111346.3676969-7-rppt@kernel.org> References: <20240716111346.3676969-1-rppt@kernel.org> <20240716111346.3676969-7-rppt@kernel.org> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.48.157.16] X-ClientProxiedBy: lhrpeml500006.china.huawei.com (7.191.161.198) To lhrpeml500005.china.huawei.com (7.191.163.240) X-Stat-Signature: wj1z5u5bywux7giy936gcbjh8i34qn5t X-Rspamd-Queue-Id: 90F6440015 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1721406536-740293 X-HE-Meta: U2FsdGVkX1+Sw2FbkSZyCwVRIi0UE/6faVSFUBa/Ks6s2tZt7aOUzU3TBA0twZ8CyuJAN8bT76zX1O/A2E5s69fX7GaN6wNl85ZHLw5hjUZ0EmH+ZnXB9NYly1Tz6W0wZsgawFrlj2EC/JLoTqkN2U/D8Em/+/az70KHS/zeBqEjDx/Z5gWi033zb4CxN9ksMXHLTTAVu2S38Xx6eENP2xtlBxk2enWFpvoXg9YBBUhMk4mCcjuG5kE6WfqpKZWNerZuXsEuWpPj3O4vK7/tsRqhZLwNc0URHwrTdUnk4xC9kk1OhaAwsY18mT6wAHav0S/0iTKTmfV/4AyabagNVih2vrf0Dfi+yfNxm+w0bOLXPdZIdgoRAiHpiGisDic+QSarcVWKQhAGL85UrzrotTcE+dOYudEHvO8d1MqKmSYgESvpC0WjGablBVdRQaD++Y1XDjUPKvgBY/QwEzEwS0n4nBbFKlN5T10DR5X6gbTR+gvO5sp43htSjJm8ORiwNjst6cMyFfCm+9UVUxn5VcjNr8X5QV8TfHDC7Q5Pn+xe9hFl7sWplCl+6htxi8V7smWHru6+VW3yamyrn8xcDTwv8ZOVhel0VErO3CRjqg48AasluQUU4FWGCpxHVoMajCsfUm4kWuUjFcmZuYQwTDpRAOGGuz8kgcCFGFWAgHAYqiFLUXtzlJld7iRPJvD3rbkRFUAT8x8NN/hn0r0hH7PPHluR4Wj6ZjyuzGxJkMHAwiR/Wca5xLOF/VZGyHWPhKZbAh8GP2pRBhzARLvuuJNZ+VamS0c+4yLmwn/pTAsDVZud2et3Mefx3fjZrxafN2EB+9xGNbZp5v92VgAMmS5jd1SIBABbU7o0hA8Ta/Zcn3wU46+tYpS7+63ekTHDiWHyFzGGMX85CLUW2U28i52o9Cypqpja0qgA5Ifp+KPEp77EXvUgQWGHysdzXHPk2tLzOjQmDe7AllCsaH9 TWRAAP3k fTHu2hpUagr2eFVn3SbZg1m1z80eljj/eR7jEz415iVDs4IDtcT3aZR2OdrWTz/3N20IylH0TdYMovbPPDxmqtuaxAUjcHzELwlY1XlQ52qHQKn8nHOS1s3fUHHSQ/KnchRd4mDoV0aT9u0XqWtbYrjVs++TIGMAIbP/36L1PKzfu03pJXvJVjOxWB6Zf/6ZJeMbYnmxMsKSVJ4TexI1/xYdoxJ32jbyvOf1s39zVctaOcaeYAeHV2RGpxRBUAgqDFlCFH4TXiWKqVoDWjvAZS1OkefgTM2CuN+1a6bhn9eE3IoWTtBVYm/wrKw== 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: On Tue, 16 Jul 2024 14:13:35 +0300 Mike Rapoport wrote: > From: "Mike Rapoport (Microsoft)" > > Allocation of numa_distance uses memblock_phys_alloc_range() to limit > allocation to be below the last mapped page. > > But NUMA initializaition runs after the direct map is populated and initialization (one too many 'i's) > there is also code in setup_arch() that adjusts memblock limit to > reflect how much memory is already mapped in the direct map. > > Simplify the allocation of numa_distance and use plain memblock_alloc(). > This makes the code clearer and ensures that when numa_distance is not > allocated it is always NULL. Doesn't this break the comment in numa_set_distance() kernel-doc? " * If such table cannot be allocated, a warning is printed and further * calls are ignored until the distance table is reset with * numa_reset_distance(). " Superficially that looks to be to avoid repeatedly hitting the singleton bit at the top of numa_set_distance() as SRAT or similar parsing occurs. > > Signed-off-by: Mike Rapoport (Microsoft) > --- > arch/x86/mm/numa.c | 12 +++--------- > 1 file changed, 3 insertions(+), 9 deletions(-) > > diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c > index 5e1dde26674b..ab2d4ecef786 100644 > --- a/arch/x86/mm/numa.c > +++ b/arch/x86/mm/numa.c > @@ -319,8 +319,7 @@ void __init numa_reset_distance(void) > { > size_t size = numa_distance_cnt * numa_distance_cnt * sizeof(numa_distance[0]); > > - /* numa_distance could be 1LU marking allocation failure, test cnt */ > - if (numa_distance_cnt) > + if (numa_distance) > memblock_free(numa_distance, size); > numa_distance_cnt = 0; > numa_distance = NULL; /* enable table creation */ > @@ -331,7 +330,6 @@ static int __init numa_alloc_distance(void) > nodemask_t nodes_parsed; > size_t size; > int i, j, cnt = 0; > - u64 phys; > > /* size the new table and allocate it */ > nodes_parsed = numa_nodes_parsed; > @@ -342,16 +340,12 @@ static int __init numa_alloc_distance(void) > cnt++; > size = cnt * cnt * sizeof(numa_distance[0]); > > - phys = memblock_phys_alloc_range(size, PAGE_SIZE, 0, > - PFN_PHYS(max_pfn_mapped)); > - if (!phys) { > + numa_distance = memblock_alloc(size, PAGE_SIZE); > + if (!numa_distance) { > pr_warn("Warning: can't allocate distance table!\n"); > - /* don't retry until explicitly reset */ > - numa_distance = (void *)1LU; > return -ENOMEM; > } > > - numa_distance = __va(phys); > numa_distance_cnt = cnt; > > /* fill with the default distances */