Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1427384lqt; Wed, 20 Mar 2024 03:55:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW625I7H4xHVrP7dEbHr5TJFQGOXokRfoguwkYq40Wlt1U+dqGyJihgklOaQCrAEzZFT/kM/VF0FGjGSzlOBbppgNJWacwgQyVo5XlL5w== X-Google-Smtp-Source: AGHT+IF2hUrNIYf/ixMuMsAUjJuvAyZnqrdZCEj8Ssi8yUhuSU3Rz7cas0y69gjkvgcVZ9kwnblm X-Received: by 2002:a05:620a:11a6:b0:789:dc1e:3a52 with SMTP id c6-20020a05620a11a600b00789dc1e3a52mr19775565qkk.28.1710932134821; Wed, 20 Mar 2024 03:55:34 -0700 (PDT) Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u13-20020a05620a084d00b00789f3428c6bsi8420986qku.20.2024.03.20.03.55.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 03:55:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-108809-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector2 header.b=vy0bi5ld; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-108809-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108809-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 7B0C31C213C2 for ; Wed, 20 Mar 2024 10:55:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D312D3A27B; Wed, 20 Mar 2024 10:55:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="vy0bi5ld" Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2101.outbound.protection.outlook.com [40.107.104.101]) (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 45987381AC; Wed, 20 Mar 2024 10:55:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.104.101 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710932122; cv=fail; b=DSb5FHeIFrs7l7OgnySFeqRIzuoDPlCpcZxvy4WsPaitStltg5Emhf4zZikyTeaz33/0zp926SldDaphm6EImSq2bchrCdkzt4Rn+Ygf7H9mPOg5x8llfWORqRvEHSNTtCoRUJ5HkWhgAflxeSCXCKztOqrqCL9vaDkrCVy+hoU= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710932122; c=relaxed/simple; bh=NzvjaKLoqH2H9dQaFQkue56NAwZPYL70eUDEnYX2G/I=; h=Message-ID:Date:Subject:To:Cc:References:From:In-Reply-To: Content-Type:MIME-Version; b=CsZz42whCO3167s33Bu9OLSuwkNJ0fjvFN3jbIyM1EacBgtZDlRTxt5j5AF+XBbTmhcKYRVUY+8zru/6OXhJTzCpBDtAC0sbWqikR5ZnY/zOQG3HIAJrxiFGOng6L0ulwCgo/WEzC9MwgstBmUC2RXEaFgLI9/CVlFSUn5pWI2E= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=virtuozzo.com; spf=pass smtp.mailfrom=virtuozzo.com; dkim=pass (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b=vy0bi5ld; arc=fail smtp.client-ip=40.107.104.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=monbVy1sP3JA6gWE7zSuAsPBZK44g34nNj32McsgFwqEg9UJq/Nx0SdAbTe3jQqKnKNM5V/ahfw74gI3aVugb9Hmvq6WHzTXWdH4plb1H/+f7MEbnBW5HZC1nG8TtUEq82h6o+plUHs98RzSjewkCPjsnwsl4xa8t8cfgltkC0GNJws/Dfgv1nAdg0R4JCkCAMxbLvD7LuqJ1MpwOHwadCasRv3th6magZjsmSIcaXzhCiT0BYjCGsBkV54kgzhLJ3tQ35aUkk8xuyIrCZt//ml6i5DRV+DwvVrPKuL2fsX+vHZWKkCcLR+DcIaMf9PWacOH3gDgV/pzzLVWoN8K0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1Wn0hRJWYtMA2BHuz9foWcgH4fPaNPeLClzOhB/tZw8=; b=NqrwT+OGs4qkd5EOL6SyW56wvTnmTh+1H1pLVqCbY3uLY30oYiNk9/3e1UhMhaZ2yBGUmDKuPzT5rWp0BEWqUOvZNO3/bRSZw610SF+187/1l5eqjMt7lSDknNCcPOSk+wSna5Y5o815IJHfjaRlF8IFR79+JCZ09xRSDI/OalnbgEIBOn8cqbH/4ST4woZUIRhmwRrwTbk6u0NR09P0TFsXWSOwU3MkwC3g0qjgswVHF7LPXs/fpVZ4IinZnpiuwVOOJHmN6uzUEFgrb277/wFCB6VTYf2k73fMm8obMQWU3l+VgzOHLRAVrUc1xYHe6pJolQgF8/ttJwDDKHU/gg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1Wn0hRJWYtMA2BHuz9foWcgH4fPaNPeLClzOhB/tZw8=; b=vy0bi5ldpY0w2/enwCAgja2sdmrKAXGr0JaVpESIibN+V6wZvrfTAZwoQ6XjF9THVSItkC82BcPPzVzKEI3afgKLdX5XOhT303smUUfmgfkN+QEYYoCw3HP8nHkb1WZanCbReA0KblVgmXKgqlSR1r4Z2ZhLlMUXel9Kl6Kh9hUfpKpBSp7eCu5obbYyxu2jyiCtAaUQn3Rl/c/KmSI6FwRAGCSS2zau4TNGeaFLAWxjd4VEK6ELCL5ve8qhHocjIO0otb9TeD1skX93nx7wq3hwFB6In42KJgk/AheIte/Hn914lU+4IhtMQq8VchX1EJlH5wAGlFcNAjIP2UJ/6Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from DU0PR08MB9003.eurprd08.prod.outlook.com (2603:10a6:10:471::13) by PAXPR08MB7525.eurprd08.prod.outlook.com (2603:10a6:102:24b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.28; Wed, 20 Mar 2024 10:55:13 +0000 Received: from DU0PR08MB9003.eurprd08.prod.outlook.com ([fe80::ade0:bad9:96bb:6bd0]) by DU0PR08MB9003.eurprd08.prod.outlook.com ([fe80::ade0:bad9:96bb:6bd0%3]) with mapi id 15.20.7386.025; Wed, 20 Mar 2024 10:55:13 +0000 Message-ID: Date: Wed, 20 Mar 2024 18:55:05 +0800 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm/memcontrol: stop resize loop if limit was changed again Content-Language: en-US To: Michal Hocko Cc: Johannes Weiner , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , Vladimir Davydov , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel@openvz.org References: <20240320100556.463266-1-ptikhomirov@virtuozzo.com> From: Pavel Tikhomirov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: KL1PR02CA0005.apcprd02.prod.outlook.com (2603:1096:820:c::10) To DU0PR08MB9003.eurprd08.prod.outlook.com (2603:10a6:10:471::13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR08MB9003:EE_|PAXPR08MB7525:EE_ X-MS-Office365-Filtering-Correlation-Id: 84a8df26-7ba0-41b7-cb45-08dc48cc381e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kWxVfZR9tuAlImmuqTKdXqbxzFdUH0Co6D4222bxrFVGkzQVsb+TOi+GNvFfMOqcbhW3j188w5uQmxVzTKp8iV7vAKoIciM6ej6uwtxOjpDALaVjgYouIcE6eEV0ovLr4US4RbTLX/vwtg0PsDKhxqDVahuvw2yswpYT1ZWSu3e5+1rdwm5O+uWhZSAbl4t/IYHC0t+4YyQd4q5lrpudEgz96QNHN2QwLMuXzDtdp9CeeJO1zuyQoaYRN2nT5PWFaLUdocOxcs8qxhe8cmdT++uRkoMdZLrDWaPbR6tfr6oQpkeAJgs1Ml2MERf0JBFIgRMJaWbqicUYLuq+Q08Gg64+WYrDY33S8x2LerGcNrTVT/zGug4XT7Y/QyBjEcjjWoLRKSmgbax6CVJRVglGwgEkNW4eppEXzGFOSt/IRTrgsslsmbxCNdrBgIT1NScxFt2LYuW9GW2if0BX/J+MylAjARH8uFT6mEpcZ5FN0ewcxAq4IZRILFhJlI3FnoF6usyYC/cScnZQPklkpYhFLXgopgfbUalZhmwCc1xBFqGVYqXvoZ5uf+W1mtCcH5wM4EyXKNaHM05QIu0Raa42jSTR8U9yEXCiYr0ya1OcfWshfG1tlJA9ub9UhUx6V39200OHllmJKxvtwXNRufecLuaBZTTJB6yXFe2liEB4BYw= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU0PR08MB9003.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(7416005)(366007)(1800799015)(376005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?MW16SWRlRmNYNmNQR1VyempsVmVPZ2lKdmdwdGJWdVV0OWpReXdxMlRQSXll?= =?utf-8?B?T1JMRWNiZDBwVTFiMnNzaFJGQ1pOVWNLdFo1eS9sK1JyTXN1aXNsMlZmeTBO?= =?utf-8?B?RzVvZ0JHWDllVDlDOWRHTmdja1lwWFFrbysvekpXM2NXN21ad0JXRlB5K3VH?= =?utf-8?B?VWZnTXN4VENIS1RieENpMjJHRHpWMEVJRnRoUTVDS0FmeE5qUUswc2FvVms3?= =?utf-8?B?ei8rOWIzRkI0MkNSTERFODh1cXlQeEpwamV5TTNmcE15N2hyb2tnTXc0cHg4?= =?utf-8?B?dXBKcENFUFZkQm9pUWIwalBUWmthN3ExN0tvdUsrMEpLNExVMDU2bHdTcTRs?= =?utf-8?B?Y2hzdVFJeklSYnc1Rm9LMndZZU9PNWdoTjQxVmVMQm1VL09ZdXFoTy9UOGg0?= =?utf-8?B?L0J1ZFduVDd6M1ZFQWF2OHhVbS9qamtLVnRxNDdZaVNPb2o3VXIya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T0=?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 84a8df26-7ba0-41b7-cb45-08dc48cc381e X-MS-Exchange-CrossTenant-AuthSource: DU0PR08MB9003.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Mar 2024 10:55:13.4604 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: X2jDTyb6Kg68EY1LfgnFNhgHWuMmBeFR52AxAErQnENLIhm2VH407t9fyUgxX69/m7DEjyQlRkdyrEYwnVPICKXR1B2kL+B7zWVRH3pZjlA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB7525 On 20/03/2024 18:28, Michal Hocko wrote: > On Wed 20-03-24 18:03:30, Pavel Tikhomirov wrote: >> In memory_max_write() we first set memcg->memory.max and only then >> try to enforce it in loop. What if while we are in loop someone else >> have changed memcg->memory.max but we are still trying to enforce >> the old value? I believe this can lead to nasty consequence like getting >> an oom on perfectly fine cgroup within it's limits or excess reclaim. > > I would argue that uncoordinated hard limit configuration can cause > problems on their own. Sorry, didn't know that. > Beside how is this any different from changing > the high limit while we are inside the reclaim loop? I believe reclaim loop rereads limits on each iteration, e.g. in reclaim_high(), so it should always be enforcing the right limit. > >> We also have exactly the same thing in memory_high_write(). >> >> So let's stop enforcing old limits if we already have a new ones. > > I do see any reasons why this would be harmful I just do not see why > this is a real thing or why the new behavior is any better for racing > updaters as those are not deterministic anyway. If you have any actual > usecase then more details would really help to justify this change. > > The existing behavior makes some sense as it enforces the given limit > deterministically. I don't have any actual problem, usecase or reproduce at hand, I only see a potential problem: Let's imagine that: a) We set cgroup max limit to some small value, memory_max_write updates memcg->memory.max and starts spinning in loop as it wants to reclaim some memory which does not fit in new limit. b) We don't need small limit anymore and we raise the limit to a big value, but memory_max_write() from (a) is still spinning. And if we are lucky enough and processes of cgroup are constantly consuming memory, to compensate effect from memory_max_write() from (a), so that it will continue spinning there forever. Yes it is not that bad, because memory_max/high_write() also constantly checks for pending signals in loop so they won't actually get irreversibly stuck. But I just thought it was worth fixing. > >> Signed-off-by: Pavel Tikhomirov >> --- >> mm/memcontrol.c | 6 ++++++ >> 1 file changed, 6 insertions(+) >> >> diff --git a/mm/memcontrol.c b/mm/memcontrol.c >> index 61932c9215e7..81b303728491 100644 >> --- a/mm/memcontrol.c >> +++ b/mm/memcontrol.c >> @@ -6769,6 +6769,9 @@ static ssize_t memory_high_write(struct kernfs_open_file *of, >> unsigned long nr_pages = page_counter_read(&memcg->memory); >> unsigned long reclaimed; >> >> + if (memcg->memory.high != high) >> + break; >> + >> if (nr_pages <= high) >> break; >> >> @@ -6817,6 +6820,9 @@ static ssize_t memory_max_write(struct kernfs_open_file *of, >> for (;;) { >> unsigned long nr_pages = page_counter_read(&memcg->memory); >> >> + if (memcg->memory.max != max) >> + break; >> + >> if (nr_pages <= max) >> break; >> >> -- >> 2.43.0 > -- Best regards, Tikhomirov Pavel Senior Software Developer, Virtuozzo.