Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp735171rdb; Thu, 15 Feb 2024 13:58:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWIWCk1xLXrW47+gzW73feB6LefJGNZdJR2HQVrfJcaoo/ljhussvnAo+79fVQXJ2KGKtEHi6CUhabpL5WR9w2seIwHuKtdnb2DBkBqtw== X-Google-Smtp-Source: AGHT+IE5Y5vvBtfnvJBtLQJxUT7qdtodfVoh6dp21deS8Z/FwVBCSb+O+bdHBD2cSd+6yprRkHvg X-Received: by 2002:a05:6a00:d51:b0:6e0:4de8:4896 with SMTP id n17-20020a056a000d5100b006e04de84896mr2535971pfv.8.1708034316318; Thu, 15 Feb 2024 13:58:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708034316; cv=pass; d=google.com; s=arc-20160816; b=Uc9t/LSy+JeM79QawpLqhz0EJS5JUAuGFFT1/gRl6YlDtOUWxCurteVDFts2WJ4gFT TMYeT55nTs/PIwc7ugcT1v676egIHP0Pjl1Lu162NksS2gdIRUZKueKzzRDT8jcMtqVP 8KDYIr7Am4q9DdQ7m46EUVeEP43kQY2eknvobwH8MDz6iG+N1uHf6sWxSekLSyOivOTS h70qZ/ERJEsDvmvsIo73k9d46skINJgKt4BLPp1ziKAJNib6148gMS7X0Mqgq5FQGRiu jhPyGKxzTWZ3LUB2iHfQgRZz/NHw+8UvYqlheA2pT0nDOyl8b/swIFXDA7HhXpOal3Of mUBA== 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=KIFuhxtUimaTB1oGyts61MXj7SFhTQEDfGLXLyf0SXA=; fh=xsvI7l1HeEjfi9GLdU9i1+gXWs6iCG50UXVPhs7pR1M=; b=FIKYI+1MN24A8CkMWiA49KnZWuSx14a6nlJGcPoMF5CN5yrlRvETPzBZ8BRTwnendt 1HVPgSZarI+C1XpytOkRqNLhBButTjdg407zxhOfbgMi7XvSu9oDqa8NhA+PFYqv5nxY TCx3uhY4uw1He4ntMdPCh61ldJVsjO/ySzoRgNpqRW6nuLCvuTX2cQeeIiqag+bmD5/a cvWVO9fSVS6j7DEUv1htBKlMes1QJaZrAUn87wb+L5t+UIV4gWlywsdPu/bBvN7lWauj CgJu2YnkWd/GYybbJb5gpkmGqvSOZDevTr7FHLA+HkuG823Kv8BZJA3jWYSC/iYl9RUa nuXg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=sDIUhMWx; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=sDIUhMWx; 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-67721-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67721-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id bz36-20020a056a02062400b005dc352a5637si1797392pgb.323.2024.02.15.13.58.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 13:58:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67721-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=sDIUhMWx; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=sDIUhMWx; 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-67721-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67721-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 07D5C283FCB for ; Thu, 15 Feb 2024 21:58:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 68588145328; Thu, 15 Feb 2024 21:58:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="sDIUhMWx"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="OtqQfKBg"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="sDIUhMWx"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="OtqQfKBg" 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 82758145322 for ; Thu, 15 Feb 2024 21:58:04 +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=1708034286; cv=none; b=DDsQPx+7KJX9KNlAbaoDLLufhn4H/OuRtoXaY99IL2VxyBLAinBsRT9s+Q+18OTJ7JGz+ImntMeU+9B2sBmpriXmQpe4OWyI5uI+ZTlD5GZ/kO6I+WNxIlXKkiHfwfs/DpzFCedwCAtST5izzAhnkajKfghxfNLbet6x66vPqe0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708034286; c=relaxed/simple; bh=aYpSLX+xXPs03BNbPDOuAzvuIMCtLzwxMokQYULvESA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=URhlMXlP+ChQNjxilerHR94BZE1MpAxkqeaQyibj96W0etp3Qdcmpxdw62T0MgFj1gT8hjjToLbNN0RacHVAMWdr1zv/DtP+Vpv+LoxTzz9woMQjNsZEXiv2pK4mavo/OY8kxQC1rHCqRuO5qqR3bBlGGAr5u0lLQxGC4pGw+AQ= 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=sDIUhMWx; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=OtqQfKBg; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=sDIUhMWx; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=OtqQfKBg; 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 [IPv6:2a07:de40:b281:104: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 B7440220D6; Thu, 15 Feb 2024 21:58:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708034282; 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=KIFuhxtUimaTB1oGyts61MXj7SFhTQEDfGLXLyf0SXA=; b=sDIUhMWxQNqioKstlKsyntTXD4/nZuU7AQ/MJmtBx1nNpvQXfTteQsqntN6z+FqQ+8boS8 5GdXNmtZ9XK4fuC8hLx9vkaTfn+9AdwUYBS++5FXDmYsQy6SH6med4vL3abc4VNF37+GfN oIpF1Lsous6wkOPdOMfoXdy0j6BkDQY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708034282; 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=KIFuhxtUimaTB1oGyts61MXj7SFhTQEDfGLXLyf0SXA=; b=OtqQfKBgL/dfkEFMjon07KDicDuBnypyUM3a+kD80udyLzUBb0lFFtHTyzWZGMLzUyRYYO KabHKm3Z3YGcZEDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708034282; 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=KIFuhxtUimaTB1oGyts61MXj7SFhTQEDfGLXLyf0SXA=; b=sDIUhMWxQNqioKstlKsyntTXD4/nZuU7AQ/MJmtBx1nNpvQXfTteQsqntN6z+FqQ+8boS8 5GdXNmtZ9XK4fuC8hLx9vkaTfn+9AdwUYBS++5FXDmYsQy6SH6med4vL3abc4VNF37+GfN oIpF1Lsous6wkOPdOMfoXdy0j6BkDQY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708034282; 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=KIFuhxtUimaTB1oGyts61MXj7SFhTQEDfGLXLyf0SXA=; b=OtqQfKBgL/dfkEFMjon07KDicDuBnypyUM3a+kD80udyLzUBb0lFFtHTyzWZGMLzUyRYYO KabHKm3Z3YGcZEDA== 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 35FB71346A; Thu, 15 Feb 2024 21:58:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id eMxvCuqIzmXPAQAAn2gu4w (envelope-from ); Thu, 15 Feb 2024 21:58:02 +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 v10 2/7] lib/stackdepot: Move stack_record struct definition into the header Date: Thu, 15 Feb 2024 22:59:02 +0100 Message-ID: <20240215215907.20121-3-osalvador@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240215215907.20121-1-osalvador@suse.de> References: <20240215215907.20121-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 X-Spam-Level: X-Spamd-Bar: / Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=sDIUhMWx; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=OtqQfKBg X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [0.49 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.de:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[9]; NEURAL_HAM_SHORT(-0.20)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; 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:dkim,suse.de:email,suse.cz: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-Score: 0.49 X-Rspamd-Queue-Id: B7440220D6 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 | 43 ---------------------------------- 2 files changed, 47 insertions(+), 43 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..514b8d40ff57 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. */ #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