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 095BBC87FCD for ; Thu, 29 Aug 2024 17:39:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7D6E96B00A6; Thu, 29 Aug 2024 13:39:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 785D76B00A9; Thu, 29 Aug 2024 13:39:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B1E16B00AB; Thu, 29 Aug 2024 13:39:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 360BB6B00A6 for ; Thu, 29 Aug 2024 13:39:37 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E0D60A6F9D for ; Thu, 29 Aug 2024 17:39:36 +0000 (UTC) X-FDA: 82505995152.17.20EFFAF Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf03.hostedemail.com (Postfix) with ESMTP id 623A720027 for ; Thu, 29 Aug 2024 17:39:34 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=iQXwmBqT; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=lHOsBi8Z; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=iQXwmBqT; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=lHOsBi8Z; spf=pass (imf03.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724953085; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=knYaAgVRYgshjI/uTZOG3uXVzF6WdqSQAdgmVYbAPhg=; b=aAK/ptRyniRFbug5jMmlnrJxemG6wbO811Mu531xbvWNYyM9ARRzUwvxP37iZDuxObhe9B JLOen4y2ZNJndbHr+EXpuVWaMEZk1d8qlSx4OaFcnPhQR0YYeIl2dehieBtoBTZz14Di8Q 8HBZPntoDEr3m+7VRJTaP2F8VzSD+Mo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724953085; a=rsa-sha256; cv=none; b=sbsc5R9zyWjwqOx0LPCkuIBdcjx4l7qvqqFpjpblt1BvM0G6RGBwq51BH4RPxElebnbCi2 JszyRhCUeQnsS1pQVB7baDVahUKh97JpRoXzLuZXKHXkatrnctTGidwTYE2jbTrgwZ97Or Gkkb7hMOyXVIIXrU0XiZZFvSg+NZY6o= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=iQXwmBqT; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=lHOsBi8Z; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=iQXwmBqT; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=lHOsBi8Z; spf=pass (imf03.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 7308A1F454; Thu, 29 Aug 2024 17:39:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1724953172; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=knYaAgVRYgshjI/uTZOG3uXVzF6WdqSQAdgmVYbAPhg=; b=iQXwmBqTb6gtNnQLpZcv6wOaz9oWVyOmrqO+nCgQdragRwcUpFPDngzsUVg//UQPbksLIs LPSnbyRRy4EZKP3NbrWGbwcLVrlLVwZPwGztnJh6tu7dyDJRzd8F4kSRU2ppsgJo2SisZ4 PwxcKcfZYaRauiu0DfCd0M000f24too= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1724953172; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=knYaAgVRYgshjI/uTZOG3uXVzF6WdqSQAdgmVYbAPhg=; b=lHOsBi8ZqDK3eBDaqyO3bHzw7Buj+HXZBcKAx8nd5xkil7TVzehaH3n8VvfmSaX6hm7TC+ +acazPPRYDFZpjCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1724953172; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=knYaAgVRYgshjI/uTZOG3uXVzF6WdqSQAdgmVYbAPhg=; b=iQXwmBqTb6gtNnQLpZcv6wOaz9oWVyOmrqO+nCgQdragRwcUpFPDngzsUVg//UQPbksLIs LPSnbyRRy4EZKP3NbrWGbwcLVrlLVwZPwGztnJh6tu7dyDJRzd8F4kSRU2ppsgJo2SisZ4 PwxcKcfZYaRauiu0DfCd0M000f24too= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1724953172; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=knYaAgVRYgshjI/uTZOG3uXVzF6WdqSQAdgmVYbAPhg=; b=lHOsBi8ZqDK3eBDaqyO3bHzw7Buj+HXZBcKAx8nd5xkil7TVzehaH3n8VvfmSaX6hm7TC+ +acazPPRYDFZpjCA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 4E47F13408; Thu, 29 Aug 2024 17:39:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 16mzElSy0GY4DwAAD6G6ig (envelope-from ); Thu, 29 Aug 2024 17:39:32 +0000 Message-ID: Date: Thu, 29 Aug 2024 19:39:32 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] memcg: add charging of already allocated slab objects Content-Language: en-US To: Shakeel Butt Cc: Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , David Rientjes , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Eric Dumazet , "David S . Miller" , Jakub Kicinski , Paolo Abeni , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Meta kernel team , cgroups@vger.kernel.org, netdev@vger.kernel.org References: <20240827235228.1591842-1-shakeel.butt@linux.dev> <9fb06d9b-dec5-4300-acef-bbce51a9a0c1@suse.cz> From: Vlastimil Babka Autocrypt: addr=vbabka@suse.cz; keydata= xsFNB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DswL1WAr tEAZaruo7254TyH+gydURl2wJuzo/aZ7Y7PpqaODbYv727Dvm5eX64HCyyAH0s6sOCyGF5/p eIhrOn24oBf67KtdAN3H9JoFNUVTYJc1VJU3R1JtVdgwEdr+NEciEfYl0O19VpLE/PZxP4wX PWnhf5WjdoNI1Xec+RcJ5p/pSel0jnvBX8L2cmniYnmI883NhtGZsEWj++wyKiS4NranDFlA HdDM3b4lUth1pTtABKQ1YuTvehj7EfoWD3bv9kuGZGPrAeFNiHPdOT7DaXKeHpW9homgtBxj 8aX/UkSvEGJKUEbFL9cVa5tzyialGkSiZJNkWgeHe+jEcfRT6pJZOJidSCdzvJpbdJmm+eED w9XOLH1IIWh7RURU7G1iOfEfmImFeC3cbbS73LQEFGe1urxvIH5K/7vX+FkNcr9ujwWuPE9b 1C2o4i/yZPLXIVy387EjA6GZMqvQUFuSTs/GeBcv0NjIQi8867H3uLjz+mQy63fAitsDwLmR EP+ylKVEKb0Q2A== In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 623A720027 X-Stat-Signature: ufod37dhyh1dmsqeyghnz9xzmi6yz7np X-HE-Tag: 1724953174-596186 X-HE-Meta: U2FsdGVkX1/rbR8u06wn6/WJ8mRx0gilfjDMwbvhI54OYnp5tchtbZS/ZJVEUPgtFvWWHf0XLCB4KwNasvCfMPL21+sZ3NLXTY83+wNy+PrmYt1b2G+m8wj4I0WF2p5CofAfCkeC/hbGST/kXAzoBQVfRaI40xiAFY0QcNxdwSa/22imCBVv4ZIEeOJkj9eP7J4s3m4R8QJWBriFQBgUvYQtZCq+sLkObLRLo0+3Llq4OkS3oyjw5cUWAUeDeV0TjIF0forAVM/oXVPWanI2cgrE8BA9nUUg/PMTnHoU96MXKIAtRGwvDKLZb5YJLlangOuM2x66DTCtvTtHGAxd7GnVWRGSzyQOwdloWQJ93JdK0dYIcfsk1YI5HpPvhYw9+zrxMZE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amicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 8/29/24 18:10, Shakeel Butt wrote: > On Thu, Aug 29, 2024 at 11:42:10AM GMT, Vlastimil Babka wrote: >> On 8/28/24 01:52, Shakeel Butt wrote: >> > At the moment, the slab objects are charged to the memcg at the >> > allocation time. However there are cases where slab objects are >> > allocated at the time where the right target memcg to charge it to is >> > not known. One such case is the network sockets for the incoming >> > connection which are allocated in the softirq context. >> > >> > Couple hundred thousand connections are very normal on large loaded >> > server and almost all of those sockets underlying those connections get >> > allocated in the softirq context and thus not charged to any memcg. >> > However later at the accept() time we know the right target memcg to >> > charge. Let's add new API to charge already allocated objects, so we can >> > have better accounting of the memory usage. >> > >> > To measure the performance impact of this change, tcp_crr is used from >> > the neper [1] performance suite. Basically it is a network ping pong >> > test with new connection for each ping pong. >> > >> > The server and the client are run inside 3 level of cgroup hierarchy >> > using the following commands: >> > >> > Server: >> > $ tcp_crr -6 >> > >> > Client: >> > $ tcp_crr -6 -c -H ${server_ip} >> > >> > If the client and server run on different machines with 50 GBPS NIC, >> > there is no visible impact of the change. >> > >> > For the same machine experiment with v6.11-rc5 as base. >> > >> > base (throughput) with-patch >> > tcp_crr 14545 (+- 80) 14463 (+- 56) >> > >> > It seems like the performance impact is within the noise. >> > >> > Link: https://github.com/google/neper [1] >> > Signed-off-by: Shakeel Butt >> > --- >> > v1: https://lore.kernel.org/all/20240826232908.4076417-1-shakeel.butt@linux.dev/ >> > Changes since v1: >> > - Correctly handle large allocations which bypass slab >> > - Rearrange code to avoid compilation errors for !CONFIG_MEMCG builds >> > >> > RFC: https://lore.kernel.org/all/20240824010139.1293051-1-shakeel.butt@linux.dev/ >> > Changes since the RFC: >> > - Added check for already charged slab objects. >> > - Added performance results from neper's tcp_crr >> > >> > include/linux/slab.h | 1 + >> > mm/slub.c | 51 +++++++++++++++++++++++++++++++++ >> > net/ipv4/inet_connection_sock.c | 5 ++-- >> > 3 files changed, 55 insertions(+), 2 deletions(-) >> >> I can take the v3 in slab tree, if net people ack? > > Thanks. > >> >> BTW, will this be also useful for Linus's idea of charging struct files only >> after they exist? But IIRC there was supposed to be also a part where we >> have a way to quickly determine if we're not over limit (while allowing some >> overcharge to make it quicker). >> > > Do you have link to those discussions or pointers to the code? From what > you have described, I think this should work. We have the relevant gfp > flags to control the charging behavior (with some caveats). I think this was the last part of the discussion, and in the cover letter of that there are links to the older threads for more context https://lore.kernel.org/all/CAHk-%3DwhgFtbTxCAg2CWQtDj7n6CEyzvdV1wcCj2qpMfpw0%3Dm1A@mail.gmail.com/ >> Because right now this just overcharges unconditionally, but that's >> understandable when the irq context creating the socket can't know the memcg >> upfront. In the open() situation this is different. >> > > For networking we deliberately overcharges in the irq context (if > needed) and the course correct in the task context. However networking > stack is very robust due to mechanisms like backoff, retransmit to handle > situations like packet drops, allocation failures, congestion etc. Other > subsystem are not that robust against ENOMEM. Once I have more detail I > can follow up on the struct files case. Ack. Agreed with Roman that it would be a separate followup change. > thanks, > Shakeel > >