From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C35040E8EF for ; Fri, 5 Jun 2026 15:42:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780674151; cv=none; b=A0Vvt1JfFV78o6t35822Vp08S+N+P+cxQCB4INkTdWr48bLxVhLtc/HpjtENJzJLnZ5yjLxXM4AJmLEyqNZG0Nmxo/fethD17g5qCFCfbLgZa1qjp72uYp9Hf1nGJP0NXvBUkRBaNdKxqqp91POEM/5u8VbXw2lUaiwHR59UVX0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780674151; c=relaxed/simple; bh=hNXMOCusmTiv9t8jBH97402lT0OFK1tPV6LcYWEcI0o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Qr9BTRFGbrKnP2tuwxLili859Et9oh7RblQ2A+FJ0EF1Y1wt0/1YONge7Q7kJIkj8BP4K29rXFgu+th3UAGLG6to3O1gdxSXgOzJiQdtPcI0quhJVi7rz+ku7yDERKrr8xV8fnVnHbDzBsYBgPd6XXxlNcUakX8Ge7RAsgEiLr4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=dNxqloee; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Q+HEcTwM; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dNxqloee"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Q+HEcTwM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780674149; h=from:from: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; bh=ykStheHWzMecvQlC8/orrpWH+CEGzXq9KPPg3CU9BFw=; b=dNxqloeek2jOdHxXMtB4u0Ij9oD662ickFNoMs74YXVK1ZWdr9qlE3V6VZq6mcuPo3ccAt l8RXivRVHfB0hknD86Gk4fkCxtNKcqkM5ZzfaEOEMnqcJxCsZTTew/z33e00RsdIr70wfg f9nw7il+Kws5OMSSc7U5tMqGUXb8gD0= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-295-7sd4bQW7NyW8oNt3Q0kuYA-1; Fri, 05 Jun 2026 11:42:28 -0400 X-MC-Unique: 7sd4bQW7NyW8oNt3Q0kuYA-1 X-Mimecast-MFC-AGG-ID: 7sd4bQW7NyW8oNt3Q0kuYA_1780674147 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-91574ad681eso227512785a.0 for ; Fri, 05 Jun 2026 08:42:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780674147; x=1781278947; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=ykStheHWzMecvQlC8/orrpWH+CEGzXq9KPPg3CU9BFw=; b=Q+HEcTwMSZGwipJDNevrJmq+OjbpOrsA78SyPVjkkw0DSCG8VzY1cUwbluO/8cwhj4 lHmCtWuNpbTMFUW0OUS6joQeefT8aUj+cBM1QyhcZOOtvDMLJ5EpJniqwvWDRxEYmeUP +/0mwUgzndc08H3FeNvMAySqcrNSdbKksb7Th9cf9raFl8AxZpsrgkmSM2kKhB4BsN8j hvMLNGFlWACS7hIR3NKbec8/3HeLFKEnBShmJhsenkIMP/Elb/dvnH6mqQzIDnIeMCj/ lldKC4ABYi2Nr6hlaQl2Ffle1J0JuGLUmQcEdsvpW1GhaY9Sp1gzDtx3FbmUPlX8ldLp JJHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780674147; x=1781278947; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ykStheHWzMecvQlC8/orrpWH+CEGzXq9KPPg3CU9BFw=; b=CsWBnqavKtUmzuPLzYbK+fdu3nSYI5EL2sfesHmQ514QysPyqHjCqFYAVt0YFMqhq7 L5ZUZJHQ07pSN0H5C/VI7FwpSNDlT2awrlets6x9iL/NeEWjkFxjvlQxd/0z5FWPitbH B2d9g1kvRowQc5w2FEb1qOerXpzIS8oYMnphIRyngKMbxmvqMFidouPAEaX0U3hsl/Fe RE0VgaNy+c+E+WzJ5yQsmANsyTWt366rdPJaYCkf+nz1WJnz0aA3d19k3OwCh1MQwQcb nuC3m7OwoJcHeyF6vyHVdqjfy1gqtO/RFCKPjidBAzb3VNy6pLt6cDEQqdcPU9kc5tqH to6Q== X-Forwarded-Encrypted: i=1; AFNElJ/uX6CJYVLZGeNoXp9AGqY8eYXAlZ9CRH93HRpFBPovg7D3JGX8eSX2Funnb8MjUZDCRbOdwnbmeLCk384=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/i4NU0/kZI3cYoC96LBAhml5pFZKZq8H/pbddMy0OGHox37Ie 9xb68NS6u9YcsXCyG4AzZF2vwtYO3h1AxR5kyo20I0++3khMF6BHr4scKlV23Yi89sQ2P6Qd5HN 5afUoCxbImKBvG/OZYQxp5JFbXGrSx088jq3Lk4+Z+QxbTdI3XuHCZSEuNOAMgqqPWA== X-Gm-Gg: Acq92OFU1GyZc3VfvkSQkkJoLF9gzTOxJngoOlT39LDx85nE9731imG9FBctmUB+epV /2lLCNmrSybJa2oK1tlm1CmOJ3bMpskyw2zpAVxKJi6OkCVgRY5QeQIM7fvticVSnMR4ICfIfij ScNNNbPGlWrkJ5GVVzSmK8eNhhdX5qZHfquYJWYoi05H2xfCd8PNfHSHrHsjSeehayQ17BEUNno B5ajS6eoeL8kc30rvd/RO98X7ShVau22rCgR521sEXT/Tpphyr0rq+M8r1smYMxKftg+RnoIC6C 4OiF+idRivg75KU8StTi6cUE4FXkIEAL9DvN8bniwyyAzgIWmn011qJ01hoyUXRgqVHsdUlr0jW 1j9aHzMiyT0fNlCEq+eWQ3NqL24t0opH/+BZNyIlv5QKpQA3B/DkGOvjdCqupj6B1WeYGU1Naxq SH X-Received: by 2002:a05:620a:f11:b0:915:8f08:5f9d with SMTP id af79cd13be357-915a9dd4bd8mr792213085a.56.1780674147328; Fri, 05 Jun 2026 08:42:27 -0700 (PDT) X-Received: by 2002:a05:620a:f11:b0:915:8f08:5f9d with SMTP id af79cd13be357-915a9dd4bd8mr792205585a.56.1780674146859; Fri, 05 Jun 2026 08:42:26 -0700 (PDT) Received: from localhost (pool-100-17-21-205.bstnma.fios.verizon.net. [100.17.21.205]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9158a3d2384sm921805785a.39.2026.06.05.08.42.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2026 08:42:26 -0700 (PDT) Date: Fri, 5 Jun 2026 11:42:25 -0400 From: Eric Chanudet To: Maarten Lankhorst Cc: Michal =?utf-8?Q?Koutn=C3=BD?= , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , Maxime Ripard , Natalie Vock , Tejun Heo , Jonathan Corbet , Shuah Khan , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, "T.J. Mercier" , Christian =?utf-8?B?S8O2bmln?= , Maxime Ripard , Albert Esteve , Dave Airlie , linux-doc@vger.kernel.org Subject: Re: [PATCH v2 2/2] cgroup/dmem: add dmem.memcg control file for double-charging to memcg Message-ID: References: <20260519-cgroup-dmem-memcg-double-charge-v2-0-db4d1407062b@redhat.com> <20260519-cgroup-dmem-memcg-double-charge-v2-2-db4d1407062b@redhat.com> <158bc103-7f99-4df4-8d3b-2da9b04ac0ed@lankhorst.se> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <158bc103-7f99-4df4-8d3b-2da9b04ac0ed@lankhorst.se> On Fri, Jun 05, 2026 at 01:27:09PM +0200, Maarten Lankhorst wrote: > Hey, > > On 5/26/26 18:59, Eric Chanudet wrote: > > On Fri, May 22, 2026 at 05:26:16PM +0200, Michal Koutný wrote: > >> Hello Eric. > >> > >> On Tue, May 19, 2026 at 11:59:02AM -0400, Eric Chanudet wrote: > >>> Add a root-only cgroupfs file "dmem.memcg" that lets an administrator > >>> configure whether allocations in a dmem region should also be charged to > >>> the memory controller. > >> > >> This kinda makes sense as it is not unlike io.cost.* device > >> configurators. > >> > >> Just for my better understanding -- will there be a space for userspace > >> to switch this? (No charged dmem allocations happen before responsible > >> userspace runs, so that the attribute remains unlocked.) > >> > >> (I'm rather indifferent about the actual double charging/non-charging > >> matter.) > > > > Yes, this is intended to be configured before the user space stack that > > would start allocating things is started. Once it has started (and tried > > to charge something), the configuration is locked > > > >> > >>> > >>> To handle inheritance, dmem adds a depends_on the memory controller, > >>> unless MEMCG isn't configured in. > >>> > >>> Double-charging is disabled by default. Once a charge is attempted, the > >>> setting is locked to prevent inconsistent accounting by a small 4-state > >>> machine (off, on, locked off, locked on). > >>> > >>> The memcg to charge is derived from the pool's cgroup, since the pool > >>> holds a reference to the dmem cgroup state that keeps the cgroup alive > >>> until it gets uncharged. > >>> > >>> Signed-off-by: Eric Chanudet > >>> --- > >>> Documentation/admin-guide/cgroup-v2.rst | 23 +++++ > >>> kernel/cgroup/dmem.c | 158 +++++++++++++++++++++++++++++++- > >>> 2 files changed, 178 insertions(+), 3 deletions(-) > >>> > >>> diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst > >>> index 6efd0095ed995b1550317662bc1b56c7a7f3db23..1d2fa55ddf0faa17baa916a8914d3033e8e42359 100644 > >>> --- a/Documentation/admin-guide/cgroup-v2.rst > >>> +++ b/Documentation/admin-guide/cgroup-v2.rst > >>> @@ -2828,6 +2828,29 @@ DMEM Interface Files > >>> drm/0000:03:00.0/vram0 12550144 > >>> drm/0000:03:00.0/stolen 8650752 > >>> > >>> + dmem.memcg > >>> + A readwrite nested-keyed file that exists only on the root > >>> + cgroup. > >> > >> Strictly speaking this is not nested-keyed but flat keyed [1], > > > > Indeed, > > > >> which leads me to realization that this is the first instance of a boolean. > >> All in call, such a composition comes to my mind (latter is RO): > >> > >> drm/0000:03:00.0/vram0 enable=0|1 locked=0|1 > >> > > > > So per[1] 1 key, 2 sub-keys (enable RW, locked RO), that looks better > > and match the documentation, thanks! > > > >> > >> > >>> +static ssize_t dmem_cgroup_memcg_write(struct kernfs_open_file *of, char *buf, > >>> + size_t nbytes, loff_t off) > >>> +{ > >>> + while (buf) { > >>> + struct dmem_cgroup_region *region; > >>> + char *options, *name; > >>> + bool flag; > >>> + > >>> + options = buf; > >>> + buf = strchr(buf, '\n'); > >>> + if (buf) > >>> + *buf++ = '\0'; > >> > >> I recall there was a discussion about accepting only a single device per > >> write(2) (at the same time I see this idiom is still present in other > >> dmem.* files, so this is nothing to change in _this_ patch). > > > > I would second that. When setting say dmem.max for 2 regions, with a > > typo on the second, the first one is set, but write still get EINVAL. > > > > Also, I just notice dmemcg_limit_write() returns EINVAL if the region is > > not found (this patch returns ENODEV). > > > >> > >> Thanks, > >> Michal > >> > >> [1] https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html#format > > > > > > > > Perhaps a bit late, but before we start adding this UAPI we should enforce a > single region per write? I can send that separately, although that is a UAPI change. Is there any user that would be affected? This series is hung on charging memcg using memory objects from the context of dmem, when at that level of abstraction it doesn't have access to the underlying pieces that were allocated. Best, > > Kind regards, > ~Maarten Lankhorst > -- Eric Chanudet