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 1DD99C4332F for ; Thu, 3 Nov 2022 16:15:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 96D886B0072; Thu, 3 Nov 2022 12:15:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F5DC6B0073; Thu, 3 Nov 2022 12:15:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7BDFC6B0074; Thu, 3 Nov 2022 12:15:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 6862B6B0072 for ; Thu, 3 Nov 2022 12:15:54 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 160FF1A14D1 for ; Thu, 3 Nov 2022 16:15:54 +0000 (UTC) X-FDA: 80092632228.07.B3DF365 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf15.hostedemail.com (Postfix) with ESMTP id 2D5DDA000C for ; Thu, 3 Nov 2022 16:15:52 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 99AD91F385; Thu, 3 Nov 2022 16:15:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1667492151; 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=ZOK1SaMwXOlrr+TCwRQHAO97zFVkBbjRiC2eDpxq0LY=; b=zLBk+t5BD46kD3mceZHnuszvYf1SMhHGYgCD6GcvPN6Bw8f3S/LBcT3D3RKDGRxu+uujkJ DpeV30k+qkh1MRGi8jU/L/6lGfkUU/5X7V3VVkImNutkzSt5j4hbhYfCSyFBO2sr+gKxbn 1EdV9zPDBxajRzmhfG7VYZ1TzLBiEBg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1667492151; 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=ZOK1SaMwXOlrr+TCwRQHAO97zFVkBbjRiC2eDpxq0LY=; b=BRM0tyepyNwrzGxX2wr9UTdxBE2XeCqntmsu+WUE+BlfQYq2Q5va+zz8BYQwPcqzjfVRYK q+OofWREa7uubZDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 62D9C13480; Thu, 3 Nov 2022 16:15:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id UfhsFzfpY2MQPQAAMHmgww (envelope-from ); Thu, 03 Nov 2022 16:15:51 +0000 Message-ID: <4c7e3762-ebc3-c2cc-7ea5-71d4ea97e327@suse.cz> Date: Thu, 3 Nov 2022 17:15:51 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.0 Subject: Re: [PATCH v2 2/2] treewide: Add the __GFP_PACKED flag to several non-DMA kmalloc() allocations Content-Language: en-US To: Catalin Marinas , Greg Kroah-Hartman Cc: Linus Torvalds , Arnd Bergmann , Will Deacon , Marc Zyngier , Andrew Morton , Herbert Xu , Ard Biesheuvel , Christoph Hellwig , Isaac Manjarres , Saravana Kannan , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, Feng Tang References: <20221025205247.3264568-1-catalin.marinas@arm.com> <20221025205247.3264568-3-catalin.marinas@arm.com> From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667492153; a=rsa-sha256; cv=none; b=GCafwzBtBwXZlGfral/GG5XchUDnaDggUzMyBCvyUQb0s4kgojZvhPFzz1e91iV1L9hIEO 3IJMcMTqQZaQGSYWq4E3uANqLyX3v/CN2VdU8pV/m51GS58vDE1US44IgdNwbN21WHn08M OK9o6ddOkBQ9evUQCzfVB/FU+ua9X1w= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=zLBk+t5B; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=BRM0tyep; dmarc=none; spf=pass (imf15.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 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=1667492153; 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=ZOK1SaMwXOlrr+TCwRQHAO97zFVkBbjRiC2eDpxq0LY=; b=Ld88XmWusAqFKDhSH2Xyqd6tBRiWInngsZROuK/t5f+1rHoi/sbJpBcoV4CujaWDW5kb5h wIIfHvx1YpvfiBIxrEbgm/CKlCeDwvKmc/iI40nszsjlfOGNyLMlPcohd+6OjBnt82ju8l 5ZA+QexDdG5enK9wN68/5g/yFHB8ktw= X-Stat-Signature: 1nsc45odpia8pubkj8fy3nei3cja65ta X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 2D5DDA000C X-Rspam-User: Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=zLBk+t5B; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=BRM0tyep; dmarc=none; spf=pass (imf15.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-HE-Tag: 1667492152-372685 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: On 10/26/22 11:48, Catalin Marinas wrote: >> > diff --git a/lib/kobject.c b/lib/kobject.c >> > index a0b2dbfcfa23..2c4acb36925d 100644 >> > --- a/lib/kobject.c >> > +++ b/lib/kobject.c >> > @@ -144,7 +144,7 @@ char *kobject_get_path(struct kobject *kobj, gfp_t gfp_mask) >> > len = get_kobj_path_length(kobj); >> > if (len == 0) >> > return NULL; >> > - path = kzalloc(len, gfp_mask); >> > + path = kzalloc(len, gfp_mask | __GFP_PACKED); >> >> This might not be small, and it's going to be very very short-lived >> (within a single function call), why does it need to be allocated this >> way? > > Regarding short-lived objects, you are right, they won't affect > slabinfo. My ftrace-fu is not great, I only looked at the allocation > hits and they keep adding up without counting how many are > freed. So maybe we need tracing free() as well but not always easy to > match against the allocation point and infer how many live objects there > are. BTW, since 6.1-rc1 we have a new way with slub_debug to determine how much memory is wasted, thanks to commit 6edf2576a6cc ("mm/slub: enable debugging memory wasting of kmalloc") by Feng Tang. You need to boot the kernel with parameter such as: slub_debug=U,kmalloc-64,kmalloc-128,kmalloc-192,kmalloc-256 (or just slub_debug=U,kmalloc-* for all sizes, but I guess you are interested mainly in those that are affected by DMA alignment) Note it does have some alloc/free CPU overhead and memory overhead, so not intended for normal production. Then you can check e.g. cat /sys/kernel/debug/slab/kmalloc-128/alloc_traces | head -n 50 77 set_kthread_struct+0x60/0x100 waste=1232/16 age=19492/31067/32465 pid=2 cpus=0-3 __kmem_cache_alloc_node+0x102/0x340 kmalloc_trace+0x26/0xa0 set_kthread_struct+0x60/0x100 copy_process+0x1903/0x2ee0 kernel_clone+0xf4/0x4f0 kernel_thread+0xae/0xe0 kthreadd+0x491/0x500 ret_from_fork+0x22/0x30 which tells you there are currently 77 live allocations with this exact stack trace. The new information in 6.1 is the "waste=1232/16" which means these allocations waste 16 bytes each due to rounding up to the kmalloc cache size, or 1232 bytes in total (16*77). This should help finding the prominent sources of waste.