Received: by 2002:a05:7208:13ce:b0:7f:395a:35b6 with SMTP id r14csp1275999rbe; Fri, 1 Mar 2024 09:08:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU8JSj9+4BmLC1TbLvFKsZmbWhJ2f4j+SJ9v9BMpQLwy+TwhJrATX3BGMYK0QDsfm9eOCOC28fYLiwqCisZf0gTDGvZFVU0zxPXxGp4bw== X-Google-Smtp-Source: AGHT+IEYYKQXjV3UxDV0GnlTSuPiM4D3bGWEK06B3j5kaHAs/CLCJ0asRc2ZmpQpztm2loxnHTrC X-Received: by 2002:ac8:5bd6:0:b0:42e:b90c:c5a9 with SMTP id b22-20020ac85bd6000000b0042eb90cc5a9mr2563508qtb.51.1709312937969; Fri, 01 Mar 2024 09:08:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709312937; cv=pass; d=google.com; s=arc-20160816; b=vxParosSTYPnCY9ve50KDr1X8b4CqsaUxafpoPXsJ3WlNK150dznJ/TvI/KSD7DJuo STBm1XJD8+NL7J2plheP+qVZMxbXiqS5X2ipJAluDAFZ58T+rama3CkpNZ+x2N/yKk0h N8539ymE6umFt1XqH3MNXClM8lOF1muKzsIjaQ0KcFwqqZxEZz1jIh0B0K9m59iTbUF0 S0Oc5flFgTcR1lFVcR6+gzhe5SP6/kxK9fHbvc110kbS9bZp1tM5LXElU6YLRLZXNWG2 gIXVDPUyGZpQFXQOaVkMj69rwjTA4viOGElD9P/vYpp8gpM7AXSX1HllX0VceSgwk+5r 51DA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:from :dkim-signature:dkim-signature:dkim-signature:dkim-signature; bh=JWL3xLKHsHdlJnILzpkn8H/KWzQeCNwfHWgrgk6UfkI=; fh=WGGwdVVTGLpVYCxjY83qTUlyyBzuw+WV0hgXC1Po200=; b=tAS+V5EXue3cuvNXSaI7l49oa6+SU5yQTLhjGa3Q/Kd6BUThB0qWy80waDoiyD6oRZ io1R2OCdz/oqIGWkFORKGJYouZaUoJyZyQUZx1+8pGvi6vyM48OWQCXXJDSmDL7EQAeQ KAMlcadE9lAcNafDQ8XCRu3+jyuL3SWVVRW4XQYoOWsYI4e8yegAcWgP9mMQFBOCMLOD xeKocMbkU1OESpE4vbJLHcTNjqP1LuA2kaQ5plVdfBg1EBkm7aMTC8UAWecUtWttXwqy LWe+MXCkZ2lIiC8qGzycWlnV2YyUptWraDpubuOnGLSFm95jSW7gCR7oDJUSuPPRb8zy Pk4A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=aEYEwxxz; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=aEYEwxxz; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-kernel+bounces-88798-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88798-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id i20-20020ac85c14000000b0042ece00339fsi1138188qti.111.2024.03.01.09.08.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 09:08:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88798-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=aEYEwxxz; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=aEYEwxxz; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-kernel+bounces-88798-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88798-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 608131C2527D for ; Fri, 1 Mar 2024 17:07:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 71851F9F6; Fri, 1 Mar 2024 17:07:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="aEYEwxxz"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="oWi0rFN8"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="aEYEwxxz"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="oWi0rFN8" Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9789546B3; Fri, 1 Mar 2024 17:07:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709312834; cv=none; b=qD3mBof/dN0pxdrPMgoxfTRH/VZ1nJ+gu2d1lFdKoc+V7xxtIjA1lsczOA8HFHFqH0kT1QiAnrnYNs2Cz5MKIOGfiMLjZld102/pKr0GY9Mvt7ou+civ/9XA9Br03Lek2lqGE0F0WIQ8+v8Md0GSN0KpbhrAAE/WmBewedHLEM8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709312834; c=relaxed/simple; bh=EPPw3Z+THJ8g+UKlbE+3geV2OTp28OCAl/HgN9Xu6M4=; h=From:Subject:Date:Message-Id:MIME-Version:Content-Type:To:Cc; b=fPRkW2+kHgL3kBaDVOWOlI3VnpI3lM1Vt6JaM9Wb4d9AOHF2rg9xgGXiaQckS4hsjX8oxID4FXz/Y5E5feKAzCKcvjcYDnNYu/5aBO6gBFDaOR453GTvM4sIeSnyMjt1HfaNy5jbep1ySCWHg/8hNC2LEYTAJ3BqGLlzHQX2g9A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=aEYEwxxz; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=oWi0rFN8; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=aEYEwxxz; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=oWi0rFN8; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [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 8B827207B5; Fri, 1 Mar 2024 17:07:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1709312830; 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; bh=JWL3xLKHsHdlJnILzpkn8H/KWzQeCNwfHWgrgk6UfkI=; b=aEYEwxxzeymsxCReiwtKQ71aPmw2twMkOHoZrO7gi/hwptOpSO8Gkymp1z04EpTRCFQVWM bTmkCC3Un7JpF+O/+wsvlSByBPoVv48C5l5FsVL4vfXEYggd2iUfQC/CaHBIdhhl+fY3Us VD9IVbnwRmiMXvFLVDfu2vfaXsRrLmU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1709312830; 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; bh=JWL3xLKHsHdlJnILzpkn8H/KWzQeCNwfHWgrgk6UfkI=; b=oWi0rFN8PpclO76dABxGHJgaC0Wy6gmCoQYOhTD7BgCRWRS/Rvx3vzNP2POQckCk36pNAT L7usYQuHj7ceFPCg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1709312830; 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; bh=JWL3xLKHsHdlJnILzpkn8H/KWzQeCNwfHWgrgk6UfkI=; b=aEYEwxxzeymsxCReiwtKQ71aPmw2twMkOHoZrO7gi/hwptOpSO8Gkymp1z04EpTRCFQVWM bTmkCC3Un7JpF+O/+wsvlSByBPoVv48C5l5FsVL4vfXEYggd2iUfQC/CaHBIdhhl+fY3Us VD9IVbnwRmiMXvFLVDfu2vfaXsRrLmU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1709312830; 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; bh=JWL3xLKHsHdlJnILzpkn8H/KWzQeCNwfHWgrgk6UfkI=; b=oWi0rFN8PpclO76dABxGHJgaC0Wy6gmCoQYOhTD7BgCRWRS/Rvx3vzNP2POQckCk36pNAT L7usYQuHj7ceFPCg== 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 5928D13A59; Fri, 1 Mar 2024 17:07:10 +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 al52FT4L4mUcGQAAD6G6ig (envelope-from ); Fri, 01 Mar 2024 17:07:10 +0000 From: Vlastimil Babka Subject: [PATCH RFC 0/4] memcg_kmem hooks refactoring and kmem_cache_charge() Date: Fri, 01 Mar 2024 18:07:07 +0100 Message-Id: <20240301-slab-memcg-v1-0-359328a46596@suse.cz> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIADwL4mUC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIxMDIyNL3eKcxCTd3NTc5HTdxFSzJGNzC8tkSyMTJaCGgqLUtMwKsGHRSkF uzkqxtbUAW4jPNmEAAAA= To: Linus Torvalds , Josh Poimboeuf , Jeff Layton , Chuck Lever , Kees Cook , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Johannes Weiner , Michal Hocko , Shakeel Butt , Muchun Song , Alexander Viro , Christian Brauner , Jan Kara Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org, Vlastimil Babka X-Mailer: b4 0.13.0 Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TAGGED_RCPT(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; BAYES_HAM(-3.00)[100.00%]; R_RATELIMIT(0.00)[to_ip_from(RL8ogcagzi1y561i1mcnzpnkwh)]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_TWELVE(0.00)[24]; FREEMAIL_TO(0.00)[linux-foundation.org,kernel.org,oracle.com,linux.com,google.com,lge.com,linux.dev,gmail.com,cmpxchg.org,zeniv.linux.org.uk,suse.cz]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; SUSPICIOUS_RECIPS(1.50)[] X-Spam-Flag: NO Hi, I have tried to look into Linus's suggestions to reduce slab memcg accounting overhead [1] [2]. The reorganized hooks are in Patch 1 and it definitely seems like nice cleanup on its own. In Patch 2 I have tried to move them to mm/memcontrol.c to reduce calls to memcg code. I hoped to see better performance, but probably didn't. Patch 3 introduces the suggested kmem_cache_charge() API and Patch 4 tries to use it for the testcase in [1] but it's unfinished due to my lack of VFS knowledge. I haven't done much benchmarking yet, just in a guest VM on my desktop for the test case from [1]. Applying patches 1+2 might have improved it slightly, but could be noise. With 3+4 the memcg overhead is gone as expected (the charging never happens) but due to the unfinished state I don't know yet if the separation might hurt cases where the open() actually succeeds. Anyway thought I would share already so others can play with it and see if it's a good direction to pursue (with patches 3+4). I think Patch 1 should be good to apply in any case (after more testing, and review), not yet sure about Patch 2. [1] https://lore.kernel.org/all/CAHk-=whYOOdM7jWy5jdrAm8LxcgCMFyk2bt8fYYvZzM4U-zAQA@mail.gmail.com/ [2] https://lore.kernel.org/all/CAHk-=whw936qzDLBQdUz-He5WK_0fRSWwKAjtbVsMGfX70Nf_Q@mail.gmail.com/ Signed-off-by: Vlastimil Babka --- Vlastimil Babka (4): mm, slab: move memcg charging to post-alloc hook mm, slab: move slab_memcg hooks to mm/memcontrol.c mm, slab: introduce kmem_cache_charge() UNFINISHED mm, fs: use kmem_cache_charge() in path_openat() fs/file_table.c | 9 +- fs/internal.h | 1 + fs/namei.c | 4 +- include/linux/slab.h | 10 +++ mm/memcontrol.c | 90 ++++++++++++++++++++ mm/slab.h | 10 +++ mm/slub.c | 231 +++++++++++++++------------------------------------ 7 files changed, 188 insertions(+), 167 deletions(-) --- base-commit: 6613476e225e090cc9aad49be7fa504e290dd33d change-id: 20240229-slab-memcg-ae6b3789c924 Best regards, -- Vlastimil Babka