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 038C6C48BC1 for ; Wed, 14 Feb 2024 17:01:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D67986B00A6; Wed, 14 Feb 2024 12:01:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CEFCF6B00A7; Wed, 14 Feb 2024 12:01:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ACF166B00AA; Wed, 14 Feb 2024 12:01:00 -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 9EFA06B00A6 for ; Wed, 14 Feb 2024 12:01:00 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 647ED120D65 for ; Wed, 14 Feb 2024 17:01:00 +0000 (UTC) X-FDA: 81791024280.02.70E1C76 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf06.hostedemail.com (Postfix) with ESMTP id 13357180038 for ; Wed, 14 Feb 2024 17:00:57 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=OvZdWWwV; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=ZCRlyNPp; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="SicvF/Zp"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Rz4F4l7O; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf06.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707930058; a=rsa-sha256; cv=none; b=w3WMCtm04Znf1iwIWG+w49PcrklJ5V92pQ+lwY//Idb8Y8Vpxt7ehdLm3CT7arx3VTQG7d LQozo5xC7wpKssiFsX7Yiqg3KgfEUV04gnFjzF2CkK9sFAamgv2N3vkYEu3QLy+pecDgKk ajOSlYeEU1Hz2CJ7f6kT6w8mGuUIAeg= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=OvZdWWwV; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=ZCRlyNPp; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="SicvF/Zp"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Rz4F4l7O; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf06.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707930058; 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=JA43trKKhKihZJJ9usT00f7GursSmzhg3mriwKaV7y0=; b=hBU0jCLYYUO9Ip1Ap6XLYZL0Dbug1LWfXfpjvG13GSvZ6s/x3BeyW33j2TLXt0Tj43dBfY Cd0lvkyQQXgl982zgE8jTBLMMS1V/fc3Puwny3TqQxce4YlXZM4wgJPhxeTrQMkdqx6r97 zTzQFcItOLAIiKAKoRQOm7wk4UTtp2I= Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 E039621D01; Wed, 14 Feb 2024 17:00:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707930056; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JA43trKKhKihZJJ9usT00f7GursSmzhg3mriwKaV7y0=; b=OvZdWWwV7yZibleSQHB/hwhj/LiACYirr963CTUvEqVb3T5jJzTJmpg2W7xSR98m5zeMV7 eO3aovW54M5slj50hhrFydjo7qlyVJEok6/kbfVtBlLR2EHX4ovqUaX3rrEfdUDU7+Cei5 O3A1kisZ1+o1xuqtVch6RUJ8VEvoz5k= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707930056; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JA43trKKhKihZJJ9usT00f7GursSmzhg3mriwKaV7y0=; b=ZCRlyNPpofKtvTVeGkz8qfUJlaGaAFfvD5opse8XMjN20CftUZkgVcWFwwgCx3TmOBUSwH Wu30l+t5pBjEsNAA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707930055; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JA43trKKhKihZJJ9usT00f7GursSmzhg3mriwKaV7y0=; b=SicvF/Zpk33wVwxSTyfRK7tlNxMb2qyZMYq3qIi2J2hKZEnP6yZ5DVpq7oIHveC9uZP+vg wHLwe+yLrZQZt0ieY2KUaZiRGe3hqJ4jXf89KEDYXK6y+10VykJGGPrujOrA0mzz9lDi3L 06giLXCKHCkr0/DFMjmdCtAap6J/NZY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707930055; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JA43trKKhKihZJJ9usT00f7GursSmzhg3mriwKaV7y0=; b=Rz4F4l7Ovo8/4T70d83JG746eAdiF4zCQn1/+xsngvnA4gjUJscgUE9SwdzJkhV1NKc5g1 cpp19ge4u6YiZAAA== Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 62E1D13A0B; Wed, 14 Feb 2024 17:00:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id UKuAFcfxzGUfMwAAn2gu4w (envelope-from ); Wed, 14 Feb 2024 17:00:55 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Marco Elver , Andrey Konovalov , Alexander Potapenko , Oscar Salvador Subject: [PATCH v9 2/7] lib/stackdepot: Move stack_record struct definition into the header Date: Wed, 14 Feb 2024 18:01:52 +0100 Message-ID: <20240214170157.17530-3-osalvador@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214170157.17530-1-osalvador@suse.de> References: <20240214170157.17530-1-osalvador@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 13357180038 X-Stat-Signature: whi6py3ieb19ruazwkurxmjgbrug48ot X-HE-Tag: 1707930057-299776 X-HE-Meta: U2FsdGVkX18KQf8MeetOgPR/wx+6O1EtCfL3A8eW41Ip1B455NjnUUdKnIN9PdqYoKGFcyhA/KwtaoTklPpIctDeY0WUll4WZ4YyeQjzED48qLhyOE2QkQGcwxNVffJcWHPtavyABrqJnAvK3TKdUQNi22N1GLJBkl+Le5HmrIM2LmhrQLe0QanNHyaIQjny+xKOkwptTzLd7Y+9+75eP9hsSX0X//Bu+OQzXcVxpKGGirlIpfQmQmEDnhLrT5dlWMVSGoVc14cYb89jbpMRBmsFD1xj93cYfhkCUmbNdlBXZ3grlBIv88/N/AiTCQ6yOqXmAS5A+U70kqf/GB9n5mvIZ6ETuBjmfzAanlarO8IRWeWiACxyXIO3divAHqcmryOSEtySvJeX2Us6KQOmgTUYKJcbLoUuHhxCg3iYxiRHj11a+DWgiE9BPZeTlFKU3Qg3ZqpUzcvyPDavRmYifV34iM2tXlGaKKxsgwxlhyM025tKZJfLD067UxRcQsony5Q+dgVUjxYQAUjQblxoO5R7pEOy+kO+0ZjyH3nLdEByNuXrcPJcD9TEr+eKKMpywO/0NDlSQkoPs/yJC59gRd+DzqAitBE7KW8aXJxcFUJ6+9mbNaeh+qn7gRDd6HSTL6BlOk1UJ6fxzgbVezjK4EV81Qn7Q0j8bSzp4QRpweY2bUGOY+O80Z8fSXQMnPrc00bV077sQFG/fEyJD2K1QT6Lx8jgZi2kHx7fr+cKh9tUOM9BRz8c0gCqA2zyqdvg8y1dObWsFRBVpvjg+9FMlhSYElGhPCTK12uF6e6dUYDDk1xPfVsypB9Ch52xruZ5g+BE7PDs+hG4h7UTQh7/Npo5f7HzZN1rZdUG3e3b2Z9fur4umcs0hgtfwGHy0Y/ZT4umPoPayj3o9sEz/caZwO+bkG5LMpe1QsEU3Zko+fLYD8viHbMZVu4Q3U3p6wdwavwkmu7T6RT9b6HxuI7 lgcesmK4 wgby5uiI5nyvxePHOok8DcezaV0aqpkWFa+3m 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: In order to move the heavy lifting into page_owner code, this one needs to have access to the stack_record structure, which right now sits in lib/stackdepot.c. Move it to the stackdepot.h header so page_owner can access stack_record's struct fields. Signed-off-by: Oscar Salvador Reviewed-by: Marco Elver Reviewed-by: Vlastimil Babka --- include/linux/stackdepot.h | 47 ++++++++++++++++++++++++++++++++++++++ lib/stackdepot.c | 45 +----------------------------------- 2 files changed, 48 insertions(+), 44 deletions(-) diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index adcbb8f23600..c4b5ad57c066 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -30,6 +30,53 @@ typedef u32 depot_stack_handle_t; */ #define STACK_DEPOT_EXTRA_BITS 5 +#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_STACK_ALIGN 4 +#define DEPOT_OFFSET_BITS (DEPOT_POOL_ORDER + PAGE_SHIFT - DEPOT_STACK_ALIGN) +#define DEPOT_POOL_INDEX_BITS (DEPOT_HANDLE_BITS - DEPOT_OFFSET_BITS - \ + STACK_DEPOT_EXTRA_BITS) + +#ifdef CONFIG_STACKDEPOT +/* Compact structure that stores a reference to a stack. */ +union handle_parts { + depot_stack_handle_t handle; + struct { + /* pool_index is offset by 1 */ + u32 pool_index : DEPOT_POOL_INDEX_BITS; + u32 offset : DEPOT_OFFSET_BITS; + u32 extra : STACK_DEPOT_EXTRA_BITS; + }; +}; + +struct stack_record { + struct list_head hash_list; /* Links in the hash table */ + u32 hash; /* Hash in hash table */ + u32 size; /* Number of stored frames */ + union handle_parts handle; /* Constant after initialization */ + refcount_t count; + union { + unsigned long entries[CONFIG_STACKDEPOT_MAX_FRAMES]; /* Frames */ + struct { + /* + * An important invariant of the implementation is to + * only place a stack record onto the freelist iff its + * refcount is zero. Because stack records with a zero + * refcount are never considered as valid, it is safe to + * union @entries and freelist management state below. + * Conversely, as soon as an entry is off the freelist + * and its refcount becomes non-zero, the below must not + * be accessed until being placed back on the freelist. + */ + struct list_head free_list; /* Links in the freelist */ + unsigned long rcu_state; /* RCU cookie */ + }; + }; +}; +#endif + typedef u32 depot_flags_t; /* diff --git a/lib/stackdepot.c b/lib/stackdepot.c index c043a4186bc5..4a661a6777da 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -36,55 +36,12 @@ #include #include -#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_STACK_ALIGN 4 -#define DEPOT_OFFSET_BITS (DEPOT_POOL_ORDER + PAGE_SHIFT - DEPOT_STACK_ALIGN) -#define DEPOT_POOL_INDEX_BITS (DEPOT_HANDLE_BITS - DEPOT_OFFSET_BITS - \ - STACK_DEPOT_EXTRA_BITS) #define DEPOT_POOLS_CAP 8192 -/* The pool_index is offset by 1 so the first record does not have a 0 handle. */ +/* The pool_index is offset by 1 so the first record does not have a 0 handle */ #define DEPOT_MAX_POOLS \ (((1LL << (DEPOT_POOL_INDEX_BITS)) - 1 < DEPOT_POOLS_CAP) ? \ (1LL << (DEPOT_POOL_INDEX_BITS)) - 1 : DEPOT_POOLS_CAP) -/* Compact structure that stores a reference to a stack. */ -union handle_parts { - depot_stack_handle_t handle; - struct { - u32 pool_index : DEPOT_POOL_INDEX_BITS; /* pool_index is offset by 1 */ - u32 offset : DEPOT_OFFSET_BITS; - u32 extra : STACK_DEPOT_EXTRA_BITS; - }; -}; - -struct stack_record { - struct list_head hash_list; /* Links in the hash table */ - u32 hash; /* Hash in hash table */ - u32 size; /* Number of stored frames */ - union handle_parts handle; /* Constant after initialization */ - refcount_t count; - union { - unsigned long entries[CONFIG_STACKDEPOT_MAX_FRAMES]; /* Frames */ - struct { - /* - * An important invariant of the implementation is to - * only place a stack record onto the freelist iff its - * refcount is zero. Because stack records with a zero - * refcount are never considered as valid, it is safe to - * union @entries and freelist management state below. - * Conversely, as soon as an entry is off the freelist - * and its refcount becomes non-zero, the below must not - * be accessed until being placed back on the freelist. - */ - struct list_head free_list; /* Links in the freelist */ - unsigned long rcu_state; /* RCU cookie */ - }; - }; -}; - static bool stack_depot_disabled; static bool __stack_depot_early_init_requested __initdata = IS_ENABLED(CONFIG_STACKDEPOT_ALWAYS_INIT); static bool __stack_depot_early_init_passed __initdata; -- 2.43.0