Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7013156rwl; Mon, 9 Jan 2023 16:37:48 -0800 (PST) X-Google-Smtp-Source: AMrXdXtRAVBCsZQKYsNd+iQ2NVJcdrZ98G2j2Montoqe1cQ4JqiTz94BglKWgWBnqo21wYMA6rg0 X-Received: by 2002:a17:902:c7d5:b0:193:62a:80df with SMTP id r21-20020a170902c7d500b00193062a80dfmr13249042pla.33.1673311068580; Mon, 09 Jan 2023 16:37:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673311068; cv=none; d=google.com; s=arc-20160816; b=BjCkSu//KbAtBb5hgMFLVirPjV6/uPaYJ/QFPeiFFfm8kOoz/cF69nwBL1a9oZFdDK rfFdvwJYG5CQZmZRSd/jiMauekYXcL8reXwYEXPj3i+6nqKQ5XZv88/HVbT0neYv6bGh AXRVB07pcjGpeCP7SUz/jZNOctUcQnQ7ss8LsNuYUXW2xnNTcxzhuOKzOwMmRuaCJEik oUu2xYqcRMX+PdYIp4qON+GCGPq0AMdTCMptWd+qM7ePJKkNv0k5JRGSb9Sera2m+BxR Cy20C9BxJdT70Y5Jnkg4jwfUhLA8YiY1Z49FWYJ6TWoT6GiYgL1sDdNr3evjANK9vJN4 4nYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=sgQCt0va7Fj5/9fGcldqaAxXWYK8cBxGZmP9xyPfdn4=; b=sxotBNDE3+lvoNNpWiwZkQcnrYCIK1H3WWVpUeS1cEBXNRM8y0UBIAxEgDxn1hz7zG yg/GnmKh5UobNa1vL2hRA0s+n3TF0iLLcy6JsllPXanSRZMxq9Ga01m59l+o4WOZhCGv EIiAJKFhwssA61e3f/kLdumssYR5rkeomlDf6rdQqRwTXdRuUSYI7k20bQghvtlI9LKP KjET0O6cEheqh8jcp34IiE/YOEtyoZlModUlFtlLIxSXDnXKshd0IaBLmqhtr3sw7yRG fb4nLYgW1du/tCqE85wb6iBhYNkVBuQvcQd7b/BNKMxXg5bvy7uWSZr55pGTaiTwhikN muEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=CjxZ1mdp; 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 u12-20020a17090282cc00b00190fde95ac5si9842947plz.411.2023.01.09.16.37.41; Mon, 09 Jan 2023 16:37:48 -0800 (PST) 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=CjxZ1mdp; 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 S235654AbjAJAS3 (ORCPT + 53 others); Mon, 9 Jan 2023 19:18:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235593AbjAJASZ (ORCPT ); Mon, 9 Jan 2023 19:18:25 -0500 Received: from mail-yw1-x112e.google.com (mail-yw1-x112e.google.com [IPv6:2607:f8b0:4864:20::112e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC48414D24 for ; Mon, 9 Jan 2023 16:18:24 -0800 (PST) Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-4c15c4fc8ccso135051947b3.4 for ; Mon, 09 Jan 2023 16:18:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=sgQCt0va7Fj5/9fGcldqaAxXWYK8cBxGZmP9xyPfdn4=; b=CjxZ1mdpIhqu8VGPVCMoqsbsDlIhqCjEmsPqq5qkb1qszkge1Jm7eoOuPAcP/ZV3bk wPP+sf8id+ynxeTBPKOWQaibXFQF9VkirxIevCIzpGAQ21ueiyMyljdoDpqBwv6iADhp JWDpspg8gxuUz/g8o8f3Q/TpOZXD4wUkStfMnP3bNMTdaoT8E8PrN4XpF0W1y5T9lIyj m9H9otSUCpmNvNlNujrmOWTRlgks+Pwp+EXc1GX8tr1KUVIqmZXacuPH98ZfnNVZNFn8 /a3FCftCVuu8stwkCKaAOtd2Rf8qgv7JUkOT3SOOPfRdmX4H3QpcqFd3fI60DVZdrWVr exyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=sgQCt0va7Fj5/9fGcldqaAxXWYK8cBxGZmP9xyPfdn4=; b=ruseLA4Ny1jYyFmg3lg347mjfAntR2DWermibui18wmaABgCBb6MR93nTtHcHCrUpY qrKWNWXy/a1DVfoXS0HGmCiotSZEAPXPY1iu6TV74TCrhWx2Jmmc7WyporFHcyhjF04/ HVBvlt98Bc7o1t8RXjAeEojKLB4MkqxSc3g/Tku1yPRhnFyvdVW3JdpANeDLLEyKQgOw xzfHP9vpzVLWhslv4weo4Il8H7yzRMho3rC3kbdq7jIPFFchweZ9mUiVjuIcZfWOOSbz l75EN2xw/LUhVZ2rePgywDbDNlld/dA8/K5pcQiCoezd6+lbVJGsD64p2tqS1ueL2LKG n6lA== X-Gm-Message-State: AFqh2kpGNDL1wcGzihChgBxveEjRW9XueZB5ACKVZs2ByxBBi6uKyRRd 6y/wml8ZtQwP2+k1WjKW+05j1yaCwu4Cn10Hu0Kodw== X-Received: by 2002:a81:7386:0:b0:391:c415:f872 with SMTP id o128-20020a817386000000b00391c415f872mr1094430ywc.318.1673309903890; Mon, 09 Jan 2023 16:18:23 -0800 (PST) MIME-Version: 1.0 References: <20230109213809.418135-1-tjmercier@google.com> In-Reply-To: <20230109213809.418135-1-tjmercier@google.com> From: Shakeel Butt Date: Mon, 9 Jan 2023 16:18:12 -0800 Message-ID: Subject: Re: [PATCH 0/4] Track exported dma-buffers with memcg To: "T.J. Mercier" Cc: Tejun Heo , Zefan Li , Johannes Weiner , Jonathan Corbet , Greg Kroah-Hartman , =?UTF-8?B?QXJ2ZSBIasO4bm5ldsOlZw==?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Carlos Llamas , Suren Baghdasaryan , Sumit Semwal , =?UTF-8?Q?Christian_K=C3=B6nig?= , Michal Hocko , Roman Gushchin , Muchun Song , Andrew Morton , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Eric Paris , daniel.vetter@ffwll.ch, android-mm@google.com, jstultz@google.com, cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Content-Type: text/plain; charset="UTF-8" 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, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Hi T.J., On Mon, Jan 9, 2023 at 1:38 PM T.J. Mercier wrote: > > Based on discussions at LPC, this series adds a memory.stat counter for > exported dmabufs. This counter allows us to continue tracking > system-wide total exported buffer sizes which there is no longer any > way to get without DMABUF_SYSFS_STATS, and adds a new capability to > track per-cgroup exported buffer sizes. The total (root counter) is > helpful for accounting in-kernel dmabuf use (by comparing with the sum > of child nodes or with the sum of sizes of mapped buffers or FD > references in procfs) in addition to helping identify driver memory > leaks when in-kernel use continually increases over time. With > per-application cgroups, the per-cgroup counter allows us to quickly > see how much dma-buf memory an application has caused to be allocated. > This avoids the need to read through all of procfs which can be a > lengthy process, and causes the charge to "stick" to the allocating > process/cgroup as long as the buffer is alive, regardless of how the > buffer is shared (unless the charge is transferred). > > The first patch adds the counter to memcg. The next two patches allow > the charge for a buffer to be transferred across cgroups which is > necessary because of the way most dmabufs are allocated from a central > process on Android. The fourth patch adds a SELinux hook to binder in > order to control who is allowed to transfer buffer charges. > > [1] https://lore.kernel.org/all/20220617085702.4298-1-christian.koenig@amd.com/ > I am a bit confused by the term "charge" used in this patch series. From the patches, it seems like only a memcg stat is added and nothing is charged to the memcg. This leads me to the question: Why add this stat in memcg if the underlying memory is not charged to the memcg and if we don't really want to limit the usage? I see two ways forward: 1. Instead of memcg, use bpf-rstat [1] infra to implement the per-cgroup stat for dmabuf. (You may need an additional hook for the stat transfer). 2. Charge the actual memory to the memcg. Since the size of dmabuf is immutable across its lifetime, you will not need to do accounting at page level and instead use something similar to the network memory accounting interface/mechanism (or even more simple). However you would need to handle the reclaim, OOM and charge context and failure cases. However if you are not looking to limit the usage of dmabuf then this option is an overkill. Please let me know if I misunderstood something. [1] https://lore.kernel.org/all/20220824233117.1312810-1-haoluo@google.com/ thanks, Shakeel