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 735BDC282EC for ; Tue, 18 Mar 2025 01:20:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 483AC280002; Mon, 17 Mar 2025 21:20:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 433FB280001; Mon, 17 Mar 2025 21:20:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2FDCB280002; Mon, 17 Mar 2025 21:20:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 10DD5280001 for ; Mon, 17 Mar 2025 21:20:20 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5DCC216028F for ; Tue, 18 Mar 2025 01:20:20 +0000 (UTC) X-FDA: 83232916200.17.B33F66B Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [95.215.58.176]) by imf25.hostedemail.com (Postfix) with ESMTP id 813B2A0008 for ; Tue, 18 Mar 2025 01:20:18 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=U8qOLmA+; spf=pass (imf25.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.176 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1742260818; 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=+vpwPHrf20lSWnkzGhdqIPFZKWwfBUMFQHDJp14oi8M=; b=lgnYUHCeqTGDnWECMYZvPHuaI81DoF42uxn/S7bv5JFJgwdbDoyZ9Erfm9/XAdaxn0/C1Z li7wMvv7QWNChNJNFC0IReMAy1IPztZXWUx+wx2PSsRC+JAGM3r+lsr0OsU69Cpd+KY8Z4 PTQCmLTZ7+LVcZjtC+nbsKTwB0P1Tyk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1742260818; a=rsa-sha256; cv=none; b=hsRdyQA8xczQ78h+vTDk2Md5M4CrpNJHxBBF3UQSJx9OiAUFW5TvvbbXGXiJqqfByBvEjD sSAPe8g/Aj5fbX/T4bAJMPTpbw8Im9Bk4dQUkKaSh2wqdg+kSZa3OlDQzmBdYh4hgygsKf JShjsa8jKgpVMVNhf2kFj99dWL9sRLY= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=U8qOLmA+; spf=pass (imf25.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.176 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev; dmarc=pass (policy=none) header.from=linux.dev Date: Tue, 18 Mar 2025 01:20:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1742260816; 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=+vpwPHrf20lSWnkzGhdqIPFZKWwfBUMFQHDJp14oi8M=; b=U8qOLmA+CT7DQ2Jg5YUmxUs0T3NNLq9xr+yALISTNzUP1Q8xMThUfPIMAoAY8Ml45RRB08 /Fhu3IQUMZ//yX5o2IYqitzyY9VlilY3csrYJC6kG/Hfn4Z5fGCI5aWuDjfZAsKWfsGX11 9aUwTeUnLuWIewKUBUL6YiLMvlENnUI= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Shakeel Butt Cc: Andrew Morton , Johannes Weiner , Michal Hocko , Muchun Song , Vlastimil Babka , Sebastian Andrzej Siewior , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Meta kernel team Subject: Re: [PATCH 8/9] memcg: combine slab obj stock charging and accounting Message-ID: References: <20250315174930.1769599-1-shakeel.butt@linux.dev> <20250315174930.1769599-9-shakeel.butt@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250315174930.1769599-9-shakeel.butt@linux.dev> X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 813B2A0008 X-Stat-Signature: 4p3kjgx45pba6oxmy5nbfb8q4es3ixbz X-HE-Tag: 1742260818-710493 X-HE-Meta: U2FsdGVkX1/VKQD5vm2ggnHtZ2a49+3Y1mE6ZQhpM46DsNaRuxLqp68F3/k9CdOkBi8hwiln/thj78wHLaNp3MdFI0mle4CrnntP0Ze/tb2sU0Vds8f136VwP1NTPCguiEBSZvSJDDjuQJKoMhUs0vgNLsxG+L9Ih/jcKzegXXvhaPWQz/wN/kG+C+44VCDGnh5ofLKMTjXDH+MMxKBsf1mpUgpkJvtWYpXZoWJYAYH13cui4bvDtgM/22tXmM85tBTqfgDusZR6bczju+XNhqe2prfq/0ekSkfMJ/+FPdlnmMUZc5Udzl3zYHD2a1M+c0ac9ga3jvHAbzVpE/pXWVAxrf9dOuxB6mI2FVqhe4j/beg0j9C8G5Kg/awzy82y+CaaHPfBkvfUO58A2ajtL8cocRsN0qFeTlz9HK3pCUyLsQkw/6pMFno3K5pQxcm4SboZRVMJaLaLRIz8wK6jic6zr4Jw8aZO7N3de0i6ImFhRYA1/Ve/BQulBItTH1dZTPKX18J2XXBRHdZYDQkJxW9i5SwqSItYmusy6wxMD3P755pWH8W0U7TyAtUAGdGtYFow0sxIsGLKFmHOSTTVsuzjuP56UBn52ZEvTCAcUJrIWdKdYrS+N5QHUS2HKvaPjpHaJ8Nu9eyGcGux/BP0ozIzev6Qb+gfcqBYJCi2ZwtkDZJLKKTQlri4AvoqssEvMeM7UwmDCpdTKMGuZBKBYadAKsP2IJUHCsQ+Rojhd/wyFhrchVlY5k7Zy7xMkajHlOZcp2mS1jZgyqNxF7mOHfbDqI0yzv0h0jF3DwYbUfFkHvGSU4qaYxu874yoQWnvWfX7POxm48Uw8Dk0VznESFKJe6yHmvzWMri9u9KNz/zMoX0S9pzinuNPbrgW4Kx9oghRtCbE2CUeao2mh0L4mfJmKvG9hEcVzrvg547eG3y419s17eSUd4C17zSzCmTMMGgSwJdcnsr5Z3tn+No ewDa3GAJ XXUwPyXLSMUT2edErlUUkSKleup3kGF6B/8Y1YwUCX90Dt+E4N1tfyAtqfafPd/kYdNegbh9jMHpOMBCiDQuvAjljdeN9Ckz8i/Y8DtpnND4qBXhjEjc+EKBaVo2enTkrAGbqQo/AMjxY1AjvJztzcuOFQ96KoRfGaJa/6rSEhvg1fR5wGu+epqAqlIBAQQzwWWDFSv2Y9TzYLFyexaWCOnuP5g== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000008, 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 Sat, Mar 15, 2025 at 10:49:29AM -0700, Shakeel Butt wrote: > From: Vlastimil Babka > > When handing slab objects, we use obj_cgroup_[un]charge() for > (un)charging and mod_objcg_state() to account NR_SLAB_[UN]RECLAIMABLE_B. > All these operations use the percpu stock for performance. However with > the calls being separate, the stock_lock is taken twice in each case. > > By refactoring the code, we can turn mod_objcg_state() into > __account_obj_stock() which is called on a stock that's already locked > and validated. On the charging side we can call this function from > consume_obj_stock() when it succeeds, and refill_obj_stock() in the > fallback. We just expand parameters of these functions as necessary. > The uncharge side from __memcg_slab_free_hook() is just the call to > refill_obj_stock(). > > Other callers of obj_cgroup_[un]charge() (i.e. not slab) simply pass the > extra parameters as NULL/zeroes to skip the __account_obj_stock() > operation. > > In __memcg_slab_post_alloc_hook() we now charge each object separately, > but that's not a problem as we did call mod_objcg_state() for each > object separately, and most allocations are non-bulk anyway. This > could be improved by batching all operations until slab_pgdat(slab) > changes. > > Some preliminary benchmarking with a kfree(kmalloc()) loop of 10M > iterations with/without __GFP_ACCOUNT: > > Before the patch: > kmalloc/kfree !memcg: 581390144 cycles > kmalloc/kfree memcg: 783689984 cycles > > After the patch: > kmalloc/kfree memcg: 658723808 cycles > > More than half of the overhead of __GFP_ACCOUNT relative to > non-accounted case seems eliminated. Oh, this is huge! I believe the next step is to also integrate the refcnt management, it might shave off few more percent. Reviewed-by: Roman Gushchin