Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2919574lqz; Wed, 3 Apr 2024 12:19:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWKz3QX6AqMUJUJeHns0dc1hvMQksGzfH0v6hO59+w4a3MYC/gfc850oSk37CifLR52L/OdQY2GpK8sp465NG6FuLTK37Qux56aHK+mqA== X-Google-Smtp-Source: AGHT+IEO3eJTemle8tadGyP4ZdDctH5R2PCY0IUW+tpI0OmRCykuWOhIFZwHmZwvxy9aDUfQcfg8 X-Received: by 2002:a05:6871:10b:b0:22e:9739:8b52 with SMTP id y11-20020a056871010b00b0022e97398b52mr275646oab.20.1712171982995; Wed, 03 Apr 2024 12:19:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712171982; cv=pass; d=google.com; s=arc-20160816; b=KCSLm+ajyt8s//UllUWzbdxvsRl5ymp5B6FDIpsTYJ6eLtgJZI9qJ6QijfNjX9Lk1W mWDHBSyGH1Yle5P4ukXku8Yg/Wd64zOTVhpwjDRXnrogefCKsMgtxrYDV9jTBIVYjgQe KxzLsSeiw0HPIumkjMEtyAScX6W6lYoSgOyeJdnEZzKCDdIgP1nVkjlIJXbsPrjZH/pt B30cbrKA2c1aQktN6uaQgupMba+m3fQrV0FwfA0vY++du356XfFijp/i0FyW6+eC+nFx nCXIeCMnF6A1lyIlSInYJM+YJzN7AiyRuZH2KwoAYSrzWQEywFsA6VXs+t6l84UAK7xu 6QIQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=zVsS4/McIZ2rFmGChCwH1Oum9JbWNRjCsuUljg3CrOI=; fh=ykp9buvbxWVwpycUgngYo/NVo4EaSIavt72oRf8uV64=; b=Bgpp9YBW4xk7uvbEL7KsMu/MvOVk7ciD2gmPiJSsE4Hp+hsyxGA1s4cr658S0e/Sft 1vmI8d2JdbZc6mEx9bPOLtjEjWRbjtvWg0L1Bs6I474s4y6D1ouWOlompbMk2resX/Mz uFaAjhwhN76Wb5CEej58K9r89w/asFbBBfAtRjbF3HvBX6b/1Jx1aPER1vjHOaScI1Q3 WCQd0CouGxrRL+mnDSSkPegaEZOezStS0BcoUjuH81dZAuPWQ0mvfo38sUYyaKyomSIi T7gVJlaIzLCW7eHoDi6LlMF/gjsy1faCZsxCT6I6haQKR2kBkpsKyTCSgVPNrWybO5/t RR1w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-130411-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130411-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id q7-20020a056a00084700b006eb43bc0fbesi6811589pfk.51.2024.04.03.12.19.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 12:19:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-130411-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-130411-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130411-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 6972EB3D92D for ; Wed, 3 Apr 2024 18:02:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 884B3153518; Wed, 3 Apr 2024 18:02:24 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 32389152513; Wed, 3 Apr 2024 18:02:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712167344; cv=none; b=SEXtTkACKWkYJ3C+yr9it6HEZpiwaYraqcRxNty5W19YbDHQhLEKvsmjf942KO9qbtPi86mi1n6+1dRp6DkeKgWLCSBOTrdXFFVNyZycyV3EwxIwxm+efw86jGJ5GKRC0pn83sd6nCT1+5dCZaJAAsFWSnNfVJDIkwI0qYHs07Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712167344; c=relaxed/simple; bh=wohhLCNkof1vY1W1Dwlmkq643wtKNO9tiiqXimh9pKk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=F+cmCEygnzc2hUXXfPCmrf8/IBOt13fk2iQqAbCdI0lMYpErgqo5cl4R0uHJb9SQ/DAn8LUbLycecRicElw0oJluQ0icrEJXmTpxUD0pjfAaGFoqSX/1p4SWk7PQF3JgVyg5UUQSE06jWRJo18bEmrOePB5uq58WsY/tWjf+jKU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 20D441007; Wed, 3 Apr 2024 11:02:52 -0700 (PDT) Received: from [10.57.18.20] (unknown [10.57.18.20]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5F9333F766; Wed, 3 Apr 2024 11:02:17 -0700 (PDT) Message-ID: <2143378c-0d5b-4e68-9da4-cabc149cb84f@arm.com> Date: Wed, 3 Apr 2024 19:02:15 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/2] mm, slab: move memcg charging to post-alloc hook Content-Language: en-US To: Vlastimil Babka , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org, Chengming Zhou , Linus Torvalds , Josh Poimboeuf , Jeff Layton , Chuck Lever , Kees Cook , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Johannes Weiner , Michal Hocko , Muchun Song , Alexander Viro , Christian Brauner , Jan Kara , Shakeel Butt , Mark Brown References: <20240325-slab-memcg-v2-0-900a458233a6@suse.cz> <20240325-slab-memcg-v2-1-900a458233a6@suse.cz> <30df7730-1b37-420d-b661-e5316679246f@arm.com> <4af50be2-4109-45e5-8a36-2136252a635e@suse.cz> From: Aishwarya TCV In-Reply-To: <4af50be2-4109-45e5-8a36-2136252a635e@suse.cz> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 03/04/2024 16:48, Vlastimil Babka wrote: > On 4/3/24 1:39 PM, Aishwarya TCV wrote: >> >> >> On 25/03/2024 08:20, Vlastimil Babka wrote: >>> The MEMCG_KMEM integration with slab currently relies on two hooks >>> during allocation. memcg_slab_pre_alloc_hook() determines the objcg and >>> charges it, and memcg_slab_post_alloc_hook() assigns the objcg pointer >>> to the allocated object(s). >>> >>> As Linus pointed out, this is unnecessarily complex. Failing to charge >>> due to memcg limits should be rare, so we can optimistically allocate >>> the object(s) and do the charging together with assigning the objcg >>> pointer in a single post_alloc hook. In the rare case the charging >>> fails, we can free the object(s) back. >>> >>> This simplifies the code (no need to pass around the objcg pointer) and >>> potentially allows to separate charging from allocation in cases where >>> it's common that the allocation would be immediately freed, and the >>> memcg handling overhead could be saved. >>> >>> Suggested-by: Linus Torvalds >>> Link: https://lore.kernel.org/all/CAHk-=whYOOdM7jWy5jdrAm8LxcgCMFyk2bt8fYYvZzM4U-zAQA@mail.gmail.com/ >>> Reviewed-by: Roman Gushchin >>> Reviewed-by: Chengming Zhou >>> Signed-off-by: Vlastimil Babka >>> --- >>> mm/slub.c | 180 +++++++++++++++++++++++++++----------------------------------- >>> 1 file changed, 77 insertions(+), 103 deletions(-) >> >> Hi Vlastimil, >> >> When running the LTP test "memcg_limit_in_bytes" against next-master >> (next-20240402) kernel with Arm64 on JUNO, oops is observed in our CI. I >> can send the full logs if required. It is observed to work fine on >> softiron-overdrive-3000. >> >> A bisect identified 11bb2d9d91627935c63ea3e6a031fd238c846e1 as the first >> bad commit. Bisected it on the tag "next-20240402" at repo >> "https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git". >> >> This works fine on Linux version v6.9-rc2 > > Oops, sorry, can you verify that this fixes it? > Thanks. > > ----8<---- > From b0597c220624fef4f10e26079a3ff1c86f02a12b Mon Sep 17 00:00:00 2001 > From: Vlastimil Babka > Date: Wed, 3 Apr 2024 17:45:15 +0200 > Subject: [PATCH] fixup! mm, slab: move memcg charging to post-alloc hook > > The call to memcg_alloc_abort_single() is wrong, it expects a pointer to > single object, not an array. > > Reported-by: Aishwarya TCV > Signed-off-by: Vlastimil Babka > --- > mm/slub.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/slub.c b/mm/slub.c > index f5b151a58b7d..b32e79629ae7 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -2100,7 +2100,7 @@ bool memcg_slab_post_alloc_hook(struct kmem_cache *s, struct list_lru *lru, > return true; > > if (likely(size == 1)) { > - memcg_alloc_abort_single(s, p); > + memcg_alloc_abort_single(s, *p); > *p = NULL; > } else { > kmem_cache_free_bulk(s, size, p); Tested the attached patch on next-20240302. Confirming that the test is running fine. Test run log is attached below. Test run log: -------------- memcg_limit_in_bytes 8 TPASS: process 614 is killed memcg_limit_in_bytes 9 TINFO: Test limit_in_bytes will be aligned to PAGESIZE memcg_limit_in_bytes 9 TPASS: echo 4095 > memory.limit_in_bytes passed as expected memcg_limit_in_bytes 9 TPASS: input=4095, limit_in_bytes=0 memcg_limit_in_bytes 10 TPASS: echo 4097 > memory.limit_in_bytes passed as expected memcg_limit_in_bytes 10 TPASS: input=4097, limit_in_bytes=4096 memcg_limit_in_bytes 11 TPASS: echo 1 > memory.limit_in_bytes passed as expected memcg_limit_in_bytes 11 TPASS: input=1, limit_in_bytes=0 memcg_limit_in_bytes 12 TINFO: Test invalid memory.limit_in_bytes memcg_limit_in_bytes 12 TPASS: echo -1 > memory.limit_in_bytes passed as expected memcg_limit_in_bytes 13 TPASS: echo 1.0 > memory.limit_in_bytes failed as expected memcg_limit_in_bytes 14 TPASS: echo 1xx > memory.limit_in_bytes failed as expected memcg_limit_in_bytes 15 TPASS: echo xx > memory.limit_in_bytes failed as expected Summary: passed 18 failed 0 broken 0 skipped 0 warnings 0 Thanks, Aishwarya