From patchwork Fri Aug 7 06:21:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 11704841 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8DB28138C for ; Fri, 7 Aug 2020 06:21:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 525832177B for ; Fri, 7 Aug 2020 06:21:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="j3iOVIdv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 525832177B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1135F8D005E; Fri, 7 Aug 2020 02:21:54 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0EA7E8D0026; Fri, 7 Aug 2020 02:21:54 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 025C28D005E; Fri, 7 Aug 2020 02:21:53 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0119.hostedemail.com [216.40.44.119]) by kanga.kvack.org (Postfix) with ESMTP id E1A858D0026 for ; Fri, 7 Aug 2020 02:21:53 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id ACD0B180AD804 for ; Fri, 7 Aug 2020 06:21:53 +0000 (UTC) X-FDA: 77122776906.09.form94_1e0732026fbe Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id 87FD2180AD802 for ; Fri, 7 Aug 2020 06:21:53 +0000 (UTC) X-Spam-Summary: 1,0,0,a96ec4e0036fee57,d41d8cd98f00b204,akpm@linux-foundation.org,,RULES_HIT:41:355:379:800:960:967:973:988:989:1260:1263:1345:1359:1381:1431:1437:1534:1542:1711:1730:1747:1777:1792:2198:2199:2393:2525:2559:2563:2682:2685:2731:2859:2895:2902:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3354:3865:3866:3867:3868:3870:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:5007:6119:6261:6653:6737:7576:7903:8531:8599:9025:9545:9592:9707:10004:10913:11026:11658:11914:12043:12048:12264:12295:12296:12297:12438:12517:12519:12555:12679:12783:12986:13221:13229:14181:14721:14849:21080:21451:21627:21740:21795:21939:21990:30051:30054:30064:30070,0,RBL:198.145.29.99:@linux-foundation.org:.lbl8.mailshell.net-62.2.0.100 64.100.201.201;04yrfwj7asx3qg5mundz11nate7chyc4pys768rxomrsfwy7isi7dznjzpemkcn.x59yknx3rkuiuco9t5zsjxaq7m5g9ukws7fyg4bkir5y1fdk6794wur5fpjppa7.c-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netche ck:none, X-HE-Tag: form94_1e0732026fbe X-Filterd-Recvd-Size: 3855 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Fri, 7 Aug 2020 06:21:53 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9F81D221E5; Fri, 7 Aug 2020 06:21:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596781312; bh=Dl3Dm/Eu5wjiTaKK45eDk/3qF/7YCH/X+eekyMacs4s=; h=Date:From:To:Subject:In-Reply-To:From; b=j3iOVIdvXBQzyDWvr08wtiWnnW4Cg4M1PSsNy8TOkRUJPHJSYcHRDg4DUG9NnbznD 3e03V4qTC82SCn4p7A5ZxNgcaXzSmQwnlOE2qBR38FWVncDrAVoYYtFC0fAAkufe9f WWYOeoKDAYkITKBdRmBo9mSykeG69z/wXzZAVBGo= Date: Thu, 06 Aug 2020 23:21:51 -0700 From: Andrew Morton To: akpm@linux-foundation.org, chris@chrisdown.name, domas@fb.com, guro@fb.com, hannes@cmpxchg.org, linux-mm@kvack.org, mhocko@suse.com, mm-commits@vger.kernel.org, shakeelb@google.com, tj@kernel.org, torvalds@linux-foundation.org Subject: [patch 085/163] mm: memcontrol: avoid workload stalls when lowering memory.high Message-ID: <20200807062151.2JYr5jJgy%akpm@linux-foundation.org> In-Reply-To: <20200806231643.a2711a608dd0f18bff2caf2b@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Rspamd-Queue-Id: 87FD2180AD802 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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: From: Roman Gushchin Subject: mm: memcontrol: avoid workload stalls when lowering memory.high Memory.high limit is implemented in a way such that the kernel penalizes all threads which are allocating a memory over the limit. Forcing all threads into the synchronous reclaim and adding some artificial delays allows to slow down the memory consumption and potentially give some time for userspace oom handlers/resource control agents to react. It works nicely if the memory usage is hitting the limit from below, however it works sub-optimal if a user adjusts memory.high to a value way below the current memory usage. It basically forces all workload threads (doing any memory allocations) into the synchronous reclaim and sleep. This makes the workload completely unresponsive for a long period of time and can also lead to a system-wide contention on lru locks. It can happen even if the workload is not actually tight on memory and has, for example, a ton of cold pagecache. In the current implementation writing to memory.high causes an atomic update of page counter's high value followed by an attempt to reclaim enough memory to fit into the new limit. To fix the problem described above, all we need is to change the order of execution: try to push the memory usage under the limit first, and only then set the new high limit. Link: http://lkml.kernel.org/r/20200709194718.189231-1-guro@fb.com Signed-off-by: Roman Gushchin Reported-by: Domas Mituzas Acked-by: Michal Hocko Reviewed-by: Shakeel Butt Cc: Johannes Weiner Cc: Tejun Heo Cc: Chris Down Signed-off-by: Andrew Morton --- mm/memcontrol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/mm/memcontrol.c~mm-memcontrol-avoid-workload-stalls-when-lowering-memoryhigh +++ a/mm/memcontrol.c @@ -6213,8 +6213,6 @@ static ssize_t memory_high_write(struct if (err) return err; - page_counter_set_high(&memcg->memory, high); - for (;;) { unsigned long nr_pages = page_counter_read(&memcg->memory); unsigned long reclaimed; @@ -6238,6 +6236,8 @@ static ssize_t memory_high_write(struct break; } + page_counter_set_high(&memcg->memory, high); + return nbytes; }