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 E1F92CD11C2 for ; Fri, 5 Apr 2024 09:53:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5E3D06B00A6; Fri, 5 Apr 2024 05:53:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 56CA26B00B3; Fri, 5 Apr 2024 05:53:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E5F26B013A; Fri, 5 Apr 2024 05:53:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1E4E16B00A6 for ; Fri, 5 Apr 2024 05:53:35 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 900EF4114E for ; Fri, 5 Apr 2024 09:53:34 +0000 (UTC) X-FDA: 81975015948.29.6B721A6 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf14.hostedemail.com (Postfix) with ESMTP id 5A936100014 for ; Fri, 5 Apr 2024 09:53:31 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=0AXR3Sr9; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=mv3acM2x; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Z0+7rq6f; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=lVccGfCI; dmarc=none; spf=pass (imf14.hostedemail.com: domain of jack@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=jack@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712310811; 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=kxLJbVvPYqfzG83pwvoYNu5wMFXj9ZScFtz4XZeGAUk=; b=o8EPn48TsR4CXNaAJobMpHavG0svDPbYtXtyOU4fADzfda+Zyra+2plzsWLudgrJ6VUuJs vzX9ZQXlg6C5oy7BMc4/XcWRe849wwcpPXf0bZ8PXsoLhQv6EBV+09V5Y6Z39X/WilT6fI 9WDTCtH9zrPPUNr3RS7aNiCoJ0z6d7s= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=0AXR3Sr9; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=mv3acM2x; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Z0+7rq6f; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=lVccGfCI; dmarc=none; spf=pass (imf14.hostedemail.com: domain of jack@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=jack@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712310811; a=rsa-sha256; cv=none; b=jHVAKADQG9gtA26rvHLDd/2RoGa4kluve/yjhh8QYryhDISnsvmCWQtQ7bICuF42YW5PBf wBklhHzSQrQ1F/L+Nhpaz0fFsWOo2aO/ckPM1vdBkcRTOHA6CJf2jpg0gGkkhoBqHNmUTJ 1nNVYhQmD89jORuxvsiTtnX3Ld3lPOw= 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 65BF721A2E; Fri, 5 Apr 2024 09:53:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1712310809; 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=kxLJbVvPYqfzG83pwvoYNu5wMFXj9ZScFtz4XZeGAUk=; b=0AXR3Sr9XfI+c7rTPImw5uCIqUd0/09qhqdILdsZtrOOOTHNThWW8IWO2LavomosrDlGR4 r5zcQ7aU/RB1e9VhO2PeMNtjvZCEdKzHqupTEPNLaoS68JZ7HFWh4OFd1ckPqsmFOlBB7H mcwM4kvxTwfCAYfvPvAMLZZtKWx5vB8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1712310809; 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=kxLJbVvPYqfzG83pwvoYNu5wMFXj9ZScFtz4XZeGAUk=; b=mv3acM2xzaAtD0goPoMaKRbxprQYlRRQRdWeBSj+XgsIgB6XYwFswsOsyAWM2lrdH+uuj0 DSsBpoDlTl2n1rDQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1712310808; 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=kxLJbVvPYqfzG83pwvoYNu5wMFXj9ZScFtz4XZeGAUk=; b=Z0+7rq6fcjYyrOGJFwhu7EPjxeB2YzEP6/GI4QJE77wXmTpoCFc1mE9dE1Bj/PEGY1tu49 ESTilKNYDaC1JrKhdHCnLw44UtjznYqGrEfN+CtNGBPA2Dt9MhQgjmAw2Ok0XXX+qUvUQJ M0o1kG24lT0V2nbGjew3Qb50utPv0T0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1712310808; 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=kxLJbVvPYqfzG83pwvoYNu5wMFXj9ZScFtz4XZeGAUk=; b=lVccGfCILCM4svVbHjo2v2GSsNkbxp/3kUm/GIkdwdP1GGRDcHYdF3Ew32qMBI0ItKMWtc 2n16V0vgVrwCANAQ== 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 5716C139F1; Fri, 5 Apr 2024 09:53:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id 2Ig+FRjKD2a3YAAAn2gu4w (envelope-from ); Fri, 05 Apr 2024 09:53:28 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 0505DA0814; Fri, 5 Apr 2024 11:53:27 +0200 (CEST) Date: Fri, 5 Apr 2024 11:53:27 +0200 From: Jan Kara To: Suren Baghdasaryan Cc: Kent Overstreet , Andrew Morton , Matthew Wilcox , joro@8bytes.org, will@kernel.org, trond.myklebust@hammerspace.com, anna@kernel.org, arnd@arndb.de, herbert@gondor.apana.org.au, davem@davemloft.net, jikos@kernel.org, benjamin.tissoires@redhat.com, tytso@mit.edu, jack@suse.com, dennis@kernel.org, tj@kernel.org, cl@linux.com, jakub@cloudflare.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, vbabka@suse.cz, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, linux-arch@vger.kernel.org, linux-crypto@vger.kernel.org, bpf@vger.kernel.org, linux-input@vger.kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-security-module@vger.kernel.org Subject: Re: [PATCH 1/1] mm: change inlined allocation helpers to account at the call site Message-ID: <20240405095327.ufsimeplwahh6mem@quack3> References: <20240404165404.3805498-1-surenb@google.com> <20240404154150.c25ba3a0b98023c8c1eff3a4@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Queue-Id: 5A936100014 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: cizduchszcwtgr9mgbin55mpijzikc8a X-HE-Tag: 1712310811-115895 X-HE-Meta: U2FsdGVkX1+P73oUXsyqFnZ+UAvf2FNeYTnLuzPzLGkZfIBl2qKOapLzaasMUR1Tzbn5YEBMpiypMlRTC9xSgsH1c3hYFl6Yylaaq3yVb/K73+zyCYaMqaEzjQMtpZlFDD1pppezm3oddUmYR7n1RDNsvJRQDMgqmWucYCsjQU+HpyJggO4Ad79qom4agDRuUpaZn1kGwhJ+wrS6YODn2+cdokNCZFlcUFJ+H2Lmf2GNCn3SkXkBIjAbQ38ib/KpjtXhU0i+VE+PWmfUYe3aCrWOk5hP/cul+Q1GduiKjm2coeIKM8XJ5zfq+x57z/zQbJsWNvwHuFCfLOCGPMq0uaQVOOpiEyuARpWERWeSPTbB7bFrJlCgsVYSbtO8HR6kZgfxinGccD4g+WsfxKx+tG1I9O45nkQP7nCaom10268LcwrLqjiriRSuUg6BP2KI1H1KgnWKjja6L1P3FVkLhLURhQfS1g4QGb+uYAN6fFyzJPtFhJdnsd9EXgEgH9/fRVASZ3NbLe3Tg2gn0SR9ds7PTkVxi74Ctyk/yqPSNBb4D2L/OkLDFn5lzfV7+D8tsEPEM66sfipTCnLv37HSLIeNVVbhfDiA0WwIq6+zX0ub7kX5HQSuh4lD7nqeZDf0j6SKtR8PexhtrQoIrZIZrHANUJMSJcKMbyJWtqHnwrpGXJL0OFv+bUmQI/j4+87fXxtEldPNnIV4REYXJXrAUI6BsxH2MF4F9QUlJqFYsBB9Y91qkM7KuG05mu99WtjFQCanoubgD7obeWJuNdL4vTReomy0tZksaML++zvuBGtf0WtXwGOH85pDsK3IlQpvyBUd5lFyhoOzBwrv4cbJfBpjy4U5j5blulbhJ/uPfg5rzc4BGIIkXNNRqBIUyEKiXdv3PrYgDO+jg7OmNmRPig== 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 Thu 04-04-24 16:16:15, Suren Baghdasaryan wrote: > On Thu, Apr 4, 2024 at 4:01 PM Kent Overstreet > wrote: > > > > On Thu, Apr 04, 2024 at 03:41:50PM -0700, Andrew Morton wrote: > > > On Thu, 4 Apr 2024 18:38:39 -0400 Kent Overstreet wrote: > > > > > > > On Thu, Apr 04, 2024 at 11:33:22PM +0100, Matthew Wilcox wrote: > > > > > On Thu, Apr 04, 2024 at 03:17:43PM -0700, Suren Baghdasaryan wrote: > > > > > > Ironically, checkpatch generates warnings for these type casts: > > > > > > > > > > > > WARNING: unnecessary cast may hide bugs, see > > > > > > http://c-faq.com/malloc/mallocnocast.html > > > > > > #425: FILE: include/linux/dma-fence-chain.h:90: > > > > > > + ((struct dma_fence_chain *)kmalloc(sizeof(struct dma_fence_chain), > > > > > > GFP_KERNEL)) > > > > > > > > > > > > I guess I can safely ignore them in this case (since we cast to the > > > > > > expected type)? > > > > > > > > > > I find ignoring checkpatch to be a solid move 99% of the time. > > > > > > > > > > I really don't like the codetags. This is so much churn, and it could > > > > > all be avoided by just passing in _RET_IP_ or _THIS_IP_ depending on > > > > > whether we wanted to profile this function or its caller. vmalloc > > > > > has done it this way since 2008 (OK, using __builtin_return_address()) > > > > > and lockdep has used _THIS_IP_ / _RET_IP_ since 2006. > > > > > > > > Except you can't. We've been over this; using that approach for tracing > > > > is one thing, using it for actual accounting isn't workable. > > > > > > I missed that. There have been many emails. Please remind us of the > > > reasoning here. > > > > I think it's on the other people claiming 'oh this would be so easy if > > you just do it this other way' to put up some code - or at least more > > than hot takes. > > > > But, since you asked - one of the main goals of this patchset was to be > > fast enough to run in production, and if you do it by return address > > then you've added at minimum a hash table lookup to every allocate and > > free; if you do that, running it in production is completely out of the > > question. > > > > Besides that - the issues with annotating and tracking the correct > > callsite really don't go away, they just shift around a bit. It's true > > that the return address approach would be easier initially, but that's > > not all we're concerned with; we're concerned with making sure > > allocations get accounted to the _correct_ callsite so that we're giving > > numbers that you can trust, and by making things less explicit you make > > that harder. > > > > Additionally: the alloc_hooks() macro is for more than this. It's also > > for more usable fault injection - remember every thread we have where > > people are begging for every allocation to be __GFP_NOFAIL - "oh, error > > paths are hard to test, let's just get rid of them" - never mind that > > actually do have to have error paths - but _per callsite_ selectable > > fault injection will actually make it practical to test memory error > > paths. > > > > And Kees working on stuff that'll make use of the alloc_hooks() macro > > for segregating kmem_caches. > > Yeah, that pretty much summarizes it. Note that we don't have to make > the conversions in this patch and accounting will still work but then > all allocations from different callers will be accounted to the helper > function and that's less useful than accounting at the call site. > It's a sizable churn but the conversions are straight-forward and we > do get accurate, performant and easy to use memory accounting. OK, fair enough. I guess I can live with the allocation macros in jbd2 if type safety is preserved. But please provide a short summary of why we need these macros (e.g. instead of RET_IP approach) in the changelog (or at least a link to some email explaining this if the explanation would get too long). Because I was wondering about the same as Andrew (and yes, this is because I wasn't really following the huge discussion last time). Honza -- Jan Kara SUSE Labs, CR