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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC2DFC54EBE for ; Tue, 10 Jan 2023 00:18:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235639AbjAJAS3 (ORCPT ); Mon, 9 Jan 2023 19:18:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235654AbjAJAS0 (ORCPT ); Mon, 9 Jan 2023 19:18:26 -0500 Received: from mail-yw1-x112c.google.com (mail-yw1-x112c.google.com [IPv6:2607:f8b0:4864:20::112c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE4E739F8A for ; Mon, 9 Jan 2023 16:18:24 -0800 (PST) Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-4d13cb4bbffso14778227b3.3 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=1QUmBkLQEepW2X7ua5oZsq2VVT4H6IU4TWZc1ebOVmi/4RVfHkxN30UNJN+j2gQ7dY 1XRpMGOC3kCsuAoNLuOJueuuFOa6y56RIiQ03d5I3f6grhMOsosjQ30p1llc/afgoB+y nrQxGvzPL2qJ0jMZYYeAHvuYmVSNNHyFjGmALV+cDdl9e2UCSxXQYQefgm30QDFiQ9r1 5bvOdJrdHxN0NqM7uWH9bE7oijamSxFhaxP4smyJVMx8a6GWqxPW8VKA7wEKL2YZ9/ig MYrA187an/TOJxae0pvyzLrrw9lrQXMhN9xFtmSYWp35mbHYrM2Pm/Se73tn8awNcp/t q7/A== X-Gm-Message-State: AFqh2kqmJXZVQXpQ+iRtkUi5Z00k+0caIoTjhE3KnuhPM8kj4wvTQCTY DaRw6dzyU0yI5/yHfK/rmnY2iuhZA26U489ncz7+sA== 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" Precedence: bulk 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