From patchwork Fri Mar 1 17:07:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 21224 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp18646dyc; Fri, 1 Mar 2024 09:09:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWv/8KD9QZrloxNnpPukizVIC/+wNgZxbbnWk6UxHa/2eXNYLR3gUNPLZtR/A52fCYpxXo6BmLRE8gTuwKNFo43OKMMdA== X-Google-Smtp-Source: AGHT+IH/i1lWhtMsL5/Nuxt1AWsIXwW0O01+WMtu6YY+NxuTR2wUI7+Y9VZzCTBaudnOcmSpJCks X-Received: by 2002:a50:c8cb:0:b0:566:a235:9355 with SMTP id k11-20020a50c8cb000000b00566a2359355mr1775371edh.33.1709312946692; Fri, 01 Mar 2024 09:09:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709312946; cv=pass; d=google.com; s=arc-20160816; b=w1KF3JUrsHuhbQAt6jRvNnXq4P7oRbfBtn5JXqbRLweKYm3uKEFEBqhq0VbDrFliiF h3lJoycgbgA63rcOOYqe4M07fozR/oOJ2SSO7+rumtBcK+e4zilTcHYXJ7ZHPY2RXyOY lymnm/xv7TEGm69ZhiQahuG8kj2db9Heyvg4cxOnqQ2BxOk5STgX3vF15m7bqYobLakn 1OSRLslyqabI399tvPVSfPtDGzl8lbWCT76b/3ONvyT/Xv2tyxsbIRDoo8JNVkkbUphu FpRj7NjdKz0Q7lGSYFoONCdJcKgHgr8e9pQlLYCTMK53+VV2ngYra7dHLUSct8INQBn9 Y3SA== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88798-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id cx25-20020a05640222b900b00565bede3515si1591103edb.530.2024.03.01.09.09.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 09:09:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88798-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88798-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id A2B171F25B78 for ; Fri, 1 Mar 2024 17:08:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03A8036B08; Fri, 1 Mar 2024 17:07:18 +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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792344532213534166 X-GMAIL-MSGID: 1792344532213534166 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,