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 60DF0C83F16 for ; Thu, 29 Aug 2024 16:20:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D90F96B0089; Thu, 29 Aug 2024 12:20:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D409C6B008A; Thu, 29 Aug 2024 12:20:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C2FE36B008C; Thu, 29 Aug 2024 12:20:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A7AAD6B0089 for ; Thu, 29 Aug 2024 12:20:40 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 723E1120683 for ; Thu, 29 Aug 2024 16:20:40 +0000 (UTC) X-FDA: 82505796240.24.EF08587 Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [95.215.58.186]) by imf03.hostedemail.com (Postfix) with ESMTP id 94C4520009 for ; Thu, 29 Aug 2024 16:20:38 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=qHFy6zh3; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf03.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.186 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724948366; a=rsa-sha256; cv=none; b=GfZxT95O4+aNyVbAv1CjrL1k/SwdfgnXh7GYEunp4S6XykflIcsNlFo3/f4fkS5cuW5XE3 AOk6pn6rpcTWQu8ssZbq7NLIuGuFYgXt5cc7e7oENJwLrEH6GwxElOQFDakniN9KAOwhhV a/5x7PNfxtl03ryW61JxCQJiw5kpuo0= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=qHFy6zh3; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf03.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.186 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724948366; 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=TqnxVaBjgZfealincCR2Zh7tFE8qlNsIgLvhONXdZ1c=; b=IYhvr5IkOL+EOKlzqWYQpMgoCdTzXnLz+MWIocD1z32HFGptuhHYbpVuCJ3XCpOH/ralmm C0sgueIgq1QPkKsXIwxS/6cOTlP6TJ7Hy+HBEs5L80yvVqzc0nT3ly4cd5XucYrx/bDpct /uwdcM+G1xmeVZEjk1JZNtEWlNtchS0= Date: Thu, 29 Aug 2024 16:20:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1724948436; h=from:from:reply-to:subject:subject: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=TqnxVaBjgZfealincCR2Zh7tFE8qlNsIgLvhONXdZ1c=; b=qHFy6zh3aSVycnfwMPa+TGK1S86Y8eGqQ+lER+GugiPaxKDt1qqI5UdERHZKWVvCiRP0uJ mAc/ne4Mph2X8TNL/fp/s9L8udkV8DXLIkPNwe4JgfQchKfQE2x81o0YNdAjhxdcFzEtRz eepH/wLlvDilwHkme1dwivldLtoMDfI= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Shakeel Butt Cc: Vlastimil Babka , Andrew Morton , Johannes Weiner , Michal Hocko , 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 Subject: Re: [PATCH v2] memcg: add charging of already allocated slab objects Message-ID: References: <20240827235228.1591842-1-shakeel.butt@linux.dev> <9fb06d9b-dec5-4300-acef-bbce51a9a0c1@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 94C4520009 X-Stat-Signature: 53wbpjssst3cnstsfk39zzmnxkp4dse5 X-Rspam-User: X-HE-Tag: 1724948438-411122 X-HE-Meta: U2FsdGVkX1+gCFmwL5uniumU6Iqb8gBEKzk0u8MLP9pq6pAONxf4c5AQcuah7vPEdsXDtvdE4nF2CS+b84CXrZEKzqsuMasZi6bdbMUtty2rA/P0GQjLG+gyMJ3DrGu4AH+GhUMzN+hszZUfd6mGXqGsu5/I433OX+rJvaC/LFJqyxgbDKiflgrye5zBzzf3P1uoGm9JpToLmydzDX8AZ2dSficdLCeyyIkuvfAaZW0VkG1u+SsP+d9LPem6OiQvuXiKrhuvDAwgWx67wpREqr5PRYXTSVENzqNa36Kw6aU98XvSMSddXA5bMMUndpj56/ktgDpVxsjB1R8a+in0i3bLSYnnGHs+oKY6tN2NY7T2RIEtel4RI/RomUOBL6qrtovyUsLqUEAdjaJsj2vsjmwPT4iwfnYgm2q3ncyKce5hW3aEaK9DAX4YnshoAGMAno7W7gTjRDNyW3bjG5OayRj7I/xqy021YdnjNIx9Uh2OpKuF9H4HK+GidoY0c8t/SMvfrqUOUkhM9qUPm1/phcTKrLUbO6d9BVWoBO+Nh09rN2apzSDLvxYY8Wz//XPjOF48FP6sGyYWMLoxRW7+4kfdyaeMd4ZHsiUzdtaoRRAccFzYDuI9rWm0CE5J96w0aHbSdOmG2bk8q1v2TkMgvRxjE+K7s92kAc3xNZMUoQBxplskQ0vLN9Bwu0nfiaORdmNzv4BcjgR+GBmm0h1ouA6Ntzr7dlVqW4mzX98uX0Bg+JXxigvLVvJQJkEMFzXyCyGSsJfF1hlp7jj6WrUL/2B+lzNOOBO4Nkvpjq5xOaH0mYkD9nFwYcmxl8ly9rlRs91hRtZUF7r5akrJ9+mO6jz9qYUKObbf9wytQxffkk0VN8ZRp5WWiR/SmMI1t04zcixdUsl4g6R7PxD3Z3D2uZBDJfIP1DL+Ki0Do6VbF6yk7MVI7ESZf41Tt5Tm6XPXZROkLcfdHgTIaBnvQAq GGuF+RtM AI5/9e7Uei6ei3oDgKAED32JsXQCl29cLioMhpUj/Vk/0t5PasuvCdCid/68LkNJQTa7aSUCmy9z3t0YdFnSkOC2sR1MFoV8xDDRXlAiYAerojOvpF4Y4SmauleFvuNeoFumtxnvlIRD/HZcmC8kIis54hK4FO3tLwlzyYliwGdZkQ2ITRE7Ol4SGx9ng8QkzjEAtYMOqfALb845/SUg2RChxZBQYMr29R55/LDaxo+lg21XTHvQezQPIBHq7e64/Knt63b++o7rZQlZIvHn5AZYCwsnuYfY+ZHaFIRCu1e4l92dc7xYvdizIjc/XMCcL3VwRqBmFp0FuXbo= 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: List-Subscribe: List-Unsubscribe: On Thu, Aug 29, 2024 at 09:10:53AM -0700, 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). It should work and speed up the case when we can drop the object before charging. I'd suggest to implement it in a separate change though. Thanks!