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 4D89DC54EBE for ; Tue, 10 Jan 2023 08:58:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B283C8E0003; Tue, 10 Jan 2023 03:58:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AD8208E0001; Tue, 10 Jan 2023 03:58:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9A0098E0003; Tue, 10 Jan 2023 03:58:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 877A88E0001 for ; Tue, 10 Jan 2023 03:58:23 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 46B3CC0817 for ; Tue, 10 Jan 2023 08:58:23 +0000 (UTC) X-FDA: 80338288086.13.7CB7249 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf15.hostedemail.com (Postfix) with ESMTP id A4F06A0007 for ; Tue, 10 Jan 2023 08:58:21 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b="d0/gJhZr"; spf=pass (imf15.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673341101; 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=MQLMOsWeyfQ9OMwOEPpBfSY/zX1K5gLRGoJXs0PRFhQ=; b=IFwhUm4mGTQi3XHx+kTr6OM1mlpC7BkDWQ6W0wKTL2LzXksJS4mk/QvIvuqvgL1Kflx3V+ nK+EXOvykYFmSGpQRD00fOPdOxKRBpfX1fwcrRocKsmtPtvK0JGIPZpPsn5TvdzCk9ucHE 5BpudsMqjt+PqbXjD9URy2LZoKMl+tQ= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b="d0/gJhZr"; spf=pass (imf15.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673341101; a=rsa-sha256; cv=none; b=Uk7FT6FBYG04gaf+aO7D9ilxIxx5FkPHsHGPCrn0Tmfcan4g5A7JzSW3a8nQfhhTJbWPNU J0m2vFx1pA3+l5qX6Ntof9btC5gsNcKk0vvrXUh2QqVSb5ewiu/KK5bLodtGHcMsDqP0q/ EQDk5ZWUBnT4evfMyQc2s22pbdy8+0w= 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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A4F06A0007 X-Rspam-User: X-Stat-Signature: cxikcz14smsjf8rseowx3oz87389csyr X-HE-Tag: 1673341101-155997 X-HE-Meta: U2FsdGVkX18yChuJyb1khmBi9hwQ1rjNCC8Suv0pZHCIRbjKPxMQR/zMNM14F7zWe00A7H9EI2tRCGGd5e9n9xDXY9ucvwvtyqgElBxTv5K3cnah7FYoXM5AwtcjAKMPnnqDEEKT9Mi6L1Q9AkcuKjJ0AuB6XOMUWCJbPvOae16XmgcyCwtF6Epdc5voz9TsbZ7cFrwbnIXTnuwyL61y+uqYqGMvwUlahIrQSGJTrsFzGCzVAfkEAX0bLpWkaKKCWgG7DpKXVV50wGpJG3yjKD1/FcrH3XMOwVfAsfxe5n2KMBW4n/wwrEmUG5vlae5mXWGHN3IQODONtZvwJ+NC1V4wSghnZMDSQgw+xBb845B/acafv9IHtlNKx4wMF7yxcZ1Y63FcgqDktog6Ipq103I5EqI4QoccOgQTe/nbcf85QMigLeVb3LtJKJ6yTlgYAxn2Xdd2JqtqSD3hl+fL8FBfz1Q3M4Z/iV+QWnBmosEoFpmGIgct0Gac8W8NGDNpbbN+ZP8YVx/4oY24u3pVMg8+981xelkaErf/3qELAPh2oTXKYALWB1wfARddveVY50RvzKWvzVAciyVbEqos6bG5p7uJYy9L/dGcMmEej5T4DkAzBkFExTCP+V7q8CYU5nNW8VTkYgWNDM2SCsdawnaBhD1Cg7i3M1bJYVybHCjkRxLTQ7kHSLKo3umRyOG7ClEdcV1JwpA0tBfPUjo/jlpofBlz4nLyyLylOtOeoCt5JjfCCSgxaFYnkbK0t2mhiipSrG7zgNAVVu+0D3Lmq+fBWMvKFIQqKox+mfr/LgL8qVnVXqJRPJk4BBxY8K9e1yNND6RdfKRsAxfdICjvbxDdXf537qVvvxapB6bhyQ2PjkwE7FPPPQ== 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: 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