Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1275140lql; Tue, 12 Mar 2024 12:06:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUBy9KkhBqqsVoJa0YoatB39m0bqdhJAmuw6SL3UU3d2qPdL9xBeBrDabJc/FJ6J6vozr3SYwsjzC6RTGezYrHCs+QkiKIkN76NCnh8lg== X-Google-Smtp-Source: AGHT+IEvhbi+datPGcDaxnc4MKsNxp/UsL8KqV1wQagjzhMzN8tD5OIbId+BF773+9VKtjQ8w+uU X-Received: by 2002:a0c:efc5:0:b0:690:fed6:8004 with SMTP id a5-20020a0cefc5000000b00690fed68004mr1710646qvt.29.1710270362289; Tue, 12 Mar 2024 12:06:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710270362; cv=pass; d=google.com; s=arc-20160816; b=uOCh6TX5D9mhtQPuyzbjWW4A2pnzOIMsahvZyNffNMjKehg/CETmX1u7ljxQTlpf1O A6IzEi/NGpJZ5lDmO1Hj+2ZC2tWP6EmoBSp+GWC39dx1AEg8xYHccRZ5P1RtG7SHQFnz 3MoSPuiJIFnzOeOUiab9wFdijdcn1J3QU35FzGR0hqvzzwiaTVQITG1w7I8vDrid50n2 +T1vbpYXqcGo2esCNaC8+vYK327A+xf/5nepGQIVkFb5PaeA0HylEEfNWyMu3CrUs8QA 6baKw1aEGcc94+RlsgAE3mOKAxm3Cj/50bjvaOb2TskJ4emjEVBZtfBBt5JiJIDSvvCh FsHg== 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=i2n0g7ELC5Jfz1aF+KhbZXxiuizO3RE1y/QxbejYQSE=; fh=t/Fx4bd8LLi3HWU2sF5dpgPrJabsC3sJzE47VeTuJy0=; b=LMFjVAvigEBkELlRiD/YBM3A3efXe+jt0jlCrECIyqI+KextAhfsCgwuMVkJJkVzJI 5Rlbq4Djvndqdcwhc8NzKS9G4R+wohOG5gcL/PiAz2O6BKg1nxun8KSEJIIn1hT7E5dK DdislSC+YfFge7cSXe5ZxNFdlWKhQSM6fAIbldOessrWuFCIE2Ot8Wtc99LIQE0+v/5A Zj7f/8Xjw80YRYEAo2vXVhzwCCwQ3wGS5J8v+YkEBLYspA9G20qczdYtIgUDo2eKiiuO hCAeHelMpmlBDHPFkewM7qriD+4wsjr/ylHfpUBPH9TsoB2RoZKSyfegZccrWceciYFs SdrQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=HHyhMGPR; 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-100696-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100696-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ey1-20020a0562140b6100b0068f2cd94c5esi8265295qvb.346.2024.03.12.12.06.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 12:06:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-100696-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=HHyhMGPR; 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-100696-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100696-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id DE3BD1C2268D for ; Tue, 12 Mar 2024 19:06:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E15C214263B; Tue, 12 Mar 2024 19:05:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="HHyhMGPR" Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (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 6F0945914E for ; Tue, 12 Mar 2024 19:05:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710270351; cv=none; b=hnnGJMTW+KluqOTUi4Qatc9a8SwhdCtmwJWr/gsjvcAM00Cvle1/gz1dRZJElQsSKV+b0Yu618f8o+5dblAoXRZoPknH82GhBno3PAxa9XC55FhmZB+4AahYP8kFjjoYRvk26K9tkmEc5I2XmmLvO+vRh4aC9oWMGvAjYxJFLM8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710270351; c=relaxed/simple; bh=2FpORzEzp4d+kBzYQcXfKFJJI4OP8kz4CQKscqTCH2k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JNGEhh3h4GcfDCniWGjDC8OaXaMGVRHyVcyWAj6vA7c5sH2z80870T6bPizrT4tWkyNLo+pUU15w2Dm1Sb/OHBL9mJd0edM0aPIQzdh6y42d2UgBdVagBLcY48ODYGDqn7aQXXX1ZWRlwfMgyQ+47GlyvOaU0BJIl7LKXb3rkuA= 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=HHyhMGPR; arc=none smtp.client-ip=91.218.175.170 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 12:05:40 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1710270347; 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=i2n0g7ELC5Jfz1aF+KhbZXxiuizO3RE1y/QxbejYQSE=; b=HHyhMGPRuH0SnoHYtwlS9XquVfzAfzCv2iAcquIE40GXvCaIuOL7dyut4T+neO59Dvr/0O uVp8JyXYjrlzR0tfvsDqzDmfCN2h+WRWtdOKJUPDR9WsBt8PpiJh7VrjtwRr53CAH4909m HCf/Dd7De4o1ZWLqYMlLdoYsAKPWEVI= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Vlastimil Babka Cc: 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 4/4] UNFINISHED mm, fs: use kmem_cache_charge() in path_openat() Message-ID: References: <20240301-slab-memcg-v1-0-359328a46596@suse.cz> <20240301-slab-memcg-v1-4-359328a46596@suse.cz> <8aa61329-dc3c-46f2-9db5-6e0770fbedda@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: <8aa61329-dc3c-46f2-9db5-6e0770fbedda@suse.cz> X-Migadu-Flow: FLOW_OUT On Tue, Mar 12, 2024 at 10:22:54AM +0100, Vlastimil Babka wrote: > On 3/1/24 19:53, Roman Gushchin wrote: > > On Fri, Mar 01, 2024 at 09:51:18AM -0800, Linus Torvalds wrote: > >> What I *think* I'd want for this case is > >> > >> (a) allow the accounting to go over by a bit > >> > >> (b) make sure there's a cheap way to ask (before) about "did we go > >> over the limit" > >> > >> IOW, the accounting never needed to be byte-accurate to begin with, > >> and making it fail (cheaply and early) on the next file allocation is > >> fine. > >> > >> Just make it really cheap. Can we do that? > >> > >> For example, maybe don't bother with the whole "bytes and pages" > >> stuff. Just a simple "are we more than one page over?" kind of > >> question. Without the 'stock_lock' mess for sub-page bytes etc > >> > >> How would that look? Would it result in something that can be done > >> cheaply without locking and atomics and without excessive pointer > >> indirection through many levels of memcg data structures? > > > > I think it's possible and I'm currently looking into batching charge, > > objcg refcnt management and vmstats using per-task caching. It should > > speed up things for the majority of allocations. > > For allocations from an irq context and targeted allocations > > (where the target memcg != memcg of the current task) we'd probably need to > > keep the old scheme. I hope to post some patches relatively soon. > > Do you think this will work on top of this series, i.e. patches 1+2 could be > eventually put to slab/for-next after the merge window, or would it > interfere with your changes? Please, go on and merge them, I'll rebase on top of it, it will be even better for my work. I made a couple of comments there, but overall they look very good to me, thank you for doing this work! > > > I tried to optimize the current implementation but failed to get any > > significant gains. It seems that the overhead is very evenly spread across > > objcg pointer access, charge management, objcg refcnt management and vmstats. I started working on the thing, but it's a bit more complicated than I initially thought because: 1) there are allocations made from a !in_task() context, so we need to handle this correctly 2) tasks can be moved between cgroups concurrently to memory allocations. fortunately my recent changes provide a path here, but it adds to the complexity. In alternative world where tasks can't move between cgroups the life would be so much better (and faster too, we could remove a ton of synchronization). 3) we do have per-numa-node per-memcg stats, which are less trivial to cache on struct task I hope to resolve these issues somehow and post patches, but probably will need a bit more time. Thanks!