Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1317690pxb; Thu, 24 Mar 2022 17:39:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnnI6mBrD2U56eHlkKXfImoTdSQsfnfIQl5Repqy2AnFeXeN06BLhl+iCf/wP5QJlL/Cbc X-Received: by 2002:a17:90b:905:b0:1c6:9747:1939 with SMTP id bo5-20020a17090b090500b001c697471939mr9496312pjb.37.1648168784401; Thu, 24 Mar 2022 17:39:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648168784; cv=none; d=google.com; s=arc-20160816; b=Bm4PmKeVFcGNozkMQdZ0FgGwTnwIWZMFYqyfVgJidZe0Npvdpgi5gBx09GsJ7Ua/io BTfY3to9eAiuCsHEM9DbtpROj+msI7KAGtLWseRQXPTYDynGqnny1/xMxCcwjbLZWTq7 YlqdLpDBClsN0JZwppxWH5afrDsUWLFUISDQv0+hPFT1vTMmfon8P319U8wkKG7qUVRt luLJZbFGBTKZvIQhK/Bfhg+0yCS9Fls+b5pF7PKpDYSxoM/usJuMIQ23sprt+sIwh+XP dPWelFJcVmpniSRu5mXEeeNuou//Lkk3LhwhiJhjVqF6X8canGQndBHi9pr0bkJwkGqx lTlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=lYs3d+G/MqnkVL5mPK5nuhjYbBx01naVFSe4Xk42kfM=; b=tH/6cV2aK3dWvlvNPA+JmtDSUAlbxVAc1TfNERwgJ8tHhvVBb03mXJAA2o0ogLtdx1 tDq/iTWSnWsU5EfxerJVwWlmB4Fch5o5+qmxqCgEF67hjSg6NMqeuj4OVf60Afi0o73Z t1tMe/Eqa30HJunydiXfR5FWtXG9FXBqfNRAqNvSthvRAbT/XILeICpAAnJS8TYFcQI4 VTcaFox5axhnm8JiVyywEqgXwX4ZrT9P5EQgi2IH48xD/cZyF7G8CIRQ5guMdTSyX5JL OLlIy+fvr+wT8IA8zZ1YLEjTf16syZee3EIaa4GDi3KKy4j0Ck/pPhyTJFbqSHIK623W SWBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=lKb4AaK6; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m17-20020a635811000000b003816043f0afsi809285pgb.676.2022.03.24.17.39.00; Thu, 24 Mar 2022 17:39:44 -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=@google.com header.s=20210112 header.b=lKb4AaK6; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346880AbiCWXjf (ORCPT + 99 others); Wed, 23 Mar 2022 19:39:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347112AbiCWXiw (ORCPT ); Wed, 23 Mar 2022 19:38:52 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD6A770047 for ; Wed, 23 Mar 2022 16:37:20 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id y10so3692689edv.7 for ; Wed, 23 Mar 2022 16:37:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=lYs3d+G/MqnkVL5mPK5nuhjYbBx01naVFSe4Xk42kfM=; b=lKb4AaK6N9O62KVZSBFpoXMFMKi2DX++d0hcldo7VKltrYvP1ZV+I9dYXZlx13MpxC U6xbiC42KS2p1EnoJU/ZpUu2VFNzNn/B5ByWL9Zt/vr5XdA+yDneUYBZIcau3mhQ0muv V4ah+EZCicq3OsyPu2g/e6akuJDlkHFQFQdx2jnBGU1XDVC3q67LkJ1lTpu2QD3b10Gm //++HMvqfQRnNJ7DQNGYM/1Pf8y6AjoqHMxScOBz3cW/cZXBbkCYsHBTNfYHMC39INi5 cHWn+JRXaDWTnRSK6VSSXCSqWAo9ASLt+74RRIvM/eLnYs1Iz3CUqvYDSdMrTd/CQ+rq 7Uww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=lYs3d+G/MqnkVL5mPK5nuhjYbBx01naVFSe4Xk42kfM=; b=fUxc2tXYcw1i7cznGhUjBF8chkm4NdWgwKdJ9tJUEVXict4/ZaJ1dGzlD13Z5rR4PX QiiCrtTx23j9IKqFjbsY+opR7KsSM3KKM6W19dhGXhw1w6nne+4nMvkP2MCY5PW0J1Jq Opa3imdrYTbvUeTtNGSOWp2Ns7v3A3gs/NOkWImZPKYm46VbD9pNwMBCKDMmi6/Nx+/E 9gT0GT4g91wURqu9A9n9xeLTe2wEbYU0sacDnEOp66blXfwLZVLeqSqSbxrP31eXedQS /LG5KmPfo3wv8FBJAw3p7OArJdkgkV7pvgReGzvZKYb/NVjgnX9qk39E9ns910HjnAqm iLow== X-Gm-Message-State: AOAM5310971i5uz+T5FtPc0drMtj6nXCpw+R6li9NNXwa5Tv1z7IajiB EdR1UuMJtwDoo63eplESkHfkzUSG+tPA7WVBBCch3g== X-Received: by 2002:a50:9b4f:0:b0:419:49af:429c with SMTP id a15-20020a509b4f000000b0041949af429cmr3390112edj.276.1648078639171; Wed, 23 Mar 2022 16:37:19 -0700 (PDT) MIME-Version: 1.0 References: <20220322095223.GG8477@blackbody.suse.cz> In-Reply-To: From: "T.J. Mercier" Date: Wed, 23 Mar 2022 16:37:08 -0700 Message-ID: Subject: Re: [RFC v3 5/8] dmabuf: Add gpu cgroup charge transfer function To: =?UTF-8?Q?Michal_Koutn=C3=BD?= Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Jonathan Corbet , Greg Kroah-Hartman , =?UTF-8?B?QXJ2ZSBIasO4bm5ldsOlZw==?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Hridya Valsaraju , Suren Baghdasaryan , Sumit Semwal , =?UTF-8?Q?Christian_K=C3=B6nig?= , Benjamin Gaignard , Liam Mark , Laura Abbott , Brian Starkey , John Stultz , Tejun Heo , Zefan Li , Johannes Weiner , Shuah Khan , Kalesh Singh , Kenny.Ho@amd.com, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, cgroups@vger.kernel.org, "Subject: Re: [RFC v3 5/8] dmabuf: Add gpu cgroup charge transfer function Reply-To: In-Reply-To:" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 Tue, Mar 22, 2022 at 9:47 AM T.J. Mercier wrote: > > On Tue, Mar 22, 2022 at 2:52 AM Michal Koutn=C3=BD wro= te: > > > > On Mon, Mar 21, 2022 at 04:54:26PM -0700, "T.J. Mercier" > > wrote: > > > Since the charge is duplicated in two cgroups for a short period > > > before it is uncharged from the source cgroup I guess the situation > > > you're thinking about is a global (or common ancestor) limit? > > > > The common ancestor was on my mind (after the self-shortcut). > > > > > I can see how that would be a problem for transfers done this way and > > > an alternative would be to swap the order of the charge operations: > > > first uncharge, then try_charge. To be certain the uncharge is > > > reversible if the try_charge fails, I think I'd need either a mutex > > > used at all gpucg_*charge call sites or access to the gpucg_mutex, > > > > Yes, that'd provide safe conditions for such operations, although I'm > > not sure these special types of memory can afford global lock on their > > fast paths. > > I have a benchmark I think is suitable, so let me try this change to > the transfer implementation and see how it compares. I added a mutex to struct gpucg which is locked when charging the cgroup initially during allocation, and also only for the source cgroup during dma_buf_charge_transfer. Then I used a multithreaded benchmark where each thread allocates 4, 8, 16, or 32 DMA buffers and then sends them through Binder to another process with charge transfer enabled. This was intended to generate contention for the mutex in dma_buf_charge_transfer. The results of this benchmark show that the difference between a mutex protected charge transfer and an unprotected charge transfer is within measurement noise. The worst data point shows about 3% overheard for the mutex. So I'll prep this change for the next revision. Thanks for pointing it out. > > > > > > which implies adding transfer support to gpu.c as part of the gpucg_* > > > API itself and calling it here. Am I following correctly here? > > > > My idea was to provide a special API (apart from > > gpucp_{try_charge,uncharge}) to facilitate transfers... > > > > > This series doesn't actually add limit support just accounting, but > > > I'd like to get it right here. > > > > ...which could be implemented (or changed) depending on how the chargin= g > > is realized internally. > > > > > > Michal