Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1814732rdd; Thu, 11 Jan 2024 09:59:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IFGzwx26x2rl3sa43KGefS45it9ytVr2tZ5JUY8+XWmvvWcTfEm29qw5dgFcRfcc6Og2gGh X-Received: by 2002:aa7:d456:0:b0:558:a1a4:164e with SMTP id q22-20020aa7d456000000b00558a1a4164emr34018edr.39.1704995984844; Thu, 11 Jan 2024 09:59:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704995984; cv=none; d=google.com; s=arc-20160816; b=WbYJ5J3m32yPFitfzoAKacewjHfz5eN5HtsISZMom/9mfYsU7GxEzvk2uSlEt72MDu +91d8J3D9pWPVzDixHb4PBudvq0Sm8ekNHPYk+8I9mdqC39Upt08FBnq6kj291FtD63t W3BLOclcJHSOTssIc37lxP3CXlKaeMS7i7ZXDH992935VkgNngS0IDWZEZ29wAEtXQji xvKkVxj4nrzu/58aLSJESIjcqVWroBRjiVD5hjEZW4W/RyEjlL/2ZFE0n/rYXkyNPEkA QkusOtjivapwNTY4Os+/BQqbhq6sx5cnIvjZPKqjEqJyF1z7sd7JoIFOLn/FrWDzWgL1 9h8w== ARC-Message-Signature: i=1; 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=LFlTmqKWu1L5WwW9zjp3A8ZgS4CejVZXVReh/bTmlHI=; fh=+/LVdKsE4rFKnroBtPruCUK/LqDhv+8JMirdddEGok4=; b=ltvOZyqHcRg9/vSK8gthZiG07O0/Rl/jHig2phFMB9YW+yvUOMYds8BEgaazSmD7yw F/y5Fm6I2IpBsdI80Jb+joRCylfCquNYcpsnELoHsoo9Paw/0vgf4/EuSS44W/pIPEf7 vJutb4vsScLsnlV0TPb7zP4cRgUscvnOeEEv9ZhCSlWcUiD+yzcqSw1n3U33SrOQIfZC tiXlEzzu+whdzhw17oKLKcyB25VFKXxkERR9cibj3tIyr1Pe+NYr1b2CZL1C8xscrD3v wQwQuzwb+XDLOuw9hBxqwmAwwzZh0CY1rz/nJezZXGnDa2+k0BnstoKfPKy0h+pI+sU9 As5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=WrqiSA80; spf=pass (google.com: domain of linux-kernel+bounces-23955-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23955-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id p12-20020aa7cc8c000000b00553416e4531si752514edt.675.2024.01.11.09.59.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 09:59:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23955-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=WrqiSA80; spf=pass (google.com: domain of linux-kernel+bounces-23955-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23955-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 962301F243E6 for ; Thu, 11 Jan 2024 17:59:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 789D45476B; Thu, 11 Jan 2024 17:59:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="WrqiSA80" Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [95.215.58.182]) (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 D4D7953E23 for ; Thu, 11 Jan 2024 17:59:18 +0000 (UTC) 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: Thu, 11 Jan 2024 09:59:11 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1704995956; 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=LFlTmqKWu1L5WwW9zjp3A8ZgS4CejVZXVReh/bTmlHI=; b=WrqiSA80IXtiFa7+jyPFcSmaNikWHHzREvNb09PiZp7Os1rT/qkUmCdDpiT8lud2QchAdD AKoaznC9qnvG/OBr93VGvmoftGM4EtgudZ5o5N3CxLaNH0dgnzsvpFR04nWX+3S4yTod2k p9I6asesQ+eEoQwn/E0cnVPZAunYf2o= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Johannes Weiner Cc: Andrew Morton , Michal Hocko , Shakeel Butt , Muchun Song , Tejun Heo , Dan Schatzberg , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: memcontrol: don't throttle dying tasks on memory.high Message-ID: References: <20240111132902.389862-1-hannes@cmpxchg.org> 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: <20240111132902.389862-1-hannes@cmpxchg.org> X-Migadu-Flow: FLOW_OUT On Thu, Jan 11, 2024 at 08:29:02AM -0500, Johannes Weiner wrote: > While investigating hosts with high cgroup memory pressures, Tejun > found culprit zombie tasks that had were holding on to a lot of > memory, had SIGKILL pending, but were stuck in memory.high reclaim. > > In the past, we used to always force-charge allocations from tasks > that were exiting in order to accelerate them dying and freeing up > their rss. This changed for memory.max in a4ebf1b6ca1e ("memcg: > prohibit unconditional exceeding the limit of dying tasks"); it noted > that this can cause (userspace inducable) containment failures, so it > added a mandatory reclaim and OOM kill cycle before forcing charges. > At the time, memory.high enforcement was handled in the userspace > return path, which isn't reached by dying tasks, and so memory.high > was still never enforced by dying tasks. > > When c9afe31ec443 ("memcg: synchronously enforce memory.high for large > overcharges") added synchronous reclaim for memory.high, it added > unconditional memory.high enforcement for dying tasks as well. The > callstack shows that this path is where the zombie is stuck in. > > We need to accelerate dying tasks getting past memory.high, but we > cannot do it quite the same way as we do for memory.max: memory.max is > enforced strictly, and tasks aren't allowed to move past it without > FIRST reclaiming and OOM killing if necessary. This ensures very small > levels of excess. With memory.high, though, enforcement happens lazily > after the charge, and OOM killing is never triggered. A lot of > concurrent threads could have pushed, or could actively be pushing, > the cgroup into excess. The dying task will enter reclaim on every > allocation attempt, with little hope of restoring balance. > > To fix this, skip synchronous memory.high enforcement on dying tasks > altogether again. Update memory.high path documentation while at it. It makes total sense to me. Acked-by: Roman Gushchin However if tasks can stuck for a long time in the "high reclaim" state, shouldn't we also handle the case when tasks are being killed during the reclaim? E. g. something like this (completely untested): diff --git a/mm/memcontrol.c b/mm/memcontrol.c index c4c422c81f93..9f971fc6aae8 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2465,6 +2465,9 @@ static unsigned long reclaim_high(struct mem_cgroup *memcg, READ_ONCE(memcg->memory.high)) continue; + if (task_is_dying()) + break; + memcg_memory_event(memcg, MEMCG_HIGH); psi_memstall_enter(&pflags); @@ -2645,6 +2648,9 @@ void mem_cgroup_handle_over_high(gfp_t gfp_mask) current->memcg_nr_pages_over_high = 0; retry_reclaim: + if (task_is_dying()) + return; + /* * The allocating task should reclaim at least the batch size, but for * subsequent retries we only want to do what's necessary to prevent oom