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 084A7C28B30 for ; Mon, 10 Mar 2025 12:16:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4372E280006; Mon, 10 Mar 2025 08:16:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E7F2280002; Mon, 10 Mar 2025 08:16:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B008280006; Mon, 10 Mar 2025 08:16:00 -0400 (EDT) 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 F0DDA280002 for ; Mon, 10 Mar 2025 08:15:59 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id AE8D9C0ECD for ; Mon, 10 Mar 2025 12:16:00 +0000 (UTC) X-FDA: 83205538080.30.B627D06 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf19.hostedemail.com (Postfix) with ESMTP id 79C221A0018 for ; Mon, 10 Mar 2025 12:15:58 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=N0IMrrYI; spf=pass (imf19.hostedemail.com: domain of mripard@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=mripard@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741608958; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=KUnX5nhORWvOtCZHvFP20W21X3MBVPy20HvX7ysw3k8=; b=K7WGJBdHmPni6yUW9albpcCQGJ/nsKfBpy1zN3fnj7PQzmaWly+m39xHeBqhGdaf67nrEp C3B6AkGWBgrZS9D7MdONG3QVUe3iFO/aYuxMIPd6ZtUQmTO3SSMkN0ucWcarDisuJto17z CLQCsP2uFIV3aOe1QbpIVAXvkSDgAGA= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=N0IMrrYI; spf=pass (imf19.hostedemail.com: domain of mripard@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=mripard@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741608958; a=rsa-sha256; cv=none; b=trHl20m2fBbVQu7Jf6FdZz/uFiSvV8/x3BGI5jWbJyWPSjESSx0GnDZ9iiUa9p9MC/91Dr JMN3w1ojzUyxFILjIlRiyYTGXYx777Qn1W5zst1xzlW1b4fvY6IuyzvU1twP8x0AtLPBaY GMvf5V7KGF3yL7dPAHa3JB8KBS7YcZ4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 73620A4593B; Mon, 10 Mar 2025 12:10:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC7FEC4CEE5; Mon, 10 Mar 2025 12:15:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741608957; bh=KUnX5nhORWvOtCZHvFP20W21X3MBVPy20HvX7ysw3k8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=N0IMrrYIBu39uSjEkhRFYAdxzoyG002lgHph+TW+mMDW+6bhWEFRi/J0WyRYZTSgz Bx56A/0mLXPy9N9br/OvR+ZZs6YhXlCTfAdKprucWWiYTSbdR21iPhbsbfyvDx10p1 J3Bwy2MhegMZke26K2MTuzJQxIEDMYvcu9oFhwkBocv7tuHzppQIfB0W8TyifDz1QB BrYP2Ckz59F1p/bWPXXPbSGY4X38nrUPNXZ+knrmHLsWwxlgrc2YZl3QWEt2LoHvGW yqC8c1KeMIz645bN1JtPwRVqyvH3op9kz0hUdLGcHpT25lWukDs6hjzF8n3CvYbbwA 0pmpStiii7PUg== Date: Mon, 10 Mar 2025 13:15:54 +0100 From: Maxime Ripard To: Andrew Morton , Marek Szyprowski , Robin Murphy , Sumit Semwal , Christian =?utf-8?B?S8O2bmln?= , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , Maarten Lankhorst , Thomas Zimmermann , David Airlie , Simona Vetter , Tomasz Figa , Mauro Carvalho Chehab Cc: Hans Verkuil , Laurent Pinchart , linux-mm@kvack.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Subject: Re: [PATCH RFC 00/12] dma: Enable dmem cgroup tracking Message-ID: <20250310-aromatic-gaur-of-growth-bd4071@houat> References: <20250310-dmem-cgroups-v1-0-2984c1bc9312@kernel.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ppavg5bsjgk4kjoi" Content-Disposition: inline In-Reply-To: <20250310-dmem-cgroups-v1-0-2984c1bc9312@kernel.org> X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 79C221A0018 X-Stat-Signature: udkcdbcoku5f4o3qkmpqh3enxnnanbo5 X-Rspam-User: X-HE-Tag: 1741608958-828751 X-HE-Meta: U2FsdGVkX19PacQFpFGWshTAjDIhLlZGTGUIE6d0DiJpwicFDQ8f/vO6Zu4ZMCxCcZySg2It596vNFnYIdLZcG6rpTTSULMmaYm1QZaOHGoYp7CYIIqtQpQx844hhCfdrAmp+Ztn5zWjRO9LJGu1SFLr6VENqtOjubo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BWcOrEHwlhAqtNBhAm1Tpf/9wtnxo5vMeSyBrtXqSmjPzrc8Wsl4ynR4Xc/9/d9p9xkAtGlUgN3to0xIy6yU44ZqWhWJyBvePtAp+yN8dtkw6OEiUm7B8cuJk/mOKs3CUrx4iHXrwMFVwZEend6tYGEKFBwXvWphN25NEHpH9RxgscqHXR4P5mHlzI4pJCgPA== 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: --ppavg5bsjgk4kjoi Content-Type: text/plain; protected-headers=v1; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Subject: Re: [PATCH RFC 00/12] dma: Enable dmem cgroup tracking MIME-Version: 1.0 On Mon, Mar 10, 2025 at 01:06:06PM +0100, Maxime Ripard wrote: > Here's preliminary work to enable dmem tracking for heavy users of DMA > allocations on behalf of userspace: v4l2, DRM, and dma-buf heaps. >=20 > It's not really meant for inclusion at the moment, because I really > don't like it that much, and would like to discuss solutions on how to > make it nicer. >=20 > In particular, the dma dmem region accessors don't feel that great to > me. It duplicates the logic to select the proper accessor in > dma_alloc_attrs(), and it looks fragile and potentially buggy to me. >=20 > One solution I tried is to do the accounting in dma_alloc_attrs() > directly, depending on a flag being set, similar to what __GFP_ACCOUNT > is doing. >=20 > It didn't work because dmem initialises a state pointer when charging an > allocation to a region, and expects that state pointer to be passed back > when uncharging. Since dma_alloc_attrs() returns a void pointer to the > allocated buffer, we need to put that state into a higher-level > structure, such as drm_gem_object, or dma_buf. >=20 > Since we can't share the region selection logic, we need to get the > region through some other mean. Another thing I consider was to return > the region as part of the allocated buffer (through struct page or > folio), but those are lost across the calls and dma_alloc_attrs() will > only get a void pointer. So that's not doable without some heavy > rework, if it's a good idea at all. One thing I forgot to mention is that it makes it harder than it could for subsystems that can allocate from multiple allocators (like... all the ones included in this series at least). I only added proper tracking in the backends using dma_alloc_attrs(), but they also support vmalloc. In what region vmalloc allocations should be tracked (if any) is an open-question to me. Similarly, some use dma_alloc_noncontiguous(). Also, I've set the size of the "default" DMA allocation region to U64_MAX, but that's obviously wrong and will break any relative metric. I'm not sure what would be the correct size though. Maxime --ppavg5bsjgk4kjoi Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQRcEzekXsqa64kGDp7j7w1vZxhRxQUCZ87X+QAKCRDj7w1vZxhR xV0SAP9D+a9I6bgS5IRYuQrHA6k0Ra5d7uq+uPWbr3aJfwKx2QD/fe7P1A9AYvBB 2tIKFUcziC1uvL3qqtVJMp4dvAZf0w8= =6LbE -----END PGP SIGNATURE----- --ppavg5bsjgk4kjoi--