From patchwork Wed Feb 14 17:01:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 201064 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1374505dyb; Wed, 14 Feb 2024 09:27:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUyadIZ/0xrgzEA/RAHBc19ZrU9EunLRFJZXv6YYw34iO8Ol8cCVbJ9ipJh4l14WkeUQlYkMWCHjqttAcDZS279p8AGQA== X-Google-Smtp-Source: AGHT+IHQVYxlfRlpc+I1gRnhPL8tbvEdPZHVyrQUHFzJiGvma/iAWw6s4bG4lFcgBgdGAe+F4j4y X-Received: by 2002:a92:b749:0:b0:363:9030:16eb with SMTP id c9-20020a92b749000000b00363903016ebmr3471511ilm.5.1707931640672; Wed, 14 Feb 2024 09:27:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707931640; cv=pass; d=google.com; s=arc-20160816; b=uS/yDvGUE+V6fCrkiX9L49PAT06Bhv8q9j1unuyVUtwFsJ0tX0VE/7UNexxtkJkeRv CggS6NiufmbVB5Gy6ptQnD93T+xDC1TByfrf3BsWWGQzzA2grJk+tOXMpiNFZH+M/H8I HTqC8oNaYy/UIGixC33wk6YcfwZ3qC+eBMUCTazUg/UoNAAcBM25ru7MNIK7gTsJH/D6 S/H44zR+EOy54EK0SaLsxexq9v82PknSR7lr6P0uM4pi3EcFUwz3wOR80aRFefnNHV5x id7ysIH08yFCGKvszzLc2z54lDXXWqsQwb6FIC7159KAu4McrSPN11a4Y8OXuhaoILgJ 8uuQ== 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=otvzg4/22HtI6O5djZp/Zahi4Jjn8kHzdRZcCtUTrbM=; b=yyIZm/y28c4KC7qu6Mn+ZYVEE+goOmkJGv8r7ZQMiE3rC7a4YO62U1qlGuqKGaLiLy yMxoYtLjH3tKNgFWL07XXdhR/chV0KQswQVTNjSZ5Abu7Qk1y0XmtDTWtTWkn5S4GRk0 8PgiPUgpaIqrCdziVAxk5QmZU3Zg11jLJmzxsW3X+1XDQ/JMZW9U0qJCbxaIgmMumE7f Z0pAnWwFYxrMVc2ZlAavhNzmhHyOxoKcoGd1for7lMn93NwQBGDjZHXdDX/QVKBEXUFu 5q88fxVFpjv+DAmmJqBIKY9sjiJNfLR5bnE0yL32R1Z06W+D/rS5UC9a6H19J/wYtwSI FPnw==; 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65603-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de X-Forwarded-Encrypted: i=2; AJvYcCUokv3jeyfLNDQzs6xlCYr8wIl5IzhYgWsNsdG02yT4GL4qZ1r/f96sWU4rbZWZFExcJpUwN+o9WTKg5EBjXVly7dEdyA== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id l5-20020a656805000000b005dbe38b2cfdsi4150653pgt.494.2024.02.14.09.27.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 09:27:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65603-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65603-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id EB32BB23EC3 for ; Wed, 14 Feb 2024 17:02:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C6688612C2; Wed, 14 Feb 2024 17:01:03 +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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790896127803545153 X-GMAIL-MSGID: 1790896127803545153 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;