Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1506959rwb; Wed, 26 Jul 2023 13:42:28 -0700 (PDT) X-Google-Smtp-Source: APBJJlHRhq9AfcZKyLd9cDYhm54VBUODEw1jrg3VoLdCN/B3nQqRCYPAcHb243lpYV2A0uHF6wQ0 X-Received: by 2002:a17:907:75c9:b0:993:f15f:efbe with SMTP id jl9-20020a17090775c900b00993f15fefbemr218071ejc.5.1690404148620; Wed, 26 Jul 2023 13:42:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690404148; cv=none; d=google.com; s=arc-20160816; b=WKyomhFPH+FWIj5z5ju9zqIvoysr4CTHF+3ZILbDXprW49QWcJXg4Bua35HiM8uPAj 9dXTrZFGtw0ZU3G10I08XdtW8Qs/QgDU4jGQFryXoD9ioUcEpjXZXWlKq1g7Klr0GzRN QFvwzkc2e08Hn+fa0FYbqxo9bap3A2rah5dUkxXUBClfHOLYS6Y+eucJvm8r6tpRs+u9 e/ErJ2Hc6Rptbzkuy4FRX+xBNv4t6oklyBUT+oFBv+IZTn9db/Zn5iTHsx71dK89GElg 5cfRSDrMAiguJkzV1mzgdNasHjXP/GNlN1XZnHFKUB36G2BgA6c8nA0ebZQ7/rV2QzGz KNLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=VIQUF5pxDq7OaH/cq+/yDjYiLBedFBP8ulSYElZmLwU=; fh=B3N9XGvmbKs6R5t7cvquuC4hxDLKF6LX0NH1aKiGP5k=; b=fgWsgpjV9NQktB0V3+n3NrOnaeG2t4pPIbjNy+vWeJEyx76b4TyQkN+dToAYC/nDz+ WXYzbZ1pop6yOnptRx4V7hS4SzygkpYEjcQ2zLZ1S82mR8DZrZ5QRvDULDKxe429t8E/ MGGHmEGJ65sB0kwZKUeS2+AoDlGAEU/IZihdHZi45g8tjvRuQhxqdEAHfyh9xOblTtXX 8RaKepw0t51SimymoCUNmyVtq+NU3XQKnKnf56CIhsZ20ZAroYNZtE/qvT76wKJE5BSD /jMlNPBXE3tcxpN00DT2Vb/PoeKGwBqKOIrCeQOPBDgsvIUf1KFfI/oSJq7o0WUi5pem NTkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=lABXBtPF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z22-20020a1709067e5600b0099367afd642si9064937ejr.66.2023.07.26.13.42.04; Wed, 26 Jul 2023 13:42:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=lABXBtPF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230285AbjGZTot (ORCPT + 99 others); Wed, 26 Jul 2023 15:44:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229798AbjGZTos (ORCPT ); Wed, 26 Jul 2023 15:44:48 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 401A91727; Wed, 26 Jul 2023 12:44:47 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-686efb9ee3cso179980b3a.3; Wed, 26 Jul 2023 12:44:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690400686; x=1691005486; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=VIQUF5pxDq7OaH/cq+/yDjYiLBedFBP8ulSYElZmLwU=; b=lABXBtPFwn3FCtQv5Cb3csSuJ2Td+KIqkY5ygJK0lT+9ay/TSKzRV3T/qdi98zeoJe oirsG2ATytq9UM5BIwjUrJMCjNvs/M8LRIKHCmOWwOA5XgTn6g/wTI9hbwmoN5jBAyeR r+c0pgllRpNRDT39CCHZcjyopLj5wXSO4zaJMbVwNJGLOp1Mrm0vWbBj9kIfL+80Q3/Y y4VZiF1TKsaNGhoxjq1SQuk+3lm4Cf73LWjQlG1jt2Ece5jOgByA80o/KGwosJv0zjw8 AFI2VC6F+beS2/t3y7sKqyAUHeziG+oPhfCT7qB3RLIYWwVJ4q/rAVag/eFqSaSpAe9m tx2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690400686; x=1691005486; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VIQUF5pxDq7OaH/cq+/yDjYiLBedFBP8ulSYElZmLwU=; b=b9pqys9e4NQDbssFDXGGwp1s8MZm8/E9Gin66f/pSZQjfWNaWo8GxOlE0StnruYl9t o8yWWQHXEHHcvEdiis6VPF5kJASaSut3k3gRiRZWIc2B2ZHoaKp4ziWyuPmkTGPepXbL qzah/xnebpVgWIhzcBWaKyvpsPQ4PKJSpLxEATKiUiJhCYwED5UQQas8pcPgAxlVaAA3 2xUhgeXPf89cPBp9S31e8NSt2mucFoVMXws+fqr5+z67M/6URMrb/sEXedCq79v4plhj hi2KpGriB/JV9/6sXeAOLssJGjLsiy86lANhBsN8CNXrvvhS2nUycOWYKhGO2GtrxkVQ xJxQ== X-Gm-Message-State: ABy/qLbv7Dvns7aWtnYO4JEGTPJIGMrX/XoI3PGKq7aSiCgqar06GHrk pQUOgr26ZZt5P2nUW8jQNto= X-Received: by 2002:a05:6a00:b54:b0:668:81c5:2f8d with SMTP id p20-20020a056a000b5400b0066881c52f8dmr4063786pfo.3.1690400686414; Wed, 26 Jul 2023 12:44:46 -0700 (PDT) Received: from localhost ([2620:10d:c090:400::5:18d]) by smtp.gmail.com with ESMTPSA id d19-20020aa78153000000b0065da94fe917sm1163pfn.36.2023.07.26.12.44.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 12:44:45 -0700 (PDT) Sender: Tejun Heo Date: Wed, 26 Jul 2023 09:44:44 -1000 From: Tejun Heo To: Maarten Lankhorst Cc: Tvrtko Ursulin , Intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Weiner , Zefan Li , Dave Airlie , Daniel Vetter , Rob Clark , =?iso-8859-1?Q?St=E9phane?= Marchesin , "T . J . Mercier" , Kenny.Ho@amd.com, Christian =?iso-8859-1?Q?K=F6nig?= , Brian Welty , Tvrtko Ursulin , Eero Tamminen Subject: Re: [PATCH 16/17] cgroup/drm: Expose memory stats Message-ID: References: <20230712114605.519432-1-tvrtko.ursulin@linux.intel.com> <20230712114605.519432-17-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Wed, Jul 26, 2023 at 12:14:24PM +0200, Maarten Lankhorst wrote: > > So, yeah, if you want to add memory controls, we better think through how > > the fd ownership migration should work. > > I've taken a look at the series, since I have been working on cgroup memory > eviction. > > The scheduling stuff will work for i915, since it has a purely software > execlist scheduler, but I don't think it will work for GuC (firmware) > scheduling or other drivers that use the generic drm scheduler. > > For something like this, you would probably want it to work inside the drm > scheduler first. Presumably, this can be done by setting a weight on each > runqueue, and perhaps adding a callback to update one for a running queue. > Calculating the weights hierarchically might be fun.. I don't have any idea on this front. The basic idea of making high level distribution decisions in core code and letting individual drivers enforce that in a way which fits them the best makes sense to me but I don't know enough to have an opinion here. > I have taken a look at how the rest of cgroup controllers change ownership > when moved to a different cgroup, and the answer was: not at all. If we For persistent resources, that's the general rule. Whoever instantiates a resource gets to own it until the resource gets freed. There is an exception with the pid controller and there are discussions around whether we want some sort of migration behavior with memcg but yes by and large instantiator being the owner is the general model cgroup follows. > attempt to create the scheduler controls only on the first time the fd is > used, you could probably get rid of all the tracking. > This can be done very easily with the drm scheduler. > > WRT memory, I think the consensus is to track system memory like normal > memory. Stolen memory doesn't need to be tracked. It's kernel only memory, > used for internal bookkeeping only. > > The only time userspace can directly manipulate stolen memory, is by mapping > the pinned initial framebuffer to its own address space. The only allocation > it can do is when a framebuffer is displayed, and framebuffer compression > creates some stolen memory. Userspace is not > aware of this though, and has no way to manipulate those contents. So, my dumb understanding: * Ownership of an fd can be established on the first ioctl call and doesn't need to be migrated afterwards. There are no persistent resources to migration on the first call. * Memory then can be tracked in a similar way to memcg. Memory gets charged to the initial instantiator and doesn't need to be moved around afterwards. There may be some discrepancies around stolen memory but the magnitude of inaccuracy introduced that way is limited and bound and can be safely ignored. Is that correct? Thanks. -- tejun