Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp145783rwb; Thu, 27 Jul 2023 10:31:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlHg/Xsx1fLiEIty9zvk4cWFIsIy8lnIaGB0G0XlepPxGUFxVJ2SlKLWLH6BGLDJQ1ndlorW X-Received: by 2002:a17:902:c1d2:b0:1b6:69dc:44d2 with SMTP id c18-20020a170902c1d200b001b669dc44d2mr5001199plc.51.1690479101882; Thu, 27 Jul 2023 10:31:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690479101; cv=none; d=google.com; s=arc-20160816; b=tHXVE3QeIAfKqt2tJkgk0VArRygWh5+AW3v3A7stxhYXDrUfUPKXP443stWkcu65El 0Q2wQslYl7WjqIilMv44mfQrPSjCie9BW+SOFYzVGLijvZsovvR866zG0M9vONHDcAEm a+AEXZZLKwCT2k0p2wmYr2/m32yGsDCfVnE+NB7mv1OUlXsuyLrJRCcd6wfMp3HGbqPN bC9iIH1kVkQhTCrerAPnZlWJRVG/Ts+QCb35xsfOmNdLxtEYje3ys0Vn2kWWPyih1eso +7ITsGNiW91t7+2mqueGM77V/HlttEWhvG7Pxn7EEyMcj4W//X0D4wj4twuYOCqyIREs s+QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=eIYPBMbGbz3YnMwEUtPGYn/wWiDN+jg32OoRyTA8reM=; fh=FIo20aVGUDtah8oRurCIoCzJ1ht3sEeHMxaKOZbJZgE=; b=rPxqUAKR5ig01YfvgBjU7nZAAmutgvs3/1cqkiZafxZIgqBqBt4SE6bsxgCJoBEoli v0qzAyJtb/MFlkVgYXRVeFevM/6XNlbQhUrd3Htz9KWDo61dif3NfbxtQz/1MaYBn1pw jgnFJ5L3CmwSQCd+ELOYaP7Zj9UqDrNhlyJUUbTWXaeIIPqxMYYht1tHGCrr2Zwryjk9 H7xW5nB37XxRs3TN9v1/dhvu5nyYGNYOime1pWPYPMbv6zSHHFr0jpUsuvy7cmiKgezu xSDxOzP2zcqUqSvzVHoBcqTGkUWwb3lGp61T5pqU1Ni1/FAKlOcYRen6uK9viRFu/V+8 51Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LeAxHdSe; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t2-20020a17090340c200b001b8419bd0f5si1597206pld.254.2023.07.27.10.31.28; Thu, 27 Jul 2023 10:31:41 -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=@intel.com header.s=Intel header.b=LeAxHdSe; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231748AbjG0Qnp (ORCPT + 99 others); Thu, 27 Jul 2023 12:43:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231550AbjG0Qnn (ORCPT ); Thu, 27 Jul 2023 12:43:43 -0400 Received: from mgamail.intel.com (unknown [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF14A30D3; Thu, 27 Jul 2023 09:43:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690476220; x=1722012220; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=EPPEG5IjRpK3UjK14v1TE0oHNl+auGdkynzlUa5wKQI=; b=LeAxHdSe4yD2QqqGpjKi6F0xw1xll7EEwTxXwCwXwKPK+NCzBS0UtlBX JkZCytIyjIY3E0Qt+ArKjv+h1T0BXP+0KJT7vVMSNda4Zan21qb0lk1En o9/0CvJnkNFAIUeAUEEGaOXRyRSJJEdrzshGDcVwmKbmBqBzUrpiaNUKI tzreaMKR+6TTxpT0zy1gZ6QT77HuuQ0tuN0sDN2JzwnjGLMbgYzC0drTl iBZqCqxVxt+W4ZXImlBM/4vbP6VeVrPcWL2nB+bXaVqcT4ulZStd4FW03 3rQCqkP7r29CEXEbidVTmyNGtuAnkPZklzUsOGKcIeyqVd2/qxdHSFoLA A==; X-IronPort-AV: E=McAfee;i="6600,9927,10784"; a="371996230" X-IronPort-AV: E=Sophos;i="6.01,235,1684825200"; d="scan'208";a="371996230" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jul 2023 09:43:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10784"; a="730416549" X-IronPort-AV: E=Sophos;i="6.01,235,1684825200"; d="scan'208";a="730416549" Received: from jlenehan-mobl1.ger.corp.intel.com (HELO [10.213.228.208]) ([10.213.228.208]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jul 2023 09:43:36 -0700 Message-ID: <6ed5478c-8a67-5ad8-3e6d-51c300702cf3@linux.intel.com> Date: Thu, 27 Jul 2023 17:43:33 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH 16/17] cgroup/drm: Expose memory stats Content-Language: en-US To: Maarten Lankhorst , Tejun Heo Cc: 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 , =?UTF-8?Q?St=c3=a9phane_Marchesin?= , "T . J . Mercier" , Kenny.Ho@amd.com, =?UTF-8?Q?Christian_K=c3=b6nig?= , Brian Welty , Tvrtko Ursulin , Eero Tamminen References: <20230712114605.519432-1-tvrtko.ursulin@linux.intel.com> <20230712114605.519432-17-tvrtko.ursulin@linux.intel.com> <05178cf3-df1c-80a7-12ad-816fafbc2df7@linux.intel.com> From: Tvrtko Ursulin Organization: Intel Corporation UK Plc In-Reply-To: <05178cf3-df1c-80a7-12ad-816fafbc2df7@linux.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HK_RANDOM_ENVFROM,HK_RANDOM_FROM, NICE_REPLY_A,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham 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 On 27/07/2023 14:42, Maarten Lankhorst wrote: > On 2023-07-26 21:44, Tejun Heo wrote: >> 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. Yes, keyword is "can". Trouble is migration may or may not happen. One may choose "Plasma X.org" session type in your login manager and all DRM fds would be under Xorg if not migrated. Or one may choose "Plasma Wayland" and migration wouldn't matter. But former is I think has a huge deployed base so that not supporting implicit migration would be a significant asterisk next to the controller. >> * 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? > > Hey, > > Yeah mostly, I think we can stop tracking stolen memory. I stopped doing > that for Xe, there is literally nothing to control for userspace in there. Right, but for reporting stolen is a red-herring. In this RFC I simply report on all memory regions known by the driver. As I said in the other reply, imagine the keys are 'system' and 'vram0'. Point was just to illustrate multiplicity of regions. Regards, Tvrtko