Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3603034ybb; Tue, 31 Mar 2020 08:25:31 -0700 (PDT) X-Google-Smtp-Source: ADFU+vt3tWAEpGMspC5JEl0WUrtIFQ513EXKzVRVULoOt+Pzhcd0NRTs6PETRG032voFZ55KMPB0 X-Received: by 2002:a4a:6549:: with SMTP id z9mr13700503oog.37.1585668331483; Tue, 31 Mar 2020 08:25:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585668331; cv=none; d=google.com; s=arc-20160816; b=CCS6rXJcfFSYnhqRUVU91clOFEY+EE5ji6wUTJgZLTt4yDwPI+faRWFdmQDJk44siX rEwBHPZlR2zD0gzfyjOdZHYmH52kQE9fSN+HZSSytCoGrleEGEoXDrP4ZTjj+D+UyO6n zDJqsCi9UOMoFi5zumEBIU0pbMtIwwL4nV4eQ3oWKmpa/0blISXtWYFHqHjmSv14FhUo WYeCwKQTZOZ0sLqSOsnZZrhdzC1sGNi6PniJvLeDw2J58NpAN2sFxVQeAqr7WmICtPTA 19w12a3Mo7Vj6wKLwLCe7Pu/WfEveNNn5iLJam8TWM1lzAvJ+8a07mE8p6ro+oswj2oc A2Lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=6PtH4wzWMiH5JmxAt904ilpPuqtvXlZEsu04wa6si/k=; b=m48m+y3a/aSkAafBIY0doNFkehY64+U1CKCBs7At511OsOuo0uwXa9GvtnKvfKinrN HwxNk+4jYjn2MrLxrnqhNwYnhHxIwaPslHYevR6McwjaZVX1Xo0j1kFviuekKNbqnwtn JwdVLMtTn7aT9sJSjFj86VDAE/wEM4UeNzHQdXXuBOt71wV/TMy6h5lTRId7A+DzOre4 TJa8E8onNhwsW8AnWwCplBdOFvVPha+6eLbTPeCywrFEAIboJwlRffhDcG4b/uXtx3Ql fYALF/Zx1g57Iw1diIxXS/YI7LDRe1XUVThv/bYKhsYtirwKcfwyD7yqwwOd6eY8kpM2 iFqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chrisdown.name header.s=google header.b=P8qu2lfT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chrisdown.name Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h27si7735980ots.293.2020.03.31.08.25.09; Tue, 31 Mar 2020 08:25:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chrisdown.name header.s=google header.b=P8qu2lfT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chrisdown.name Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730276AbgCaPY1 (ORCPT + 99 others); Tue, 31 Mar 2020 11:24:27 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:38381 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726595AbgCaPY1 (ORCPT ); Tue, 31 Mar 2020 11:24:27 -0400 Received: by mail-wr1-f67.google.com with SMTP id c7so483175wrx.5 for ; Tue, 31 Mar 2020 08:24:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=6PtH4wzWMiH5JmxAt904ilpPuqtvXlZEsu04wa6si/k=; b=P8qu2lfTpI9t1V10h5AQtX1pY3rsMg/xWtmYiBZTO8QwsPjlZ48gV9R/FoFJmeJWE0 6N9UVOHFvpnOaSH+7UMgcWEAHiG7XS3XGxcYf4DGWJ7JjdHdvf5MBmfs7Auv00Bns8rd 7JaAJ9XeB4dUlJrtAGbvmVJaQ85yG05sxP8nA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=6PtH4wzWMiH5JmxAt904ilpPuqtvXlZEsu04wa6si/k=; b=cBI7fcR1wtTPLYoWirbJgSZo5MfMO8RrGCLFCThlNeTLXjo0B/J6F2LtX+DowxGqfS JDbHjD9RXZfYIyYqMkdmJjtWpwoggkrH6vrtxlCMW9cztWjIeQ1LANero4wI9a3KcOjR 4F9kwpOD2J3SWiSBJMgxQ9/7PoTmK16hS9a5nMjpMkHxhDWtdAZSHt+Lc/coAt7nrp20 H/AfEGdmeom4aedAiWRs9Go+5paWVzx3xvsEnbnljDX70tpVU1HMwpX1clzbC12LR55S ap081BFrEHWOS6o54cuOCICEd4OLQ4sGa7wqZll8w1WffzNuMxf4fKX7M7edaUIF9aIw H4JA== X-Gm-Message-State: ANhLgQ088tHxjPkAG8wd+vig1wKSep1T+HZQ+x2wqmcNTMyKNwcRkMSd BH8bbSXfQ9DiJE9PD9H6P5ho2g== X-Received: by 2002:adf:9465:: with SMTP id 92mr21029231wrq.122.1585668265184; Tue, 31 Mar 2020 08:24:25 -0700 (PDT) Received: from localhost ([2620:10d:c092:180::1:27bd]) by smtp.gmail.com with ESMTPSA id c7sm27386436wrn.49.2020.03.31.08.24.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 08:24:24 -0700 (PDT) Date: Tue, 31 Mar 2020 16:24:24 +0100 From: Chris Down To: Andrew Morton Cc: Johannes Weiner , Jakub Kicinski , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH] mm, memcg: Do not high throttle allocators based on wraparound Message-ID: <20200331152424.GA1019937@chrisdown.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jakub Kicinski If a cgroup violates its memory.high constraints, we may end up unduly penalising it. For example, for the following hierarchy: A: max high, 20 usage A/B: 9 high, 10 usage A/C: max high, 10 usage We would end up doing the following calculation below when calculating high delay for A/B: A/B: 10 - 9 = 1... A: 20 - PAGE_COUNTER_MAX = 21, so set max_overage to 21. This gets worse with higher disparities in usage in the parent. I have no idea how this disappeared from the final version of the patch, but it is certainly Not Good(tm). This wasn't obvious in testing because, for a simple cgroup hierarchy with only one child, the result is usually roughly the same. It's only in more complex hierarchies that things go really awry (although still, the effects are limited to a maximum of 2 seconds in schedule_timeout_killable at a maximum). [chris@chrisdown.name: changelog] Fixes: e26733e0d0ec ("mm, memcg: throttle allocators based on ancestral memory.high") Signed-off-by: Jakub Kicinski Signed-off-by: Chris Down Cc: Johannes Weiner Cc: stable@vger.kernel.org # 5.4.x --- mm/memcontrol.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index eecf003b0c56..75a978307863 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2336,6 +2336,9 @@ static unsigned long calculate_high_delay(struct mem_cgroup *memcg, usage = page_counter_read(&memcg->memory); high = READ_ONCE(memcg->high); + if (usage <= high) + continue; + /* * Prevent division by 0 in overage calculation by acting as if * it was a threshold of 1 page -- 2.26.0