Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp3123512rdb; Tue, 13 Feb 2024 07:32:34 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU4NJ/q8WDHcbvuemVluMmEYIdBLvRM6nmxoTi3QFt6cS3AeCSL2zXDl8XzGtPXFSwdS5sbjzkpqMG0SxX+8dlnClRm9kG+TOy0LTNl/g== X-Google-Smtp-Source: AGHT+IEtID1x6Rjm+KnUXwhCYoXe4Fe4GHP5Gf6kcZiwAFjdXVwIw2qtNd8WKkNE6qx8guafayaS X-Received: by 2002:a05:6102:2744:b0:46d:6b68:4fdf with SMTP id p4-20020a056102274400b0046d6b684fdfmr6690579vsu.16.1707838353910; Tue, 13 Feb 2024 07:32:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707838353; cv=pass; d=google.com; s=arc-20160816; b=PfmymUjp14iGP9B9S6g0ZjunVF+EOxhbiGB+ir60p9Qz1dnQP58hEecgrMDdOkG5sE Sd9oKUeymCNk6fR9dTYtGhnEBK7zp0Rqq3kTgpeSkROgLilfPeqEpRRI49AizGK118o+ s8Ytrc5e3MTHND/kLz+DYIn4+5HN9mTOkyi3oogXk+7BeLEtUJ4O694ESx3xkuxGrCsr o8pQQk3fQjbJBlZl2lpQ1SSDTEV3l9ieNzXE3JYsMlFS7pWCrVY3deG7EihjsVj35YNk KQ2GRbGFawtyp1NbykOo3s/k/b2z5yArosx8DSLWl4Z3ruRtQntqsMhGHb6xQ3iEPYa2 neVA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature:dkim-signature :dkim-signature; bh=Lwad023+VpCp8Em+c31I+OWYiRbkKktBQYYUbNSO2Bg=; fh=JpiInNtw+J6ocjgAXYfsdAXCPBX9mNW4ovzU3VKI8q8=; b=j086i+mOgr59pa4NJhxgyjSOIz8DLkR+ylYjzUlMQCr/tz8GmXb/DnCeSL239I7jlG H6qC6qqktmHVtasByM1upAAaisF6lLsp2UbJZbxV/MJwDPDIhItNljwaE1ezNR8l8OzQ ZWlZOxJwfa/kL3wx5PsDv5H3Gi9DnUv8Ob+V8XnnQd5U3ck4tiOjqxyAsk35TPhmk8g7 ZOf1OUvfIVP/qIi/2vI4jGD6i38ZaG9IHFB4rZwyn4QXfeS72F7ouslPYrFikHI1Khf9 uEfFhPvuh3jggMg+auexrneoKu2+2m1C5pLg8kDF9gTzRVlBiREVWac8LHx+x3vg/MYl myLQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=es4UNiST; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=es4UNiST; dkim=neutral (no key) header.i=@suse.de; 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-63807-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63807-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; AJvYcCXeTGkrgJ2JbZO0u7T3i7spMNmUDyZGzVcfVMexfO28Nv4rH5i03dpvZcvWA2sDU/K0Lp1U+JgdEt0hy3KMkdqXhocGb+/YjU6Nc4pSxw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id v19-20020a056102331300b0046cfbc4871dsi1222000vsc.166.2024.02.13.07.32.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 07:32:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-63807-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=es4UNiST; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=es4UNiST; dkim=neutral (no key) header.i=@suse.de; 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-63807-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63807-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 7FAEC1C21B39 for ; Tue, 13 Feb 2024 15:32:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 184935EE77; Tue, 13 Feb 2024 15:32:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="es4UNiST"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="+mHTXTqZ"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="es4UNiST"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="+mHTXTqZ" Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 A6B535DF3E for ; Tue, 13 Feb 2024 15:32:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707838345; cv=none; b=Kh5yq37AvrzLWqNftrygQRL5aFCtG3L9kJ8GxaiWs9NMjU4fP1klH8UbpXAk8MhaBVYpDI0NMorF29gjxwGqIHoPmMC5WsnmkdxVEcokHLMOpbJ4mjG0b9S+cIhiYrlcPa36qhvXaZ088Br5B7T0lF8/ZVspmx1Cp6IJCq7fUDo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707838345; c=relaxed/simple; bh=Jy8VoZSnqR67yqm7MPHgwgHoYLAdDwVSuN2jp8+Gmis=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BkZ3wKcXQb+ERMXZ3Lozg/LPtT0Luxj185kCkbbCMm7cuBZ6MXJYpnkuoNlrcbeU+CHrfvOjmemhXxMiGRn8zwqSiz+pnQ4K7m/IWboNiMfboriwfQabN+rJxXKR8iU57dmhPFwG7IG88WsCSuZuOxdyxWOn9M9VdTmWS8mrN5A= 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=es4UNiST; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=+mHTXTqZ; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=es4UNiST; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=+mHTXTqZ; arc=none smtp.client-ip=195.135.223.131 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-out2.suse.de (Postfix) with ESMTPS id E424C1FCE2; Tue, 13 Feb 2024 15:32:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707838341; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Lwad023+VpCp8Em+c31I+OWYiRbkKktBQYYUbNSO2Bg=; b=es4UNiSTfoBYDBzKtt5jQvZx0jSaafqS3+MdTQ9QMIP69JC8IMTGc8cf4E31MEQodQbx9E 9i2seiwxuXdntZep8C6D4x2KTFYjAQKBe8OzDC4in0JQbXaaP1bh2pMAWZzxU6Oc6/SD3r ZJembWCzqMx94E4v7Q5J7LU7ZgZPKlc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707838341; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Lwad023+VpCp8Em+c31I+OWYiRbkKktBQYYUbNSO2Bg=; b=+mHTXTqZ1+F6RWZObuc1tTqn3dwoELDnmrt3xxLyML731VQ5NkPkZtL/Tn8rXmyVlITN2x 1J9hS91wKUwmt/CQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707838341; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Lwad023+VpCp8Em+c31I+OWYiRbkKktBQYYUbNSO2Bg=; b=es4UNiSTfoBYDBzKtt5jQvZx0jSaafqS3+MdTQ9QMIP69JC8IMTGc8cf4E31MEQodQbx9E 9i2seiwxuXdntZep8C6D4x2KTFYjAQKBe8OzDC4in0JQbXaaP1bh2pMAWZzxU6Oc6/SD3r ZJembWCzqMx94E4v7Q5J7LU7ZgZPKlc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707838341; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Lwad023+VpCp8Em+c31I+OWYiRbkKktBQYYUbNSO2Bg=; b=+mHTXTqZ1+F6RWZObuc1tTqn3dwoELDnmrt3xxLyML731VQ5NkPkZtL/Tn8rXmyVlITN2x 1J9hS91wKUwmt/CQ== 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 65EAA13A0E; Tue, 13 Feb 2024 15:32:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id NYe6FYWLy2UPfQAAn2gu4w (envelope-from ); Tue, 13 Feb 2024 15:32:21 +0000 Date: Tue, 13 Feb 2024 16:33:30 +0100 From: Oscar Salvador To: Vlastimil Babka Cc: Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Marco Elver , Andrey Konovalov , Alexander Potapenko Subject: Re: [PATCH v8 3/5] mm,page_owner: Display all stacks and their count Message-ID: References: <20240212223029.30769-1-osalvador@suse.de> <20240212223029.30769-4-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [-7.00 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[8]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[linux-foundation.org,vger.kernel.org,kvack.org,suse.com,google.com,gmail.com]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-2.90)[99.57%] X-Spam-Level: X-Spam-Flag: NO X-Spam-Score: -7.00 On Tue, Feb 13, 2024 at 03:25:26PM +0100, Vlastimil Babka wrote: > On 2/12/24 23:30, Oscar Salvador wrote: > > +static int stack_print(struct seq_file *m, void *v) > > +{ > > + char *buf; > > + int ret = 0; > > + struct stack *stack = v; > > + struct stack_record *stack_record = stack->stack_record; > > + > > + if (!stack_record->size || stack_record->size < 0 || > > + refcount_read(&stack_record->count) < 2) > > + return 0; > > + > > + buf = kzalloc(PAGE_SIZE, GFP_KERNEL); > > + > > + ret += stack_trace_snprint(buf, PAGE_SIZE, stack_record->entries, > > + stack_record->size, 0); > > + if (!ret) > > + goto out; > > + > > + scnprintf(buf + ret, PAGE_SIZE - ret, "stack_count: %d\n\n", > > + refcount_read(&stack_record->count)); > > + > > + seq_printf(m, buf); > > + seq_puts(m, "\n\n"); > > +out: > > + kfree(buf); > > Seems rather wasteful to do kzalloc/kfree so you can print into that buffer > first and then print/copy it again using seq_printf. If you give up on using > stack_trace_snprintf() it's not much harder to print the stack directly with > a loop of seq_printf. See e.g. slab_debugfs_show(). Well, I thought about not reinventing the wheel there, but fair enough than performing a kmalloc/free op on every print might be suboptimal. I will try to do ir with seq_printf alone. Thanks -- Oscar Salvador SUSE Labs