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 ABDDEC02187 for ; Tue, 14 Jan 2025 18:01:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 41D036B007B; Tue, 14 Jan 2025 13:01:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CD12280012; Tue, 14 Jan 2025 13:01:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2BBB428000C; Tue, 14 Jan 2025 13:01:16 -0500 (EST) 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 0E4666B007B for ; Tue, 14 Jan 2025 13:01:16 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 81C34160882 for ; Tue, 14 Jan 2025 18:01:15 +0000 (UTC) X-FDA: 83006824110.08.1FBA5D7 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf01.hostedemail.com (Postfix) with ESMTP id A277340027 for ; Tue, 14 Jan 2025 18:01:13 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="Khv/Exdn"; spf=pass (imf01.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=1736877673; 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=z6YESmwocWvcRxTlYDRWD8NykHiLIdfk/JE2BG6MODM=; b=oaEf9La6jOED7+L5SYYYW5zDV2vNlay3ETQ8dd2hgdLQHeFdO4hUvCaFm3AEtfT4UJA4Gg GzgQfi3kIJ/4AtybUYxg3CS1nWloCDyAwMa59AOxuJN0JNztIz/qqMtlRqM82WkqmNq1VO +oopSwkC4vRd26b6f/ZmqUR0l5+g6Uk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736877673; a=rsa-sha256; cv=none; b=uupRNYDki34G51WY1MtThBxWTq+CGefJXE9VZzuIcvwd200+aTonY0gOKWxD0Mii5oegYt nwT/G+hIZtyfXcujnBnz+t/r7P9IFLl1TtGvouw9Vo4F7E9I7T9/QbIk+Siajylqfe3HQ6 aaeqguLc7VXhwBS9SKZ6u1rqtZMbEEk= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="Khv/Exdn"; spf=pass (imf01.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 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 77D94A41A63; Tue, 14 Jan 2025 17:59:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E16D0C4CEDD; Tue, 14 Jan 2025 18:01:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736877672; bh=xGnt9QTMfNKV1OFFfTQWPhTcVBgpSWwX7LndHQqnEro=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Khv/ExdnHJ+AEA3NMRhpXuge75QH8lnhotTCn9IUVYpuCYbPb9o5f1yyqbr/8qH7r nfUDhOQyv5OU5Pd5OOE4FxvmKbgQS3T9AbmxrH2HQaQduV554cRtikSool+9Sqaxqw hrNd6Vnp0sgBrtAH0f29KdvonNKmg0GJPvXUTkm4JzCmvIR4oKKYiX5QglQ3CLyw0R NvpYQceTLVan1wgCF5qfCICTIay6uYu9R48WwGb9C4jSjrSvwsHsiMaTaKlGSRtZ3l 3cXQv8tBDyy3qSQwWAxg/SaUMfda+tdO+TAqDW9eBhqo66KsU3iNur2GskbgXea6G1 U7lClyAGCmf9w== Date: Tue, 14 Jan 2025 19:01:09 +0100 From: Maxime Ripard To: Geert Uytterhoeven Cc: Maarten Lankhorst , linux-kernel@vger.kernel.org, intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Tejun Heo , Zefan Li , Johannes Weiner , Andrew Morton , Friedrich Vock , cgroups@vger.kernel.org, linux-mm@kvack.org, Maarten Lankhorst Subject: Re: [PATCH v2.1 1/1] kernel/cgroup: Add "dmem" memory accounting cgroup Message-ID: <20250114-awesome-earthworm-of-camouflage-5bdd5b@houat> References: <20241204134410.1161769-2-dev@lankhorst.se> <20241204143112.1250983-1-dev@lankhorst.se> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha384; protocol="application/pgp-signature"; boundary="6yxrd253xm54q4ba" Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: A277340027 X-Stat-Signature: x1xdey99ddrpdapash35j4y43z4u7bm7 X-Rspam-User: X-HE-Tag: 1736877673-291174 X-HE-Meta: U2FsdGVkX18AOLmwGnQHK0S3HpE8/PJqdYhljssa4jC0JLsFp2mVyXIOPGof4xU/Y8QvdHOhc+MxCLlQAMooZFtUnzQlqCYW63SyuWsRzuz/FVeEUxTPETwVSOsQHpV071YIIIj7fCRWFHtY83ovLBLfneW2wGy/DAAzUe77aiYUol6yiePL9VmDl/+w6dU24ks1IRasaMnjc8Sq9JEvWF78OHI5gqPnVFJPhao9YrnyZN/nmNPjR0TqOrebwhdVgrGqAcPzOUDelbrLWcImKU4tcc518PZeuLMW7iulqHUcq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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: --6yxrd253xm54q4ba Content-Type: text/plain; protected-headers=v1; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Subject: Re: [PATCH v2.1 1/1] kernel/cgroup: Add "dmem" memory accounting cgroup MIME-Version: 1.0 Hi Geert, On Tue, Jan 14, 2025 at 11:16:43AM +0100, Geert Uytterhoeven wrote: > Hi Maarten, >=20 > On Wed, Dec 4, 2024 at 3:32=E2=80=AFPM Maarten Lankhorst wrote: > > This code is based on the RDMA and misc cgroup initially, but now > > uses page_counter. It uses the same min/low/max semantics as the memory > > cgroup as a result. > > > > There's a small mismatch as TTM uses u64, and page_counter long pages. > > In practice it's not a problem. 32-bits systems don't really come with > > >=3D4GB cards and as long as we're consistently wrong with units, it's > > fine. The device page size may not be in the same units as kernel page > > size, and each region might also have a different page size (VRAM vs GA= RT > > for example). > > > > The interface is simple: > > - Call dmem_cgroup_register_region() > > - Use dmem_cgroup_try_charge to check if you can allocate a chunk of me= mory, > > use dmem_cgroup__uncharge when freeing it. This may return an error c= ode, > > or -EAGAIN when the cgroup limit is reached. In that case a reference > > to the limiting pool is returned. > > - The limiting cs can be used as compare function for > > dmem_cgroup_state_evict_valuable. > > - After having evicted enough, drop reference to limiting cs with > > dmem_cgroup_pool_state_put. > > > > This API allows you to limit device resources with cgroups. > > You can see the supported cards in /sys/fs/cgroup/dmem.capacity > > You need to echo +dmem to cgroup.subtree_control, and then you can > > partition device memory. > > > > Co-developed-by: Friedrich Vock > > Signed-off-by: Friedrich Vock > > Co-developed-by: Maxime Ripard > > Signed-off-by: Maxime Ripard > > Signed-off-by: Maarten Lankhorst >=20 > Thanks for your patch, which is now commit b168ed458ddecc17 > ("kernel/cgroup: Add "dmem" memory accounting cgroup") in drm/drm-next. >=20 > > --- a/init/Kconfig > > +++ b/init/Kconfig > > @@ -1128,6 +1128,7 @@ config CGROUP_PIDS > > > > config CGROUP_RDMA > > bool "RDMA controller" > > + select PAGE_COUNTER >=20 > This change looks unrelated? >=20 > Oh, reading your response to the build error, this should have been below? Indeed, good catch. > > help > > Provides enforcement of RDMA resources defined by IB stack. > > It is fairly easy for consumers to exhaust RDMA resources, wh= ich > > @@ -1136,6 +1137,15 @@ config CGROUP_RDMA > > Attaching processes with active RDMA resources to the cgroup > > hierarchy is allowed even if can cross the hierarchy's limit. > > > > +config CGROUP_DMEM > > + bool "Device memory controller (DMEM)" > > + help > > + The DMEM controller allows compatible devices to restrict dev= ice > > + memory usage based on the cgroup hierarchy. > > + > > + As an example, it allows you to restrict VRAM usage for appli= cations > > + in the DRM subsystem. > > + >=20 > Do you envision other users than DRM? > Perhaps this should depend on DRM for now? dma-buf heaps and v4l2 support are in progress right now. Maxime --6yxrd253xm54q4ba Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iJUEABMJAB0WIQTkHFbLp4ejekA/qfgnX84Zoj2+dgUCZ4amZQAKCRAnX84Zoj2+ dgjDAX0W4SqGxbW7Q7IklK0znNvkntNHh6K1lujA0gPteaqWh799ZIBjzxh/cgs0 P3bf5LEBgMEug4QbiLG8y8uDai/9qY2bChSMIdsxk2qfhycBLAechk/7OoRr7az/ 5VlQrByP9Q== =mx8q -----END PGP SIGNATURE----- --6yxrd253xm54q4ba--