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 198E6C4829A for ; Tue, 13 Feb 2024 13:42:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A51D8D0012; Tue, 13 Feb 2024 08:42:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 955A98D0001; Tue, 13 Feb 2024 08:42:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F6738D0012; Tue, 13 Feb 2024 08:42:31 -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 714828D0001 for ; Tue, 13 Feb 2024 08:42:31 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 35065140701 for ; Tue, 13 Feb 2024 13:42:31 +0000 (UTC) X-FDA: 81786895302.15.A67C074 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf12.hostedemail.com (Postfix) with ESMTP id DCCC440016 for ; Tue, 13 Feb 2024 13:42:27 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=GeyQkYiV; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=DN0txwQ1; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Cz85Lar8; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Q1zjxZoX; dmarc=none; spf=pass (imf12.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 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=1707831748; 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=RCSWNMriDs+O5InzTCr4S0mBv91EYSv9PrgxheazaDU=; b=e+skxWy1JOlQUqamfKQegNvkkbOgJlLXV6K4s1d5VDXBGojfvY195CqGGdAhhjtaTIz2u7 LuVPGvEQszSNR/VYhpV5aIj6rEF58wjr74hRYog601Uif56pA17YYoNGBNla/h5Z9FLZ2i ETVUK1I4uvgK+8CDmgpwEMUTCuC03UY= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=GeyQkYiV; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=DN0txwQ1; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Cz85Lar8; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Q1zjxZoX; dmarc=none; spf=pass (imf12.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707831748; a=rsa-sha256; cv=none; b=j3BaHOWYRJJ+RdSLOHimP2IERCSaAukW1Zq/bFvOLDoPaA5tV1JbIJNda903ev2uIuhs+i Bmhm7T3wS685Gv44/bVRmPquiyQcF8aUHOKa8WlrS+tkqCzo+40nB33jw4oBPcXx437Ati qJa5vy/orNAhprfG77qAVt22kEF+swo= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [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-out2.suse.de (Postfix) with ESMTPS id EE16A1FCD8; Tue, 13 Feb 2024 13:42:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1707831746; 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=RCSWNMriDs+O5InzTCr4S0mBv91EYSv9PrgxheazaDU=; b=GeyQkYiV42wF2YZm4VgvxwiIdqvvgDxVNodjzQh4nOTZOvoEIAIZ9NcDT48vkpenIGQ0Lb HX0MjJLUBLdx7HfPEPwxIhy7wHljJURDIgFilUreK0u0IIZwO3Yf5V22YJMsrNWKcBl3Tr 6W7fvIdwvtryMtOlIwkz3C0vhGHNLjM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1707831746; 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=RCSWNMriDs+O5InzTCr4S0mBv91EYSv9PrgxheazaDU=; b=DN0txwQ1jAfARXwEp5OXiacChwK6FI2l35/IjZKTA/Dom5cMeE5nAmOzeKzEh3mQetCpcD X8Saa9zExHZNQfCQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1707831745; 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=RCSWNMriDs+O5InzTCr4S0mBv91EYSv9PrgxheazaDU=; b=Cz85Lar8Rb2NO2ux9p2DHypFt6Hy9ZVHGoAruwBObSWT8Rf6lUiFZ0hZwlgrh4S3fpRLCw FnToGYl9eQRefiBrkru9RsuTFl+X/rCESyC9lIQsXTR/4WaPGgJZeVDmXf/Sz2Z1+PXITn g/l56B9AtIhPme8VHYViDXUxUiHPoOw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1707831745; 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=RCSWNMriDs+O5InzTCr4S0mBv91EYSv9PrgxheazaDU=; b=Q1zjxZoXyeaSSO3z3Ff2CBnQvmYN3Z2xxVZdjlh0J6gmQpYXbr4BwcwQTGRscClww2tbo4 p5ulrklsiea4eZAQ== 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 D9F781370C; Tue, 13 Feb 2024 13:42:25 +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 pQzaNMFxy2WbHAAAD6G6ig (envelope-from ); Tue, 13 Feb 2024 13:42:25 +0000 Message-ID: <8ff46f99-d167-448f-9aae-a634b8aae4d0@suse.cz> Date: Tue, 13 Feb 2024 14:42:25 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v8 2/5] mm,page_owner: Implement the tracking of the stacks count Content-Language: en-US To: Oscar Salvador , Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Marco Elver , Andrey Konovalov , Alexander Potapenko References: <20240212223029.30769-1-osalvador@suse.de> <20240212223029.30769-3-osalvador@suse.de> From: Vlastimil Babka In-Reply-To: <20240212223029.30769-3-osalvador@suse.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Stat-Signature: eq75odj67ws3ushaxz8sb5tus8ufuwra X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: DCCC440016 X-HE-Tag: 1707831747-144203 X-HE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DJlbeaeUeB5RZaGtj/dmOsU5Z1xsCp8lhXFeqCqTeYuM5ra2YEzMKKFuuEmoI1qg007hSNdudm5rkofvdqX2uN3kcP2X3jS8lqyZ3xBzTFgVGNbLNIvZRDw9mIFXTq+hA5BRxKjZb2unc/XQFnea4SU96+QU30zU73LQ/Ln/ztn6tjmo/aUgHURg5pbPG/1uJUuDGnyy6uquJs3vCO6NHwDNQlHJyZlFZ13TLphlaB1wmlU+fXNQ== 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 2/12/24 23:30, Oscar Salvador wrote: > page_owner needs to increment a stack_record refcount when a new allocation > occurs, and decrement it on a free operation. > In order to do that, we need to have a way to get a stack_record from a > handle. > Implement __stack_depot_get_stack_record() which just does that, and make > it public so page_owner can use it. > > Also implement {inc,dec}_stack_record_count() which increments > or decrements on respective allocation and free operations, via > __reset_page_owner() (free operation) and __set_page_owner() (alloc > operation). > > Traversing all stackdepot buckets comes with its own complexity, > plus we would have to implement a way to mark only those stack_records > that were originated from page_owner, as those are the ones we are > interested in. > For that reason, page_owner maintains its own list of stack_records, > because traversing that list is faster than traversing all buckets > while keeping at the same time a low complexity. > inc_stack_record_count() is responsible of adding new stack_records > into the list stack_list. > > Modifications on the list are protected via a spinlock with irqs > disabled, since this code can also be reached from IRQ context. > > Signed-off-by: Oscar Salvador > --- > include/linux/stackdepot.h | 9 +++++ > lib/stackdepot.c | 8 +++++ > mm/page_owner.c | 73 ++++++++++++++++++++++++++++++++++++++ > 3 files changed, 90 insertions(+) > static inline void __set_page_owner_handle(struct page_ext *page_ext, > @@ -199,6 +271,7 @@ noinline void __set_page_owner(struct page *page, unsigned short order, > return; > __set_page_owner_handle(page_ext, handle, order, gfp_mask); > page_ext_put(page_ext); > + inc_stack_record_count(handle); What if this is dummy handle, which means we have recursed in page owner, and we'll by trying to kmalloc() its struct stack and link it to the stack_list because it was returned for the first time? Also failure_handle. Could you pre-create static (not kmalloc) struct stack for these handles with refcount of 0 and insert them to stack_list, all during init_page_owner()? Bonus: no longer treating stack_list == NULL in a special way in add_stack_record_to_list() (although you don't need to handle it extra even now, AFAICS). > } > > void __set_page_owner_migrate_reason(struct page *page, int reason)