Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1319816lql; Tue, 12 Mar 2024 13:35:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW4QFcHteGVZMotQZS/sQ0thvMZk2Rt0lEUQ3kUeNIBEw8CkSmLt2hQTTLgNL++igp48SBY3PRHkEjrpkP5vYG+robZdHwo2nOUE4GqgQ== X-Google-Smtp-Source: AGHT+IECBXPJGSOAciz7mat7vOberDlWLwtFnEyQSEljUoct7CSaGXhrIx40CmiIuRuyDtpznMlu X-Received: by 2002:a17:90a:6c42:b0:29b:b4a1:4f1c with SMTP id x60-20020a17090a6c4200b0029bb4a14f1cmr7494065pjj.33.1710275730658; Tue, 12 Mar 2024 13:35:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710275730; cv=pass; d=google.com; s=arc-20160816; b=GgAMxc8nhcjAS3UaDc5cn87gXKE0A1AQgQ5h6+0+uH9WganZ62jyPYl8rqQfYmOMcU mjQb8YNgZRGRCbbhrraDaYbBAUumIeyxhPdRK7tj4kBlouYSReFegkZUQ0KL8w+gife8 HnaSyb0u8qE10aCb8pWJ8QG1fh90pBnK7XdsciL4MNEJUtI3p34axCrMSUpbSVfCyEb5 lvNxyflpSIv2V1gd4h+hZWDC4yN9/WYu4oSCv6VgBZ6nImURaa8g+73YS/jLZxvO/FKO 4NfDo/xlxKXm+xQJBZN1hjkocsEJRyP8eWZoLyYDrMUQ5vPi+cMvzVODGnBIDl1gNBTY o6GQ== 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:dkim-signature:date; bh=Ie4azhdaO7XyuGP1SvLiJCvS/cPbUc5GBchc5hu2vaM=; fh=d5CJin65g/YiV13usw7cZOQBEBMQ+vqy1DNr2TBgH/c=; b=fOlm5mr7OStV+QJLkx/Cco+pWjiGRK8CZt6LXT6SOP3H6KdRTSXT4kxgfDis+o1KEo l/WkhB+3Siyq39poIFoWDzEuEBKRDkXsbVByADMdGGqhGsV3TylRiQg792siFQRGM2Jz 8yqor1gM7S9B3cheRJ2Ce3DaceqXZyXQjYKf9xULW25HwUrDsNNwpaN4YVFYa1P5g+sn 3kdkmJ5uU/x5O1GwsNDHFXF0L0yV3hkB24fGbgTLo5Wz+pjdSzRK72GEhZFYYQ6BQFDg lSP4Mc/Ue/EFq4H/ZCkKP7EiVrWevbSl9j3ifdhcLJM/NNxXdVNRCLUIvW/M84SB/od2 qJxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=sMCEXAm5; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-100767-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100767-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s9-20020a17090a440900b0029ba77412bdsi15394pjg.52.2024.03.12.13.35.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 13:35:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-100767-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=sMCEXAm5; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-100767-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100767-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 587C0281C5B for ; Tue, 12 Mar 2024 20:35:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 886E114291C; Tue, 12 Mar 2024 20:35:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="sMCEXAm5" Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (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 E1F0B382 for ; Tue, 12 Mar 2024 20:35:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710275724; cv=none; b=ifpGALLiVAcxtYAUrFeXPmdxHipauYL1yYu9SsZHK6fogh0jMFrrAw3YrQUqcL1a/PPDf13FGpd+fFGmtAQhu4MdP53E97JA8ijwCGSe+7eOuvcui5IWpveebtYKZ93J9glRCxzaAxTyEo/KKmXwhMcOM7P798KSyYsFzAJqh3g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710275724; c=relaxed/simple; bh=KXsVonS76Gx1v4lFtZ/aoukbRIl1jUwSZIPUAIXbK9M=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BAbFfVwy26/XJ35lkitKhLoaNX0XZyx8413FgWodruqkEZtWxDd6GCCFKBPNHn/OT7XkmlGPshP0tRgtMwz20VeYqvzF42sc1ESGBTaQxm/Vs+NxBGz9yPJnHZD5ORTLvNfS9X9QEAmTaVbMuNf6oGoIH9LPurCqtPFrB12EspI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=sMCEXAm5; arc=none smtp.client-ip=91.218.175.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Tue, 12 Mar 2024 13:35:12 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1710275721; 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=Ie4azhdaO7XyuGP1SvLiJCvS/cPbUc5GBchc5hu2vaM=; b=sMCEXAm5xCpiFPEB39C6K1DXlo0Ho5H5L+dlH2uLxMvPdEQRsv99r9YtsgCv9WgRZqG4tL VxNUGBPsCa75bzqnUBFcy8TdrLlI57sU+4v6e9SdmPRfHtG+pEdA9/AWeUgtroM6lfBmcw O4nP2IRw0rf+l+2B4fx3Br5iKQE0IwM= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Matthew Wilcox 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: X-Migadu-Flow: FLOW_OUT On Tue, Mar 12, 2024 at 06:59:37PM +0000, Matthew Wilcox wrote: > 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. I agree here, unlikely it will produce a significant difference. > 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(). Well, Idk if it's a feasible concern here, hard to imagine how p[i] wouldn't belong to a slab page without something like a major memory corruption. Overall I agree it's not a big deal and the current code is fine. Thanks!