Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp241535lqp; Wed, 20 Mar 2024 22:16:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXOoBN8c3VC1Q1soJYWgLKpKARlo4wqi5oKW2/C9y39BHTLpbMkGxGJCiDmVTh+GZHBcmYSJbZYQkXqxbBKTM3aJmJ45eN/LSb2gLEN4A== X-Google-Smtp-Source: AGHT+IE+w3xPYbee8+nWhbHDTDwejFd9eVFxsEUramQfObFDIdFOJu+D6LP/Aw7CMVJadDPmLUVl X-Received: by 2002:a81:71c5:0:b0:60f:e8ca:4959 with SMTP id m188-20020a8171c5000000b0060fe8ca4959mr8324864ywc.18.1710998173255; Wed, 20 Mar 2024 22:16:13 -0700 (PDT) Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id w15-20020a05620a148f00b0078834ca5fd0si15401834qkj.188.2024.03.20.22.16.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 22:16:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-109657-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=@virtuozzo.com header.s=selector2 header.b=B+tYwAho; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-109657-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109657-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 E6D5B1C210C7 for ; Thu, 21 Mar 2024 05:16:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A379F33994; Thu, 21 Mar 2024 05:16:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="B+tYwAho" Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2116.outbound.protection.outlook.com [40.107.105.116]) (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 2F7D92BAFC; Thu, 21 Mar 2024 05:16:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.105.116 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710998165; cv=fail; b=KXEdUTKCKbM3c9xbIkGhlivTxIxRuU9zaLp2cu98XA0SjuXB6iC+kGukgBqs1ciKXcWnvB3ud38fc9Q1LhJxk0J8VXxjMH2uSLzFSmEpnWD3V+UGkTgS1NWIUl7ICBT6v2pmiYSRd3UXnptO+Q6cWinLU/IVqkobgIKwS9Y7ycE= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710998165; c=relaxed/simple; bh=iEDeu6RIkb8cfJIUhUqTW3wjjFoh2ZYly4OoFPHzrS8=; h=Message-ID:Date:Subject:To:Cc:References:From:In-Reply-To: Content-Type:MIME-Version; b=QvhkbLC0C76BNvBjzIkp9KgG0DS0KWNKdLO29dO1sLoyoCGLZ2XqCPqs3T+5aP+/M08mZwcd5zyniJ9+AAhL8Qt4IMr0SrX8/CMI2NDk+jmzSY/rqQrxDk+VgWQDWuQYmAv+fHsK8xik3rfg6H3g+7ekuWhl9yPNLNeCmsdbxS0= 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=B+tYwAho; arc=fail smtp.client-ip=40.107.105.116 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=HYLWd/TqKt+J9lBJyEpfFd4DpwUFlMxITvMeHeLhmCsYfoo/V+EhVzmO5WSP/avG4J9ySv+D8beuHe3IqFIlJFaV7BtQ0+4+V0BC188edZxJpTRVyRxS8cTjjWvq2WkkmCAX7rdPSSmPaD9ZMocSQobYJ7s3fHYsjHJPOw1tiuwjoMocTZzpJoMC+Pjouew/DnLer4L/0+E3sq+MuGIyslw1NkCiLjFY6rsalTZYrZUd5bNYXErnW0EO32cHGkXH/32ql42edsQ4SooSm0NSr/s4ie9infmeJnfgRtl7hFPMm2TkPUYcIuhLmD5aHrWRqwqocN2MsNZXtDdA/jVnAg== 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=ifKpRFYOFSu2iWP8ZfqmJ9iNJzm/I71w3gav264Brl4=; b=ROSpgfeyfu2ScYK2YL/OjteCbM0M7PlTJCxZ8WANSySoZ9Tom7ZVKhvRdadp5wN9pqueuTPizxZ7TRBInYPG95fBV7d170VOTsly3aHzWVxdhWykA8iBBQtAt7iqIqxNHYVAyy3/prsWK9OAz+oHkyrXbTaErlb4NqLH2ZsWLQAdA01dGhm1o9GJLi6KeGLwmusFqR0jmdm/q7UyojaDH0cRfJ15G3QcHMBXJG2MBu/77LPlQP6LZYFYxwxCj6pIbqjqtabWbVvnDiK4DwS2G3SQYdgJeyvI/uQhKkD8Dj0uRXxmNCxXp35/gW/ukqng6sM1HVs+yybCfdektr0J1Q== 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=ifKpRFYOFSu2iWP8ZfqmJ9iNJzm/I71w3gav264Brl4=; b=B+tYwAhoIRhcZvIGR4r0TcmBVOly1vZE6wXh9PZH5jGgIbp/pxaCL+X83AuH4iSHHkYvXZzv/USvHG5TEOmvH8Lky6Q0ImJvfXXoGoUlNNiXh0euvDYVgN20iausXw3Pj2VQ+QpGvJJjuVZM+/aTHTIZefnzeiJskj00NAjHDMoMvJgDGCG8ge0OlsDG/gZLaGmDbYtbOrPJXtjqGKB6LqWRdDS2/qn50lMbuwyUV2rK4KL8kBMg++DVlrrflHdwnNWcJSGUcr99F9GUhJJ4i63ltcO+780mhIMh5shk56cD6PMmRCWqFXnf3zTL92k2I/gL4xv113QAPrK28+vt7w== 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 PA6PR08MB10396.eurprd08.prod.outlook.com (2603:10a6:102:3c7::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.15; Thu, 21 Mar 2024 05:15:59 +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; Thu, 21 Mar 2024 05:15:59 +0000 Message-ID: <18c39901-d1bb-45ab-86ae-1a74c3ff8060@virtuozzo.com> Date: Thu, 21 Mar 2024 13:15:51 +0800 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm/memcontrol: stop resize loop if limit was changed again Content-Language: en-US To: Waiman Long , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton Cc: 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: 8bit X-ClientProxiedBy: KU1PR03CA0002.apcprd03.prod.outlook.com (2603:1096:802:18::14) 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_|PA6PR08MB10396:EE_ X-MS-Office365-Filtering-Correlation-Id: 4a051618-168e-4db5-b5da-08dc4965fec5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UDS9kcmX1+NURAUsBMc1nTpaI5tcaIelFouW/Hwct/M1o4dpgodZqFAHlWozNFUdEx782j6qZ6tVOR1c7TO9xNLe4sTcc+PLcyJGnX1LnP3+fJv6JCLtEPLqbI0SUk+3V4agkakUCpZl5j7adJVOYhF+SRVrjR4EszudQ4NTO5Jf54Hrp/5c8TMWEhaq+JJW5D+An71WavqK/Euvr8UxxMkWg6cQ5f16aa+ttDlrUJR36V16rL8e0rVj20qttJhfGJ5CBZrYWpr1LTG5jWb2ytloqpmNJ3ESJamsNCSRAsAIh5XjuUSPfvvkQSmwaqsMLBjZfxnMUIFAK/fGxdc0fEkRjVwDMAdKxFnBK/K7LVoA7vw1x2qObvj4LCaMkT90tDkV2Gl2cHVuboo5oG5w3bKYZ8n2NR3Hd5UrxtO+yGkLiwGX+7wjKP4bim/kp4i4n+jE7aHTEKZfSZ+ZoTS58RHQhcxmb+QqXPCMGyMzWDGFiCiuCwysvWZUF+KDsz538r3jcvY+oL/QvfAtfp1i+WvV99Tp/2iYhhhw+BMMGr6SBjuYhKSNSoG2PHF0R5/GJIt/t009RUD98D/dNRzzpGmA7KwDa4V8guc6SdTPTlzQgcIwh7kj6f9oDlQyLwApGwx+lLIfDHDR1/FRI7BoSRyDmwHBT3Yo40xt6ZMIN+w= 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)(376005)(7416005)(1800799015)(366007);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?cGNIelFCMFdoUUtRbFlVREJYQ1NOQ0VlWkpJcmFXN1lSSXJ0WDFGcEVjQWtv?= =?utf-8?B?VFNwVGxLei91Y2RMTUZpUjh3NmlEdHlubm9xaUI5NHV2U2Q1dk1kajZEZ05D?= =?utf-8?B?aytkTXNPMDFzNnRaWU5xRkVhWGlPQVhkNS8rd1NTb2dPM05idWNiZnptUk5r?= =?utf-8?B?TmdNaVVJSzhFc0RMVlhKc0FsUDBKbkowSlV1YkN0Q3Qza2dDbXlSbU4vZzhM?= =?utf-8?B?Yysyc1JDdlEyUklzdzdyZDFzM01PQzNjS2tCb3R3VDZYdnhyTFBpakpMelht?= =?utf-8?B?Ti9ISlFLeHpwSTFyVk0rV2ZFOWJjUS9qU2p5eTdwc0Y2cWNidjhLZ0lndHYz?= =?utf-8?B?NVlUK0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hU3d6LzNkTHdMU016KzdjdWpWN2Q0?= =?utf-8?B?R0J2ZEMyV0x2YkxqelVXdUxuSXN0Y3BBWldYaVl6U1d5OTZhZWhIRHlJT0ZE?= =?utf-8?B?a09vOVNaeGtraU9SdUVpd0YvTDNnPT0=?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4a051618-168e-4db5-b5da-08dc4965fec5 X-MS-Exchange-CrossTenant-AuthSource: DU0PR08MB9003.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Mar 2024 05:15:59.7696 (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: g93jCpH2cZnrAGgmLNR/ztjyLC1+cnCJaj7JQNF0pKRhEq0Zs8RB6681EV1nABYXJP/3ZxiXjySIgmLrfrol05MjeDUFSWvgvr56Sg/5AD0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA6PR08MB10396 On 21/03/2024 01:09, Waiman Long wrote: > > On 3/20/24 06:03, 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. > > Concurrent write to the same cgroup control file is not possible as the > underlying kernfs_open_file structure has a mutex that serialize access > to the file. Concurrent write to different cgroup control files is > possible, though. Thanks for pointing this out, now I see it, in kernfs_fop_write_iter() we take of->mutex before ops->write() -> cgroup_file_write(). That means patch is not needed. > > Cheers, > Longman > >> >> 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. >> >> 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; > -- Best regards, Tikhomirov Pavel Senior Software Developer, Virtuozzo.