Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp706891rdh; Wed, 14 Feb 2024 09:02:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUSTohZmEYUHctJYR4d80VtrxlyqEFGlKfmHYUAlS1q815w6OJWBa02xYQuF2ko1iutIt7l/Lz+uguJPdGiM8Gh1GrvQW79sy2cChsgAA== X-Google-Smtp-Source: AGHT+IE1ZAqxSW3o+LKK/4LLAqnjpeQTW4Ebz0eYcE8UFor58YCMTDyEr9pVwF+U3F6Nt9iREppn X-Received: by 2002:ac2:596f:0:b0:511:3bd4:6a97 with SMTP id h15-20020ac2596f000000b005113bd46a97mr2231301lfp.7.1707930125606; Wed, 14 Feb 2024 09:02:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707930125; cv=pass; d=google.com; s=arc-20160816; b=imeRing/xtRmyBmmZc1vlBLGSSD5BFHXq6mTEyGNjiu2IKtS7niCTK1rBll88b8/C+ Y4NE23TK24gVU/PddL0+88s/WqPLNrC+bmC2Egnsf84raTjZBjbIzGr/JG3SywRRRK8k LG4F8EeNEBv3pIwtrU57Mx/RO32xAC0mV0KytmR8WlYLewPRBOJ/mWT9rPQP+Qhs/wHj J2reI3ZbSVrSlrrMj0xhhjAlBTKCSM3Zdbw7sOb7kEZoYrguF6ZY7syExZWFb4Y1d4Kg 7mjga0rYbZWN11klS+89bnslNCrTVxNvp3ApZ5xYdlHiNWK27INI0fM6WfW8m00Ikj8o VGfw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-signature :dkim-signature:dkim-signature; bh=JA43trKKhKihZJJ9usT00f7GursSmzhg3mriwKaV7y0=; fh=PylW3d1/vgYE1hZNvndKTLBlxLDlcOIjB8VmhI1wViw=; b=dFlqs7HBqMEvv4qiKhfc4H1UW3YFitS/S4Lc1lgTT5giViVbVrDcKQPUmDZell4VLr dyAf4zyQrQGQFnmKRkw6pCLO/zieyFU/kLeeHyGBKX5iXjfJhyrmeu6fIY/xul8JeNvZ l8fKVUbx2xK5fovmU8+fnV8VSSWpYwsosn+eFe1s2aiGw8nsI944G6N2yVkabXdZmafK bT2hb2//HLFQ0b6Wz1J2Bq/90w6oDTP6QhohMz+Kb7Zm9q6Oxu+Uid36bMcm3bzIgPIA GijK5LmlJQED0GCyt2hxmPmlfV1Mi38GQGB7AeWby3KRjlr8xL2/tK6u2dmoqGy6i3qb O1rA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=OvZdWWwV; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b="SicvF/Zp"; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-65603-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65603-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de X-Forwarded-Encrypted: i=2; AJvYcCXr5mIX2AzAg0nGISaGxwKPRRQ34wkSmHaEMY3iJukg0iGpmBsk92ZmK1Qe97UU3NYShtGYKVkImrGxIL13r7vBt0FSberV73sH/YVFSA== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id gv18-20020a170906f11200b00a3cf761a423si2007292ejb.855.2024.02.14.09.02.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 09:02:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65603-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=OvZdWWwV; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b="SicvF/Zp"; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-65603-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65603-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 9ED911F23BC1 for ; Wed, 14 Feb 2024 17:01:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E742060DEC; Wed, 14 Feb 2024 17:01:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="OvZdWWwV"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="ZCRlyNPp"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="SicvF/Zp"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Rz4F4l7O" Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC1D060864 for ; Wed, 14 Feb 2024 17:00:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707930059; cv=none; b=HOJCMFmcuzoMuBk9kCemf9ctwv7KyvKLMAUEekTW7d5GE+iMrvMrViW1rj8BA18NYxKuTS2MTxd5hEPYkfY4N6NDQEb8UrX3+UZDUyqlfw5EgvmCKgOJHqLbsiIJe43B1Cl+rDPqd4HsbRfnCGkFK1NTbLJoqJi1oTJQElRdBPk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707930059; c=relaxed/simple; bh=GLl1mBIBBbFhtl/JwEapHFBxfExDSz6/r73/Ef/EcG8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=svtn+0Swo8ef0TDK9mu6m6e3ozSt8zoxOxauq7uC2TIcb0gP+gAT61RViCbn2AVFaLSNGDL1fw727EAXuIV4qPWRtkc3vWsJauDWre/mUodIBEif075kkR7kZtPggAazbCaH/tNARXYR2TYDYJZCJsJ0nJU2bQ7m1q0ImqSAqPI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=OvZdWWwV; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=ZCRlyNPp; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=SicvF/Zp; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Rz4F4l7O; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [1.90 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; RCPT_COUNT_SEVEN(0.00)[9]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FREEMAIL_CC(0.00)[vger.kernel.org,kvack.org,suse.com,suse.cz,google.com,gmail.com,suse.de]; RCVD_TLS_ALL(0.00)[] X-Spam-Level: * X-Spam-Score: 1.90 X-Spam-Flag: NO 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