From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34279C54E5D for ; Tue, 12 Mar 2024 19:05:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD8856B012A; Tue, 12 Mar 2024 15:05:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A7BFF6B0129; Tue, 12 Mar 2024 15:05:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96BE06B012A; Tue, 12 Mar 2024 15:05:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 8921C6B0128 for ; Tue, 12 Mar 2024 15:05:51 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 588F44029D for ; Tue, 12 Mar 2024 19:05:51 +0000 (UTC) X-FDA: 81889316502.21.1F13934 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) by imf26.hostedemail.com (Postfix) with ESMTP id 78926140011 for ; Tue, 12 Mar 2024 19:05:49 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=HHyhMGPR; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf26.hostedemail.com: domain of roman.gushchin@linux.dev designates 91.218.175.188 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710270349; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=i2n0g7ELC5Jfz1aF+KhbZXxiuizO3RE1y/QxbejYQSE=; b=vJ67fisLfKuI4d4pWm/bL8vxTaW+Ek48F+eliWutUyGe6n3j/DTapeFXnEqACyUPQizSFY EJqbfcqankNhhI1RLHeYuiStd6flnrtQw8S1+jvAEY9YR7firkuP/p/phu6+qx0unvQQiZ 1YpuCc68VDiNN8QvQCS4bi8rjCwQfdc= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=HHyhMGPR; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf26.hostedemail.com: domain of roman.gushchin@linux.dev designates 91.218.175.188 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710270349; a=rsa-sha256; cv=none; b=W69tF+6/z0c4d0v3w/KmjsAweNAtEOckdIGwGGyJBZ0cDVeVmxlvMKCSCB4K2Budv0piRD f4/aomrAhm+TAR5/ocUUShUQraOVYHnK2o0dfnD1CQEzE/ghH+m87SwvgnpyZqjyAxx3mK nV2b4gClgPIjqHz1l+dVBDfjunHNTF0= 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> 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 X-Rspam-User: X-Stat-Signature: kr4jupfboyfua6s61oxt14jg69kwumk5 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 78926140011 X-HE-Tag: 1710270349-375833 X-HE-Meta: U2FsdGVkX19bEL7nsZ55PgiFNQ7i57zUqLdLFGogMoJ8IvcDqnqSmbn+KXC5+W8K1qNXEyJl/DN8kMDGVuZ5u+62YyV0Ysgu9LnNJ9Kmxd43OqBVcz7dvsXOsrku75f2QRGlF1efN+CCzvoYaV8r8nvDXMn0+JnHmYSPpTkg9tau01QzbMU6FvhNjsuPMH6co6aGYuGuC0EIjgPJb6wpqVzbA/6jqSEDUmsToC1V93y4aeLDrLBuJG0bIsKdIm2SzxVu3yNIyRTr6VECBtDM/Nl9ivy8EQDOEhfC7cVFHnmWUVBQEEeeNwBmtkrp+fBRgW8ccDg6EUdxt7qK+LOaEhqq2cvH+9Ygj6buXedjjD1BLN3K5950gI7tQuGezCfdVwosba7mnSmRJuSrhs0HgdTD7+jKT+TXss3ah89/tLnPknJDi8PGPmnqg7wvyCJMW9XxsI+WD2xeK2amUsu6izAhhxVWbwl5QIaBJWZPlOfe0/ivY3+hKI3YXva/VfU3SyhHK/bF2R2xGGgOp0FayQzEA8ywzP8NGhNDrZIsHHPKLsMPeIfyXBWmgyIhH3WquPUqNuuKunI6yDTzHc4X4wVQflCtGGF/8oQMNSJ/FYdJgZeFlodo/w+kA2h84OJKrXLNu68YjBE+C4IYPkVnFGeBzPo95fGgqwbKSzMVpReggLjeKb77H/12/89K5Efgl7lJAN6vlY2SsKvA1moFIcqLQgjzxI3TStyz/yAgl0k0Wj4ClyVWtz6cijUyT1Go5mn+GgA+3b7jD6RaVw3UyXVnmEUcQ5DBbDAXxZUUH1+BZ3rXmC6dwFEn8bshOFc6/qQQd6W5bT2LmDzbI6bnrk+Ub4ltSih7jZ4JkJbvQKvhOxqXaKltL+9oCbJK5ebDDj+SXdTxXVpAHeDJ8z8Po600tTPNxCle0j8v7Xw0Z/8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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!