Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7500290rwl; Tue, 10 Jan 2023 01:23:36 -0800 (PST) X-Google-Smtp-Source: AMrXdXud13jVpqYYUqmlQJy70auOXyvFBn7+PRQfLNcIp/wpIKKU4M7e+/USpB+n4NHxppMm6RsJ X-Received: by 2002:a05:6402:5245:b0:499:bcd7:a968 with SMTP id t5-20020a056402524500b00499bcd7a968mr5017310edd.22.1673342616480; Tue, 10 Jan 2023 01:23:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673342616; cv=none; d=google.com; s=arc-20160816; b=rrYI41bivmco0+ZFLHOxwuqCmkT/B1XIGXDDmvcYJ4ei6UphxSnwdkFxEoCZHrnXJD MNzWx1gg0osRb9TTJHs1+YEIqtHGguQljVa70rA60DHXZqS1J4Nr8UzaDu2IKHky/kH7 uSNKNEIS2QdJE21DN2haA9GKsyzBMk5cS7qIuze4Hf7j9FJca46j1I6JN0W9Y0nLl7zr GhI1qUWFATUe++PGSXu28vu+eoi2hr4Cx26uPJWahF9C1f55xU2sSbAiOdbFkXOZrziS lM1Sp01rA0YhmMJL1ltyHB2wkAGRRnc4Ea04tb6IerzREyesGUkgw1zuf8TkONm6Fvxy oC1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=MQLMOsWeyfQ9OMwOEPpBfSY/zX1K5gLRGoJXs0PRFhQ=; b=FU2xmZr+lU8AxN4E1Nef8FSLbCb0R6C+Np6XBC1+An4urRJmbKent+on12TBiKiBgi iXje4d2srIkD8emy+z7e3p5ugMsDl+FWz+a0uS0bOAeEX4JzIiKEPUKMiwfw3491LqfS fuFVazVjUTsgJOZ29jsqiEJRXqs+4k3/0bnptK+qeE5s6yuX4t6ncMFY5hzaXa6GKA5r dlmfiizayicJxDzKTZ6Pn6S4PPwybFJTwJH5J/E3Hy11iTUjxh6D/VmNBkiQAiG7cvs+ ZkWU4hqQ9o8ojrywFrYflEmtJBRvWM1Ls/imPlOwD/KsvQE2x6+mS2UtDHY+GYcddE7B XyxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b="d0/gJhZr"; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y17-20020a056402271100b0048a05656127si13315940edd.505.2023.01.10.01.23.23; Tue, 10 Jan 2023 01:23:36 -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=@suse.com header.s=susede1 header.b="d0/gJhZr"; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231428AbjAJJBF (ORCPT + 53 others); Tue, 10 Jan 2023 04:01:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238498AbjAJI7w (ORCPT ); Tue, 10 Jan 2023 03:59:52 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 563AF4D71E; Tue, 10 Jan 2023 00:58:25 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4930267AEB; Tue, 10 Jan 2023 08:58:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673341100; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=MQLMOsWeyfQ9OMwOEPpBfSY/zX1K5gLRGoJXs0PRFhQ=; b=d0/gJhZr3338arujv292RDCpaFVCNpNRhfmbIWIBvXye7cZy8BnXDKXCy9uBlP+DXmqzhv vH5AzxAF9dGjzxCxyUj1ty+EwLrjZ3mqqo1g8JsfnV+KA79R00NSzTgm9DNtTFXOX4Gf8S h+jlN7NEV2XA5L/y7LnIoWd7unR8GQs= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 28CB313338; Tue, 10 Jan 2023 08:58:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 36wFB6wovWP/IgAAMHmgww (envelope-from ); Tue, 10 Jan 2023 08:58:20 +0000 Date: Tue, 10 Jan 2023 09:58:19 +0100 From: Michal Hocko To: "T.J. Mercier" Cc: Tejun Heo , Zefan Li , Johannes Weiner , Jonathan Corbet , Sumit Semwal , Christian =?iso-8859-1?Q?K=F6nig?= , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , 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 Subject: Re: [PATCH 1/4] memcg: Track exported dma-buffers Message-ID: References: <20230109213809.418135-1-tjmercier@google.com> <20230109213809.418135-2-tjmercier@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230109213809.418135-2-tjmercier@google.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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 Mon 09-01-23 21:38:04, T.J. Mercier wrote: > When a buffer is exported to userspace, use memcg to attribute the > buffer to the allocating cgroup until all buffer references are > released. > > Unlike the dmabuf sysfs stats implementation, this memcg accounting > avoids contention over the kernfs_rwsem incurred when creating or > removing nodes. I am not familiar with dmabuf infrastructure so please bear with me. AFAIU this patch adds a dmabuf specific counter to find out the amount of dmabuf memory used. But I do not see any actual charging implemented for that memory. I have looked at two random users of dma_buf_export cma_heap_allocate and it allocates pages to back the dmabuf (AFAIU) by cma_alloc which doesn't account to memcg, system_heap_allocate uses alloc_largest_available which relies on order_flags which doesn't seem to ever use __GFP_ACCOUNT. This would mean that the counter doesn't represent any actual memory reflected in the overall memory consumption of a memcg. I believe this is rather unexpected and confusing behavior. While some counters overlap and their sum would exceed the charged memory we do not have any that doesn't correspond to any memory (at least not for non-root memcgs). -- Michal Hocko SUSE Labs