Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1345423lql; Tue, 12 Mar 2024 14:26:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXpzzvB8LoI7BjkycAuD8TMJqlfJYqtwqetcW89Hc7M4NjWeeQyPR+yF7ECla+Iw8oZQ6cz/19SgQppJkB2S2LpehvcCVQPa9oaiBr1mw== X-Google-Smtp-Source: AGHT+IEqSHjgmoDe7nEZbrdrNgSuBM4MMbhk9R/jRKpMGiJR6bD8wb5vSHWaEoMSOnm8V0in1AHi X-Received: by 2002:a17:907:7f04:b0:a46:50e8:2798 with SMTP id qf4-20020a1709077f0400b00a4650e82798mr531319ejc.7.1710278807792; Tue, 12 Mar 2024 14:26:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710278807; cv=pass; d=google.com; s=arc-20160816; b=lYqtw9t7RfUzm8ZvE7bacZCGIHIPl9hW9k4ci9aycca95d/yYeRhR3buGNacd1IYgu Eg3psJLHXGikxPnDv3N7RL+dhzTyGjMCr1DrXAo1r2L1TtG/TRD4IYVMqwtHK7ve+Uw3 V8HiyqNFbHOU7/1R7ST2QPRs1Z/sysYA/sVTXP5W2PYauOmfatr4LF0yaVgVM8n29L+j tjE1N64R4kGLSehqvTtNCLPxK64Q/5Inf5XKCo+/kLDRfiRA2OVC5/ryhEmgBsecIMdk o91ybONfsMel3WUdxAGL51xA7lVH9Nj8ES9rPOLz3U5aG8mJAn2ACsj4G9DxhRtV6OOT RsUQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=l7YjmToYxJzJPfPfvLPjqw7S83YnAmsGWN4NCSQKexo=; fh=4JEirlYrX7WdF06fVieGy77nlEIM622gQSx+h6zNDEk=; b=RCNCW3Nj5kqpUW1GKRw/YLEvw+tYYHxSHMbbre0NRMPk3e0h51jltg+sDT+Z5ymbaU pg4CVItiZQsVLqyelmaPc4HxR/MSuaXi7TkMoAzLU9bDDzCtkjhn9zV1tbamUkNrvr1j Hly6AP0gpdyUWfo4lDZmFHUG+Vw2ON7wtof75M5NPg4DHaOuk3Nys2gV4QY2MeasiJTI WoE0YSjio0OHkHYZ9Sle3iVim9AnFFpFi9VGtZd1yKz69whEvEOUEEqcmQ3ynSuI2Lb6 7atgq/pYX9tsqOGd0nVDKJQ+7CsaVxZ2e8QCOEu4s0Pz4Z9Fo7VO2Eqct15EoeWoidOn FFZA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=tfqxM+dB; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-100694-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100694-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id nc24-20020a1709071c1800b00a46029c4d2fsi3653163ejc.133.2024.03.12.14.26.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 14:26:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-100694-linux.lists.archive=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=@infradead.org header.s=casper.20170209 header.b=tfqxM+dB; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-100694-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100694-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 am.mirrors.kernel.org (Postfix) with ESMTPS id A53D01F22FC1 for ; Tue, 12 Mar 2024 19:00:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 83A7714263A; Tue, 12 Mar 2024 18:59:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="tfqxM+dB" Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 044E213A89F; Tue, 12 Mar 2024 18:59:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710269991; cv=none; b=BLrIxVkTrjHxxI5n5oBUwosytze0+ZpU77B+HZMbyQEASIxL6dCcfDcAuhUeRH7nPl56sIFAcki/khd/iLNjre/DSa1tDwD7w2FqR/TXm7chRMgxWjOpK4lvYV43+qZUM+xxEIqwZsRkMTiXZ4gFEklH9/e5YnNp772PLhCUQDo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710269991; c=relaxed/simple; bh=pN850QA4G3vEdGjQiE/SsZ+b17jJ6CTV9AJAa/Pj50o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=D5HmaNnCVoeqe8G5WEhXoUrcOpEe3D9SMeJnDWp74P3P99BJ6IuLvGjzVM+nw/j0aTNWzajyMWnbb11ULBtuY6ZuPJaayDP0ve+4psFsv/TL8Yl1O3yMDbiYV6ZwoJ9AhtRWN8NiYm+1CTNargoTPsqXQItkhN2wOrDNbEXLMGw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=tfqxM+dB; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=l7YjmToYxJzJPfPfvLPjqw7S83YnAmsGWN4NCSQKexo=; b=tfqxM+dBai/CGBKtNFjAO7g/kG m81UQM/6TR+5G7dylh6b4Sh3POGAQ5Cnsify746H46CIFAVQ13xhh/N2cKZlZSOqeWg7REeB1+XxE 7q6ENdm3bqEwiTOVbg22zgyKfItgIsHDUG7qBWEB4K9vgxFIgyGUlNQrb7tQVGIOI+NqEmfTAZ407 l3qsWMigWWO/8FKujwDig+0xETqvRwIar7RtD0zNizs9NrFjjATdRmQSAQtjZyq54u9/FgpvbeEuY rh392WWdoTAovRTxHA7GPUit10/KHiyH36qakY3RO46g02w/SHFSPrrlT3EFGBLrff3rd/DJcr/++ qiIF7M8w==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rk7Ld-00000003gRr-0sAR; Tue, 12 Mar 2024 18:59:37 +0000 Date: Tue, 12 Mar 2024 18:59:37 +0000 From: Matthew Wilcox To: Roman Gushchin Cc: Vlastimil Babka , Linus Torvalds , Josh Poimboeuf , Jeff Layton , Chuck Lever , Kees Cook , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Johannes Weiner , Michal Hocko , Shakeel Butt , Muchun Song , Alexander Viro , Christian Brauner , Jan Kara , linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH RFC 1/4] mm, slab: move memcg charging to post-alloc hook Message-ID: References: <20240301-slab-memcg-v1-0-359328a46596@suse.cz> <20240301-slab-memcg-v1-1-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=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Mar 12, 2024 at 11:52:46AM -0700, Roman Gushchin wrote: > On Fri, Mar 01, 2024 at 06:07:08PM +0100, Vlastimil Babka wrote: > > @@ -1926,71 +1939,51 @@ static bool __memcg_slab_pre_alloc_hook(struct kmem_cache *s, > > return false; > > } > > > > - if (obj_cgroup_charge(objcg, flags, objects * obj_full_size(s))) > > + if (obj_cgroup_charge(objcg, flags, size * obj_full_size(s))) > > return false; > > > > - *objcgp = objcg; > > + for (i = 0; i < size; i++) { > > + slab = virt_to_slab(p[i]); > > Not specific to this change, but I wonder if it makes sense to introduce virt_to_slab() > variant without any extra checks for this and similar cases, where we know for sure > that p resides on a slab page. What do you think? You'd only save a single test_bit() ... is it really worth doing? Cache misses are the expensive thing, not instructions. And debugging time: if somehow p[i] becomes not-on-a-slab-anymore, getting a NULL pointer splat here before we go any further might be worth all the CPU time wasted doing that test_bit().