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 5FCA0C83F1A for ; Mon, 21 Jul 2025 05:57:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CCA136B008A; Mon, 21 Jul 2025 01:57:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C54376B008C; Mon, 21 Jul 2025 01:57:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF46B6B0093; Mon, 21 Jul 2025 01:57:05 -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 9A8D56B008A for ; Mon, 21 Jul 2025 01:57:05 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1705B130E65 for ; Mon, 21 Jul 2025 05:57:05 +0000 (UTC) X-FDA: 83687213610.02.A79934B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf16.hostedemail.com (Postfix) with ESMTP id D631518000D for ; Mon, 21 Jul 2025 05:57:02 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FKojpntv; spf=pass (imf16.hostedemail.com: domain of airlied@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=airlied@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1753077422; 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=Q3rzazQ4BjXHZvVDYlz6PavKZkH7wTCMuLfY3C5kJTk=; b=LGbdfQjv63PLDjvDRpJ4bsaZYN/qgPSEMNur4FRs98kNhc2RfuSItZoYq3qPxI1feggZqE oGoq+qDZyKDqBeAkpSKDq+bDbP341uP8dPkIXmDKOQBPhifIEugbNnbzDiaSfn5iVm0EZu s4Caghx2M8wmGSGMSVrzNJh9fIDERfE= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FKojpntv; spf=pass (imf16.hostedemail.com: domain of airlied@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=airlied@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1753077422; a=rsa-sha256; cv=none; b=D2UZFzPczuSRDGExSfInOzTi+fkV7kfAtHjIML81AI0d6unpQljL05Uf9lzFtwdTd9UR2M KoLLhsDCFvyAfabXZEhsTfpRuvW522ElLW3vyOkQV8TTMiiMZoawB0mqJMhq4pLZ0mRZ5w XVVOq1m+TeyjvWOXZVN/KoXrijxkYcQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1753077422; 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=Q3rzazQ4BjXHZvVDYlz6PavKZkH7wTCMuLfY3C5kJTk=; b=FKojpntvFINdvYfcMXKVsJ2Izovy8JsznAgq5bVbGvhWGRIcnwsqSGnyeZvYMtgfWMbfv5 MA77Ay49xX755sM6vTYCYZF35vN51NvJUBzeB6BzmuInTorM5rCMV4lkGgvZYnrO2lyW3p y9sNO9vI5HScRQchDyHY7524dmLAy7s= Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-648-CHXoqXN8OtSAwmXpJ6hD6w-1; Mon, 21 Jul 2025 01:57:01 -0400 X-MC-Unique: CHXoqXN8OtSAwmXpJ6hD6w-1 X-Mimecast-MFC-AGG-ID: CHXoqXN8OtSAwmXpJ6hD6w_1753077420 Received: by mail-pg1-f199.google.com with SMTP id 41be03b00d2f7-b31cc625817so3789349a12.0 for ; Sun, 20 Jul 2025 22:57:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753077420; x=1753682220; 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=Q3rzazQ4BjXHZvVDYlz6PavKZkH7wTCMuLfY3C5kJTk=; b=Ado2Y+k8SBS3FN8JzpzVA7hach2KYrAIsjQvFzRGfZqq7HZ7/eQ/FBrk2EMzp7Q8LR W9/NFUBT/k577ectHhQ+Mk+ni/MdrDx3UMFZO+GgbJm4Gz0Oisl77Rv3TncmjTI336/3 zA0Thuvb8CPtgBktxHSGJMUHec+dOJqCXyAvPwS1ipX6MsReiLQSP+f9687YnX1q9BHH 6uQBvBMj6rc4sjQ4w8Ck2O1DIavqr3GlxnkmjdnYLUS78kkBTykh8VNQzRNWoRUnW7jP E88VnSRbrP9G2ZZfw2MV+wD7y5eYVO+Zuf59Zu4tr3nUByIwgyZMkntA/QUN6yeSS1z2 DrFg== X-Forwarded-Encrypted: i=1; AJvYcCVaY1WxaVTviUyM1+IqYXXWvx9voOX0HI1dZlOTE8O5uMoSwaPGaONzx7HTdGhVfJLgj0uWj5Bu1w==@kvack.org X-Gm-Message-State: AOJu0YwD4eHFrmDW7A7BnS4qaRrSSMEt4m5uSqi5E1XBCfxCo8ytoLm9 pqx8qaoegIlKGNlXfHtmdCYqLxssY5Nr8sbvSTY1eJOhuTmKxosOkZXhPIOPrQ/4oStjBmDsTtD Y9Cpn6DD9TwXKQZOw/jfyoysOywgg2gMdQCIToY2k4IMKRn5Jh+OSQTolQjJttiYDZbboXGrxdr /6x2/ADXZWewOCWB7vQ8xDHkxVluw= X-Gm-Gg: ASbGncsBxEPCp30b3JuP9t6sVeocIhuz2/74c70NLNrGAnT3yvmEUJWNW0zhowfV69m /jyjoJl81mupCM6fSLcSqK9NQzMAcTLNdyKKYYCAMSygdCNdVaDXu72CPLo8+iebhclMWn1TL9G up5NjADZDleQ+fB0IYCgQ= X-Received: by 2002:a17:903:244b:b0:234:5ea1:6041 with SMTP id d9443c01a7336-23e38f493dcmr194191285ad.10.1753077419889; Sun, 20 Jul 2025 22:56:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHG30/IUvMvXE4T8kwdI6mXQJm628Dh8t0N1cwgCJIczEB7l9/FzCUuDq7Sd8SWP/dcn+bNUrtoCZBtkW3tkvE= X-Received: by 2002:a17:903:244b:b0:234:5ea1:6041 with SMTP id d9443c01a7336-23e38f493dcmr194190925ad.10.1753077419507; Sun, 20 Jul 2025 22:56:59 -0700 (PDT) MIME-Version: 1.0 References: <20250714052243.1149732-1-airlied@gmail.com> <20250714052243.1149732-14-airlied@gmail.com> <77949b3a-201d-4e7d-a51f-e77274e4a4be@amd.com> In-Reply-To: <77949b3a-201d-4e7d-a51f-e77274e4a4be@amd.com> From: David Airlie Date: Mon, 21 Jul 2025 15:56:48 +1000 X-Gm-Features: Ac12FXxBRUtewqShIudpiVAD2K3FTCF0W2oO-DbYH3MAKSeUnM2igg0xj9npego Message-ID: Subject: Re: [PATCH 13/18] ttm/pool: enable memcg tracking and shrinker. (v2) To: =?UTF-8?Q?Christian_K=C3=B6nig?= Cc: Dave Airlie , dri-devel@lists.freedesktop.org, linux-mm@kvack.org, Johannes Weiner , Dave Chinner , Kairui Song X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: v1CMlOtDHBRFiW6ruNoA0TIwf_cWBxWR0KjIpr-wCXc_1753077420 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Queue-Id: D631518000D X-Rspamd-Server: rspam06 X-Stat-Signature: bhftb5c81zgrgqakai9s4cdnnbm7k3da X-HE-Tag: 1753077422-150376 X-HE-Meta: U2FsdGVkX18gRtlcXlfzPMnKrDBqaK4nz6fAHzFLgZTRQ8K9Mz4XItkESA3lxxb31GMMyFDi7wvsFzfadPWtftw3jkx+UpllTXCJ1l4CYz1OEpgxhvyjzoKMkn4vzbnNS2gnSAmqgL2XWG61ZGU37npNm9xKWGvxAndQATQy/7whzCCAUTiGrV6pkkZvWJDhm4WmosmTyNfxlBIqxcqM4TSg8SHSq4norzgNKQTsE3FpTQVjKB6Q2lNbW4hXv/zULi9jUCbInHSLh3nxsUxuUOSnRhOXBbb9xVK0YdqEGt7tBacy+ZGNJkC0QcaNh7qbI6r1zDlqjTyHVp7Bwooh/WNR2UxpnkDmk47m1B9b07x0v3yv6DNHGZsk1kwWv+2LGKu2vsWVL3cfYye1W8KFiSNOBdD3g6Hx1ydSb/YqrGnLbvckUnT1rOozogRRbqGigLPpE1RaJ3LSXbsW5/lHVm2d0vyiXD6SI6Y+cb5GME7ISysFBbmiw6X+KS8KjmEfFqLzFkgY4GyKFIe/UT0P3Ub6SukwU0xk46vZQ4oWgn6YOUZBRFfrEhLnGM0hfVi0atI+9blzPborAVzgDWZDCoGAI89eU/tmddVMeXaT8XxfiEB8a6cPuNktR8w4mjp7TX5p8WxsJBpsLD3fePSCxnQ7UjIfuhL+feEjbkhbemvL9qlYLWVa4lmUN394J+s+htjAtizPxzYPmBy5XIGKxqegAQv10b5jg+vj892IuHWOyPtTztQRA7n6dH0HcVk2+ow0MB470D3UZoyvM8UiCXUWKA1j8wjroBoxW+muIVRhVjgcdb3SEhEYyHA9eRgXJuPkFoZXWc0QQw1W1YIXZRzkcE8UoiN/zk/J0k2m1rAEdgCiUHP9y0f3hxSsuDQfx6BUyM7Tw/gZjWAIPggP6DdbAFDqKXpS1/bwr/KiO7CkrI5ERk153CspRgpgD0cmbMjm6hnUoKDnwepVFBA N68gTWlJ SQH9NIWWP6VAjvNdMkH9fJxHB656Ml7+asHS04vVj8x75dnD6njCKG07pOMzh2rd+Id5BNBXTn8OIJJubesKJLHpGKDy1wUCejuoSXUYcgxm+q6+7PXm1p5XhKZbM4jPABvRE5zBLeAa2r1BXL6jjcuH7gXLoxie6KHGvrDNg4K22MwePDhWWTs/TyoUYsZGw2gT56QpnN/mbiq0tgkIIk8+G5WipTgpQLhWKN9umylzOMbgMKFrRHRAvf0+Igl6w7y4SMlvYuClofnpk2Oj8jJRirO+3XU+DzlP6Sf+RYTrsE2o= 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 Tue, Jul 15, 2025 at 5:34=E2=80=AFPM Christian K=C3=B6nig wrote: > > > > On 14.07.25 07:18, Dave Airlie wrote: > > From: Dave Airlie > > > > This enables all the backend code to use the list lru in memcg mode, > > and set the shrinker to be memcg aware. > > > > It adds the loop case for when pooled pages end up being reparented > > to a higher memcg group, that newer memcg can search for them there > > and take them back. > > > > Signed-off-by: Dave Airlie > > > > --- > > v2: just use the proper stats. > > --- > > drivers/gpu/drm/ttm/ttm_pool.c | 126 ++++++++++++++++++++++++++------- > > 1 file changed, 102 insertions(+), 24 deletions(-) > > > > diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_p= ool.c > > index a4f4e27c6a1f..1e6da2cc1f06 100644 > > --- a/drivers/gpu/drm/ttm/ttm_pool.c > > +++ b/drivers/gpu/drm/ttm/ttm_pool.c > > @@ -142,7 +142,9 @@ static int ttm_pool_nid(struct ttm_pool *pool) { > > } > > > > /* Allocate pages of size 1 << order with the given gfp_flags */ > > -static struct page *ttm_pool_alloc_page(struct ttm_pool *pool, gfp_t g= fp_flags, > > +static struct page *ttm_pool_alloc_page(struct ttm_pool *pool, > > + struct obj_cgroup *objcg, > > + gfp_t gfp_flags, > > unsigned int order) > > { > > unsigned long attr =3D DMA_ATTR_FORCE_CONTIGUOUS; > > @@ -162,7 +164,10 @@ static struct page *ttm_pool_alloc_page(struct ttm= _pool *pool, gfp_t gfp_flags, > > p =3D alloc_pages_node(pool->nid, gfp_flags, order); > > if (p) { > > p->private =3D order; > > - mod_node_page_state(NODE_DATA(page_to_nid(p)), NR= _GPU_ACTIVE, (1 << order)); > > + if (!mem_cgroup_charge_gpu_page(objcg, p, order, = gfp_flags, false)) { > > Thinking more about it that is way to late. At this point we can't fail t= he allocation any more. > I've tested it at least works, but there is a bit of a problem with it, because if we fail a 10 order allocation, it tries to fallback down the order hierarchy, when there is no point since it can't account the maximum size. > Otherwise we either completely break suspend or don't account system allo= cations to the correctly any more after resume. When you say suspend here, do you mean for VRAM allocations, normal system RAM allocations which are accounted here shouldn't have any effect on suspend/resume since they stay where they are. Currently it also doesn't try account for evictions at all. > > What we need is to reserve the memory on BO allocation and commit it when= the TT backend is populated. I'm not sure what reserve vs commit is here, mem cgroup is really just reserve until you can reserve no more, it's just a single charge/uncharge stage. If we try and charge and we are over the limit, bad things will happen, either fail allocation or reclaim for the cgroup. Regards, Dave.