Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp711212lqp; Fri, 5 Apr 2024 06:47:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWZfmxKv86f/Se0Yq9jQGqJqob/giIFcby1B1VjRFyTQox7QZ09kSQJi6acuzlkrl5VLadNAbXy43xTCeBNj2GW/PM4rqKIMq3A8dPW/g== X-Google-Smtp-Source: AGHT+IECy1/OIj2rNjT2oqirJnlJK0JSdxjNLYohoBnJHttkOMt3sp+/oSdFVLp8Cf6wCVzDdrDz X-Received: by 2002:a05:6870:8202:b0:22e:b736:786d with SMTP id n2-20020a056870820200b0022eb736786dmr1723253oae.31.1712324863689; Fri, 05 Apr 2024 06:47:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712324863; cv=pass; d=google.com; s=arc-20160816; b=jcgkNa3rLU9r9pyfykZY7DeeUbF4NGsr90m57pn4dW6Z61nvPvyayaM7Tfo6H91YB1 IWl8eAlwZ/4rtkC66KzaumB2p4kmLARXrmIAfdn3cJ17vCak3CtFk48iZ3roz+4pHg/l unxEpCwm8iZkd6g37/WWexgEXrcx0iODHJtN42E7qBkmhd3GGn0XHwccIwcPx2KWaLdN OhPmuF2bmlG7uz0YG3s+oEnGZu6lRaBhUQ2wjQBZ+Q/WIgiCtQQpcKHm8Zrd0uRQ/sIz MIXmvZynDjcTMBEmQk1wbSib5Q9hgfjlbF6a1sn9be6X1UzQRo3F3B2E1oyahpphInVN 6dbg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=RDkodhxPHjCRcYuHL8QJdxmj/UyX4mSAQyu360+3BOI=; fh=vxLR1HO0Lr6dyoPdkvX+C+ajBXGfU0nn+y9CrR6BKC8=; b=ly6n5+od2GFyDTIOx69nnkf04XHHL5uz2IRTHlmUJpyotQghL92iP/JJV3HXfQK4Hp qPuiPD8/+6FAHVWy62Ywc7KsOjH2HaVjqcY01me8sBiSG2yvQCBLneFXsEna/oCicpxw laEb+nP/7wHMJZNP+0Zqu8UeXdx0/2s8Q34ZSgktP7cjULf2oxc3BEifbchLOpqtUc9i bz68eyGdpN4VRmaE79WB1cFZ5S8CKiDIhWO/zsrn59m8SAqmia+oTTePQIwlspjNa6xi 1F6BqgydXStQsRbLmszJZOKx3NEZn2oMeLZk0jLnYZ0yLGu9Oo4XvdWQrWQPoE7ArNGH 2jig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=VUbNjwdS; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-nfs+bounces-2666-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-nfs+bounces-2666-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id k32-20020a63ff20000000b005f034b4f7e0si1399293pgi.446.2024.04.05.06.47.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 06:47:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs+bounces-2666-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=@google.com header.s=20230601 header.b=VUbNjwdS; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-nfs+bounces-2666-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-nfs+bounces-2666-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 4EEDB284B9A for ; Fri, 5 Apr 2024 13:47:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B575016D9C9; Fri, 5 Apr 2024 13:47:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="VUbNjwdS" X-Original-To: linux-nfs@vger.kernel.org Received: from mail-yb1-f172.google.com (mail-yb1-f172.google.com [209.85.219.172]) (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 5836116D9A0 for ; Fri, 5 Apr 2024 13:47:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712324854; cv=none; b=ZBxpDOL0taiTuibv/DIgrleyEEZTAjMQ6vSgLlJDckYvT/Hi9X0vhhZ8XnbgmyTCXCAlzM+Cj8Of73ICSK4wIiLnaUWqX5i4gOlA7d9DnXKDXkx1fAAFyoUX2atIUnr1vb8ztruS5iu7g0+aSs0h/cxz1V+aF9jI2Oll3eHCnwg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712324854; c=relaxed/simple; bh=eHFqbIhCRlO8+eg0bsye3/gnRyfWteI0TtMg8FRqQjs=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=bCa7kU3dkj85iLCSZytNhAjg79j6ZtPchHC9lKRAbdZjQAkO+i8WFo4zoH7BWEAwqtN8NalgFBozxTtduv/KzkqZVeJ9ISMIbcZh6NqTNji4Q0VhHC9WLcDR18IMP123tITWCSP7jZ1AUr5R/DogjWxWkIWKqRruPgkUS4KT/+s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=VUbNjwdS; arc=none smtp.client-ip=209.85.219.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-dcc84ae94c1so2362622276.1 for ; Fri, 05 Apr 2024 06:47:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712324851; x=1712929651; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=RDkodhxPHjCRcYuHL8QJdxmj/UyX4mSAQyu360+3BOI=; b=VUbNjwdSHuFql+0qqSA6ulfb92n/na/cVGs9xcWDSze4ziRSFHPv67sZK5aQUDeQsb 3TuuRG5ceBVzSdQWK6ylm141wxF/YJSyp+7F71VKNBSU9GB0yjWMTL1R9JapJSI8Gv9m I1YxyWBxwMy9EqXxX8R1RPb6+AcZul2LuqH7ba1Yx/NabSMQyem5R3CkTZ1EEvowdeHa isOarVU/YLDKbyYy/URONSvQu5EcZOyIrMIBbLa5ZzP8Yt3T81nTcDtmT3TWN3wm7gb6 4nPV0rPArcITIyCy945cZX7BGr6gY1nwBvjL1nNuQ7LjG+tRrC0uBdBtWdveKzp7pCJ0 OsiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712324851; x=1712929651; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RDkodhxPHjCRcYuHL8QJdxmj/UyX4mSAQyu360+3BOI=; b=WIUKhJUhoKYidUO2cKTlU3jPFKdbqFVX7sXAcCRha5ltLpB52WTH+ibOdPJmIhavzr 0QP5k8m9MuInKPbiiP5YONdisgoIfriIw+xHIndhMDFydzTnmI2FDhCIItSm63n5Fgla zYwvZf6UvGHaPXyY/89gmwDIBW16dghQxWg2A3552thKpyPnSPSfxonLR7OspmzhJccL dYbOVxRvLiglFhN1FV220ICXe+JQrb0+uWEwFZhxrk0u8MTtGIPMa+nhLvMLlF1pvzVK qTZePcaPkOeAq1sLpqQ86/F1obCTxaSMA9nyCz2zUFjhgCrVWkCCi78+8GlHGVEye0am pyYg== X-Forwarded-Encrypted: i=1; AJvYcCU1xboGAE2lpy1Rut6XmURxoFfXRG5C0lVwnMya+FPk0wdyE3IT3e/24CKpJsL35wzbSuiBS9O0xHpVxWUYvl5xIn4W+NlgoCaF X-Gm-Message-State: AOJu0YwoCB1yAlgjr7xlJWFgd7tt/5QFTjjjLX9o9k0yT+1Kod204umC 7G4IfYe/zJ4acQX3Y/jYn6sBYr6EbkOcmckPehTM1fZyP3g9UcKDx3673jjOu3FlKxgnUCh0Mal Vf71H4IYXMOvODIwjPxwz/Fok34TSNmLbBeZ6 X-Received: by 2002:a25:e30e:0:b0:dd0:2076:4706 with SMTP id z14-20020a25e30e000000b00dd020764706mr1142654ybd.31.1712324850962; Fri, 05 Apr 2024 06:47:30 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240404165404.3805498-1-surenb@google.com> <20240404154150.c25ba3a0b98023c8c1eff3a4@linux-foundation.org> <20240405095327.ufsimeplwahh6mem@quack3> In-Reply-To: <20240405095327.ufsimeplwahh6mem@quack3> From: Suren Baghdasaryan Date: Fri, 5 Apr 2024 06:47:17 -0700 Message-ID: Subject: Re: [PATCH 1/1] mm: change inlined allocation helpers to account at the call site To: Jan Kara 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Apr 5, 2024 at 2:53=E2=80=AFAM Jan Kara wrote: > > On Thu 04-04-24 16:16:15, Suren Baghdasaryan wrote: > > On Thu, Apr 4, 2024 at 4:01=E2=80=AFPM 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 wr= ote: > > > > > > > Ironically, checkpatch generates warnings for these type cast= s: > > > > > > > > > > > > > > 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 i= t could > > > > > > all be avoided by just passing in _RET_IP_ or _THIS_IP_ dependi= ng on > > > > > > whether we wanted to profile this function or its caller. vmal= loc > > > > > > has done it this way since 2008 (OK, using __builtin_return_add= ress()) > > > > > > and lockdep has used _THIS_IP_ / _RET_IP_ since 2006. > > > > > > > > > > Except you can't. We've been over this; using that approach for t= racing > > > > > is one thing, using it for actual accounting isn't workable. > > > > > > > > I missed that. There have been many emails. Please remind us of t= he > > > > reasoning here. > > > > > > I think it's on the other people claiming 'oh this would be so easy i= f > > > 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 an= d > > > free; if you do that, running it in production is completely out of t= he > > > 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 tru= e > > > 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 giv= ing > > > numbers that you can trust, and by making things less explicit you ma= ke > > > that harder. > > > > > > Additionally: the alloc_hooks() macro is for more than this. It's als= o > > > for more usable fault injection - remember every thread we have where > > > people are begging for every allocation to be __GFP_NOFAIL - "oh, err= or > > > 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 ne= ed > 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 t= oo > 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). Ack. I'll write up the explanation or if there is a good one already in our previous discussion will add a link to it. Thanks! > > Honza > -- > Jan Kara > SUSE Labs, CR