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 695D5C5479D for ; Tue, 10 Jan 2023 00:18:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C824A8E0002; Mon, 9 Jan 2023 19:18:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C32388E0001; Mon, 9 Jan 2023 19:18:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD2EA8E0002; Mon, 9 Jan 2023 19:18:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9F28D8E0001 for ; Mon, 9 Jan 2023 19:18:26 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6972E1C7193 for ; Tue, 10 Jan 2023 00:18:26 +0000 (UTC) X-FDA: 80336977812.21.1D762FB Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171]) by imf17.hostedemail.com (Postfix) with ESMTP id D939B40015 for ; Tue, 10 Jan 2023 00:18:24 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=CjxZ1mdp; spf=pass (imf17.hostedemail.com: domain of shakeelb@google.com designates 209.85.128.171 as permitted sender) smtp.mailfrom=shakeelb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673309904; a=rsa-sha256; cv=none; b=7lpODS7RBxQougkNzIrOa2eYZMPe1VfyZyGn+4roRintRzP5MmkHqARLj488WWxYi3VRxc LnjXWfS0FIIOYrd+Fh+lnQmbgxd2y/nUgzUccArhCKAnqHn+3ESvyy5Tkqyg/2PNSmYfKp fPt2/h/rDpE0q69Jepgh5WqRRpE0SkA= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=CjxZ1mdp; spf=pass (imf17.hostedemail.com: domain of shakeelb@google.com designates 209.85.128.171 as permitted sender) smtp.mailfrom=shakeelb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673309904; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=sgQCt0va7Fj5/9fGcldqaAxXWYK8cBxGZmP9xyPfdn4=; b=myxfEC+v2U8PZY5VXxXo6cMmGzXXtFR2eeStMrUn8GuwAE0p3Wj91EVAPsfXfcC6HkB7fV mzfSL10diDzCZmIY65KQBHOlbC7/XS73yDBgELLsHDQa4707GqAYl60QCi6V4zSmtOJSf/ v43huZXakirNmBoC+dm3cndhHlDTm9w= Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-4b718cab0e4so134956717b3.9 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=pE+ra2IxkBtJ2JxlTvdZ2Tu3lC6dg5mPBqImXKbZWReQw7/EmMAwhimCv4Bbf5Q17Q 9JdIi45Brq2EYZGf3xO1fPyO/GkeX5HVbYoP5k3e6FDbu2NkfKtQp0C05vO8/KcYfYFY Zjkedqe5Vtcx8cy+y+1HU+OiL1G7d1rFJN1AXkzrDi4PUBfHaY5sZsUd71LVzObIwX66 v+IDhJHl121YDNxZuVBHrfnPRvFIdE51wH4MCOEuRqWTko32mJz1lV8jaib1UW70ss5l 6WXKtrdro9gLykvsvgPr42K9my6v4PJHmcAgy9p+s9NCobFmbk4/jRKBmcHUBhjo4t3e nxZQ== X-Gm-Message-State: AFqh2kogenhcY7FJadecmh+MkvroAA2r25t9jmTntVz/HF0Kyi3vgJIj +MJL9bQq2BN8zCDjovvjBtCzOeH/3+V9gyDbS/wNWw== X-Google-Smtp-Source: AMrXdXvykUOk6Aq29zKPFweeZ5QLOqVr0VtGabuLWKsdUabDXPvAWtUyFW1w97fkSV+2AQTk/rtQ4CJ6GNWf2U6U44A= 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-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: D939B40015 X-Stat-Signature: iht49rwdnattx11yr4g1f1fw3wr1gth1 X-HE-Tag: 1673309904-52002 X-HE-Meta: U2FsdGVkX182uG3OnmstY1bznJSmYTfUrELxWvdYc63ZzKhx4uwtb1nCFpUrYoO4Js6RcmZKoqPrYXg/s/HOZ4IBplNtHN91KZ8a3QTMXu0CKV1vWFbQgPihtm5Ih8BNpq5XuY5nxEbItFLH0/QYHFSuhZ861W/5SVfuazT+2niJhVj/jGpM0+/k/YMXauPF0dJ/2pem3e7LIJwgiSfppbARAOT7R2psxnZMh1codqyFUG0TY0Js+ghqiE7BKdNOTG+ynOj4ZOIQO/CBaftBVl74jqU3TULkn+pLsmbmKKXAcvq54F7AI9VhAH5+Slp1YcghPFqN9FopnfvxqlKCV+M23XbkPR3i78f3tw1a9KE4KBPZjzzH7i5ymQPttWaG8KFm6UeYVx2dBLBwDD6VNOMJ9X3MTeKySLhGBEPvwkWoieeweIxUYkxp9xWtozsP5efd2zpd1YiLnkVPsNxBZ4ItYUHIz5riygaeXRr2e98id9ZblFLogppA/BZrAzpMEmAUw1KW/MUXZxjvCWCN1nnEy7QaxvaQcB9goFleSDao549+JrvxSAZq4EpErpzZxdcY29qf5oz0hpx4bh2wI8J+tmEJ6TyGUL8AHdCNjh0btaEyuscIcWqOCnHd+c2vLOL9lHcLmtEcuvhivOk2RGazfnZmdlszYAUAZPygykRnp/3wlVEkr9iwcsrwnOlyOE66abePlpZliY7B9XJnu8y4b/l5wg0wGYJ8Ibgjk2v095idTq82/k2t42JMOoThQJRZ21I9KOOaDnFbRZjlIDXI/ASKjj5WvM0Yz6YI5XJGrrBcUg/8mWFo6LKMGkOq2Jqk/GZfNFzZ0iy/k6ugujTxVPMDzljkH5p/4jP58r090ti/Z01DIROS3jXbFabTbXdjVCdvA4m41o7d59igcS8vXKBnlyF6rD8lY9bmSjVbjNFaXN9WeO3YzfSaFB3QocgvvW9rfK04Y9wHBGu ar9XMFO3 DuXQlL+TK0qJ+uSPddcq/bwAVuFZ9WYaL2st44p3233lmX2w3XuAt9rA19plMv7Lah22bzid/U8kOHt9XZj73U2T6SA== 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: 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