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 72C94D65C76 for ; Thu, 14 Nov 2024 11:15:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E9F7A6B008A; Thu, 14 Nov 2024 06:15:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E4FDD6B008C; Thu, 14 Nov 2024 06:15:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CEFD16B0092; Thu, 14 Nov 2024 06:15:21 -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 B20DE6B008A for ; Thu, 14 Nov 2024 06:15:21 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 41E88ACF2C for ; Thu, 14 Nov 2024 11:15:21 +0000 (UTC) X-FDA: 82784442594.27.7832FCF Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf10.hostedemail.com (Postfix) with ESMTP id 60248C0010 for ; Thu, 14 Nov 2024 11:14:59 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=soH1KFQI; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=kQ4TG4KN; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=soH1KFQI; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=kQ4TG4KN; dmarc=none; spf=pass (imf10.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731582831; 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:dkim-signature; bh=0qjey6Mx3Q/UGdfyDuIVN7Gf6sPP9fIdKBKgrtzXg9E=; b=ttTP01kX8TjiUOChKosarPuxcmNYpqoG9i3DGGQrZ52IMSX3Tz+7LJ3mlqe4fsQH+TmUg2 VfqYxtYDRqhU9iy4oTTKJ5ZNNr+Yy2oO1nkq8eB+Va45cjWCF7Hg+IjDOrs9hHHenRJFpx BboJPylruyD+z6mWZAm/nIRDdD8UZl4= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=soH1KFQI; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=kQ4TG4KN; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=soH1KFQI; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=kQ4TG4KN; dmarc=none; spf=pass (imf10.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731582831; a=rsa-sha256; cv=none; b=J16SJ4IOExfw4pTddvPwDQlSJzo3geukfGg9YqdWAqmGsiJe3pXWgRZrvjqJgXDCKdIts2 5CO6K7fgEHzBTWQC6Tqwe2gJFdl2Sd0iCM8ToVz2s2ntpYiLBH5QLaS6KVatAJ1MmHSuO6 QxSqBkBd76ehL7/Tcg6ccBZQOy13EQs= Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 6B01621209; Thu, 14 Nov 2024 11:15:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1731582917; h=from:from:reply-to: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=0qjey6Mx3Q/UGdfyDuIVN7Gf6sPP9fIdKBKgrtzXg9E=; b=soH1KFQIh22uCUjBTw7ooNR7RW3FkSpu16dbXeUuMOZjBi+81nutpdqLjYG7dMO21+ZD38 xlNV5NQmrUgTdTUV0YO8wbL95F2596wNvFya5rrvwN9CpNodcIYgENN6Dg2JD1Xz2zks27 4CRqsDOukFthq5QPWQabS6ZAL7PA4xY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1731582917; h=from:from:reply-to: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=0qjey6Mx3Q/UGdfyDuIVN7Gf6sPP9fIdKBKgrtzXg9E=; b=kQ4TG4KNu3OM2RgAnFIyLRLWHgw8nRfex4fOQN8zExSInSuPKYOW3k2o/Eu0ZFTtni2EfK lCWzuETanD5w/tAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1731582917; h=from:from:reply-to: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=0qjey6Mx3Q/UGdfyDuIVN7Gf6sPP9fIdKBKgrtzXg9E=; b=soH1KFQIh22uCUjBTw7ooNR7RW3FkSpu16dbXeUuMOZjBi+81nutpdqLjYG7dMO21+ZD38 xlNV5NQmrUgTdTUV0YO8wbL95F2596wNvFya5rrvwN9CpNodcIYgENN6Dg2JD1Xz2zks27 4CRqsDOukFthq5QPWQabS6ZAL7PA4xY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1731582917; h=from:from:reply-to: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=0qjey6Mx3Q/UGdfyDuIVN7Gf6sPP9fIdKBKgrtzXg9E=; b=kQ4TG4KNu3OM2RgAnFIyLRLWHgw8nRfex4fOQN8zExSInSuPKYOW3k2o/Eu0ZFTtni2EfK lCWzuETanD5w/tAQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 3AC6113794; Thu, 14 Nov 2024 11:15:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id h8vIDcXbNWeXMQAAD6G6ig (envelope-from ); Thu, 14 Nov 2024 11:15:17 +0000 Message-ID: <2510b50b-4178-4c14-b2cc-db5a77a1c8d7@suse.cz> Date: Thu, 14 Nov 2024 12:15:16 +0100 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-US To: Ryan Roberts , 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> From: Vlastimil Babka In-Reply-To: <20241014105912.3207374-15-ryan.roberts@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 60248C0010 X-Stat-Signature: bnwmp6zi66xobzwd7tiu3j6kcud46dtf X-HE-Tag: 1731582899-586394 X-HE-Meta: U2FsdGVkX1+9l5aJZ4C1POuWzVHadhDELnFas52CLjovlKMnfQjOGXUOemUSBmd8rvDA91vhfk53aJ7sGjnJGBT6xTm9DF3TBxiaFQFVniaupN7dhk1pBNQu27hpqxeu1xsvQ9I6+qBxr3ETev1Ojsvbcfu9ZPkPUMDJXYiuP4zo9ajbJTuZEP9VTEBcsBnLhcWBeGQES6G3ONr38rl4YyxD/TPh7KJwx0C1JQWqknu9IC6qBlh8pjBqr5I1jQkwTI81jyGqqOXyQRxj+BpoeYdI6hSd2ttmYIIktyvsr+yYGI4qILuVvDsJA0eIisGoYbGmJM5rJoWvnWKvLBJVoOQpNXncsJ1hSTQZUtdNdax2zjXs1DnDrxQFKiKWCgIIpMLQGzyIbMHrrlcJoct5C8oZeCnjZoQbEAUJGUVWfBwHKpxsvA9hnKSN2j1t1cbYgJUZxowspNmZ82eb5j437AmuEeBkyFLm7uxUUO0Ur+33BpKHqixu5PD7jxUZeCopFdvyVqHpsWBDqk1BqoMFrFOraM4jeMoSCbBBEaLKsuPc5/Uew3v8YPtmd/3nx5tVNAEzxMleSFCr22QTrWXiUdP+x+kaZaQJfA1A9tKgw4vU1Y/NuV3c4wNJvqfyB8YlwBUpwseM0+bpyP/81Aeh/rP9rEWJveaSqv61xBdKT32ZdiCC0fPR/40uWuJ+QFXxRwEpxN2+J1Lgb0hLfTy90acEjBqooCsWBCPsflwClAd8w5QtiMFDq466oddVREldDBBRbOy9wBdk8auYlx2JNHaA5xmKmvUSFhMqCtLWpP13JUQk9qP61y88UNjhGy5trPvuTosXEWr8cRqdkhkXC2ehZm6T97p8b+6tiv+iNIJ4/FlSPO0Zc2GOFllDy0upqcOlx51nQqhL7K7tyeo7Q7kiqCnZpdFt56vBY2+EuDL4BkgFFzZqecdsLgTrbezCBBnbyobyNZkQ5j3n/78 SMlR0CuC 1DiGl1Lci+VBj1NGGTjstKn/cz5nu6ELVXdp8PREuBh3qhxSmYPzAKXFboTLVvZLmgjLH3jFFn5XAdW9rSAMRavaJ1YbzBW/IVNcdJCkiSfsg1Dlly7OEGR4JyvI8ksg1UsxXZQ2UP+ZBpClN8M2ECeRFamb5zy4MisO3NyWIKozhRNI4jdQDp7bF74TwAXYA2VxgkwTsXir92t/Ag2JA9gOTreLrjrrKMCGZqvq+69j1fcTbraekfsJP/LEfJzsxMJ0egTNJEb9HgP3JlJUUOxZlD6iBVjPO7q5vsmAAXl2toXDwwNewgEXkZj1EHYDZH6V5oLDVZIxK3HcNPfzVbNxih10k5H6wQmr1eFN+FlD1WeIK/LQitApiNIum9edX7w4V/pSxTNQztEhHOjJhJlPUv0hU8Y1IqhMsDV2EwtsRiJk= 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 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? > > Signed-off-by: Ryan Roberts Other than that, Acked-by: Vlastimil Babka > --- > > ***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;