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 3C86BD59D90 for ; Tue, 26 Nov 2024 10:15:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B33536B0083; Tue, 26 Nov 2024 05:15:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AE4BE6B0085; Tue, 26 Nov 2024 05:15:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9AB9B6B0088; Tue, 26 Nov 2024 05:15:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 7D3136B0083 for ; Tue, 26 Nov 2024 05:15:41 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E301540690 for ; Tue, 26 Nov 2024 10:15:40 +0000 (UTC) X-FDA: 82827839556.05.10B39BE Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf29.hostedemail.com (Postfix) with ESMTP id BDC1C120004 for ; Tue, 26 Nov 2024 10:15:32 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf29.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732616137; a=rsa-sha256; cv=none; b=ZkhNJPuD3WkcQBLJP1jj5mC5xo1XNDu7GNmXrKn2MJJk0tM1dzebbXKmA4XKgRzZgvlxfR J79XPpt7xklaDoCZ/vU28eJvC8fhTzGqwEtIPnqhSobU5Y2yFFirew+AYiBGXUsho/eFjz wp0fZNvEIloZTLaQoZarR41nrOny0YA= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf29.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732616137; 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=vnO20sDXJKnMEKP0y4y9CZ1eLvXQs370Rx7MEisA1ys=; b=XDXOrEUSmia/vqe6YpDFfKrJltzx5MZLt+q3SvCt28W+KG5trPyZLYl26MuJHkBLYqOgDy tAFpOLS2bA3REn58iTe4kVY40U5rtm5B1XNODdPIH4tEDsYZvpNN5xkZu5Uibntvzeuycc /2/oViR7PHzod5ZImngH4Gge2yJ9Fzw= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6C2B81682; Tue, 26 Nov 2024 02:16:08 -0800 (PST) Received: from [10.57.89.250] (unknown [10.57.89.250]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 22E3E3F5A1; Tue, 26 Nov 2024 02:15:36 -0800 (PST) Message-ID: <9a61c179-7c06-412f-a09f-0593151eb107@arm.com> Date: Tue, 26 Nov 2024 10:15:34 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v1 15/57] stackdepot: Remove PAGE_SIZE compile-time constant assumption Content-Language: en-GB To: Vlastimil Babka , Andrew Morton , Anshuman Khandual , Ard Biesheuvel , Catalin Marinas , David Hildenbrand , Greg Marsden , Ivan Ivanov , Kalesh Singh , Marc Zyngier , Mark Rutland , Matthias Brugger , Miroslav Benes , Will Deacon Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20241014105514.3206191-1-ryan.roberts@arm.com> <20241014105912.3207374-1-ryan.roberts@arm.com> <20241014105912.3207374-15-ryan.roberts@arm.com> <2510b50b-4178-4c14-b2cc-db5a77a1c8d7@suse.cz> From: Ryan Roberts In-Reply-To: <2510b50b-4178-4c14-b2cc-db5a77a1c8d7@suse.cz> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Queue-Id: BDC1C120004 X-Rspamd-Server: rspam01 X-Stat-Signature: 8rrsnz47kgjmautnqzx34wc1jy3is5om X-HE-Tag: 1732616132-521176 X-HE-Meta: U2FsdGVkX18D9iQYeKAA+skUJwhT6JmZqi4fReh5L83BeVWLW4+etLfVL+9Cmxy4FG25WgzaebketY99NJG+McBcmcUa6TmnvOTu2ESBXxpgoV4Klfn6kK5JT/xPbbodNGExjv2vySxiNg3IepPXCPb/X1bArTOwpqfhQ2iBhXmu3XI5/X9ZYJ7IqssAS+DYoins5LiVsfeH6CdS/kOFzZXt8w8LBM1KB9ziBaMd8XAXkR9hk+i1AK9UZPnD2pim49ihbpJTYbGnYzEJhnmE0TWP8aCQlIT6uEi8lw2fjllxHZAc/zLUY+jBHXPmzjCcGKBIKqAPO9JtpJi2RKLuBD8yTJJ+VuNWkZugjdT6s6XNSScqnSp52eQIHN1fVrCet7x3d9d5Hvjg6EEHV7OU73e9fzew2jTaN09v31GHt22nCtRbhEw+Leh28vUnrX6ewoUNc0lCyEnoXI//JWZhPDjUi2Owq1GeGmAcMazrupkL6N5aLoEb0c8JHcpFCmlo4iFGEAr2x4R4VWeIXXXFa4NAC5Xd9RyJr4wZzfYp170ugJ4O7Bh1eE0WDQxe0C1WqfMdU55AUKV4dS78BiwURUwWESluQ6XU3dC23QfNxOfhRLMo30YKwVGKMIt9Y2xbi+NGFCQWHVJvRC3Fa+nf2MtGKBf2W+UknAOWTeztf86kcfc8vtcxS9qu8HYzAECa8MGcqy3QM6506zI5SV4uc+wQQRJjC4mLPyjBDgv7iMWvE50kwnUwN/CFH7QPufvXbQZKBZbDsmEgX9uFIfh9Nv0X0BFyEwVO5GEJVM3WlzZQJAuXUVPncYJSeGXFy8AKxnwq7uOd9VrowPiUzwmV9v6p9mP2BwrHx/FY1VVm8KbsDoPxFmibx0+uYFM/hsRO99yZ/+eIM2V1lBS+se7ssDglI0CArXEanegJ5qGeMBr2d/NoWOhZRsm3AXkr/A5vTn36WSJLtV06g3xxI09 YvpY3eIt fFtyGgo+jkLmlW9l5qVjt0vfsyJlKf+txhqiAIfDM9haZ0yfe/lflfA29cZI/pxuzQB5J+VWHeKw7FvIQb7/NrNzSldk1193c94RHvjAkXH6vZiBXI/nBTX08Mv+vAl8MaYatoTWNL8+OKsSCcnduSBubs1jOJoAP/khPqFISIGlXwLDuQZPC/meggAYHLBCYPwqie4az56Yzx9mCCWjHH0T5FeodP/mu6BXvVfz94EF8W4fOgRdfPxL1avqQKBCALniUWGeTQGdE936MoIxCVBmimg== 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 14/11/2024 11:15, Vlastimil Babka wrote: > On 10/14/24 12:58, Ryan Roberts wrote: >> To prepare for supporting boot-time page size selection, refactor code >> to remove assumptions about PAGE_SIZE being compile-time constant. Code >> intended to be equivalent when compile-time page size is active. >> >> "union handle_parts" previously calculated the number of bits required >> for its pool index and offset members based on PAGE_SHIFT. This is >> problematic for boot-time page size builds because the actual page size >> isn't known until boot-time. >> >> We could use PAGE_SHIFT_MAX in calculating the worst case offset bits, >> but bits would be wasted that could be used for pool index when >> PAGE_SIZE is set smaller than MAX, the end result being that stack depot >> can address less memory than it should. >> >> To avoid needing to dynamically define the offset and index bit widths, >> let's instead fix the pool size and derive the order at runtime based on >> the PAGE_SIZE. This means that the fields' widths can remain static, >> with the down side being slightly increased risk of failing to allocate >> the large folio. >> >> This only affects boot-time page size builds. compile-time page size >> builds will still always allocate order-2 folios. >> >> Additionally, wrap global variables that are initialized with PAGE_SIZE >> derived values using DEFINE_GLOBAL_PAGE_SIZE_VAR() so their >> initialization can be deferred for boot-time page size builds. > > This is done for pool_offset but given it's initialized by DEPOT_POOL_SIZE, > it doesn't look derived from PAGE_SIZE? Good spot; I think I initially did this when DEPOT_POOL_SIZE was still based on PAGE_SIZE. But then I've subsequently re-defined DEPOT_POOL_SIZE to be independent of PAGE_SIZE. I'll remove this part of the change. > >> >> Signed-off-by: Ryan Roberts > > Other than that, > Acked-by: Vlastimil Babka Thanks! > > >> --- >> >> ***NOTE*** >> Any confused maintainers may want to read the cover note here for context: >> https://lore.kernel.org/all/20241014105514.3206191-1-ryan.roberts@arm.com/ >> >> include/linux/stackdepot.h | 6 +++--- >> lib/stackdepot.c | 6 +++--- >> 2 files changed, 6 insertions(+), 6 deletions(-) >> >> diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h >> index e9ec32fb97d4a..ac877a4e90406 100644 >> --- a/include/linux/stackdepot.h >> +++ b/include/linux/stackdepot.h >> @@ -32,10 +32,10 @@ typedef u32 depot_stack_handle_t; >> >> #define DEPOT_HANDLE_BITS (sizeof(depot_stack_handle_t) * 8) >> >> -#define DEPOT_POOL_ORDER 2 /* Pool size order, 4 pages */ >> -#define DEPOT_POOL_SIZE (1LL << (PAGE_SHIFT + DEPOT_POOL_ORDER)) >> +#define DEPOT_POOL_ORDER 2 /* Pool size order, 4 pages of PAGE_SIZE_MAX */ >> +#define DEPOT_POOL_SIZE (1LL << (PAGE_SHIFT_MAX + DEPOT_POOL_ORDER)) >> #define DEPOT_STACK_ALIGN 4 >> -#define DEPOT_OFFSET_BITS (DEPOT_POOL_ORDER + PAGE_SHIFT - DEPOT_STACK_ALIGN) >> +#define DEPOT_OFFSET_BITS (DEPOT_POOL_ORDER + PAGE_SHIFT_MAX - DEPOT_STACK_ALIGN) >> #define DEPOT_POOL_INDEX_BITS (DEPOT_HANDLE_BITS - DEPOT_OFFSET_BITS - \ >> STACK_DEPOT_EXTRA_BITS) >> >> diff --git a/lib/stackdepot.c b/lib/stackdepot.c >> index 5ed34cc963fc3..974351f0e9e3c 100644 >> --- a/lib/stackdepot.c >> +++ b/lib/stackdepot.c >> @@ -68,7 +68,7 @@ static void *new_pool; >> /* Number of pools in stack_pools. */ >> static int pools_num; >> /* Offset to the unused space in the currently used pool. */ >> -static size_t pool_offset = DEPOT_POOL_SIZE; >> +static DEFINE_GLOBAL_PAGE_SIZE_VAR(size_t, pool_offset, DEPOT_POOL_SIZE); >> /* Freelist of stack records within stack_pools. */ >> static LIST_HEAD(free_stacks); >> /* The lock must be held when performing pool or freelist modifications. */ >> @@ -625,7 +625,7 @@ depot_stack_handle_t stack_depot_save_flags(unsigned long *entries, >> */ >> if (unlikely(can_alloc && !READ_ONCE(new_pool))) { >> page = alloc_pages(gfp_nested_mask(alloc_flags), >> - DEPOT_POOL_ORDER); >> + get_order(DEPOT_POOL_SIZE)); >> if (page) >> prealloc = page_address(page); >> } >> @@ -663,7 +663,7 @@ depot_stack_handle_t stack_depot_save_flags(unsigned long *entries, >> exit: >> if (prealloc) { >> /* Stack depot didn't use this memory, free it. */ >> - free_pages((unsigned long)prealloc, DEPOT_POOL_ORDER); >> + free_pages((unsigned long)prealloc, get_order(DEPOT_POOL_SIZE)); >> } >> if (found) >> handle = found->handle.handle; >