Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5014594imu; Tue, 29 Jan 2019 11:15:52 -0800 (PST) X-Google-Smtp-Source: ALg8bN5tz5fr7wO6DK/njq1veiisXUssMAatpHJdX9qR3bzSLo8Vza9jTA7/UUAUHtf2sWqfkrvc X-Received: by 2002:aa7:8608:: with SMTP id p8mr27820254pfn.125.1548789352613; Tue, 29 Jan 2019 11:15:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548789352; cv=none; d=google.com; s=arc-20160816; b=Sby1RYLjuaucvvFXHskd3UdXcjVs2cmvJdQAWBjhvr54rOUGAasxhiAbfJysMJpCva hKNlJWzSSBy+zJ05gbM+2ExnQzKNK4CqBwh4Eso2rN9BZHc/bxd4FwZFHweiaGFF78p0 TxrZBNBf0edvMw7hIVofBXusH6ScF4P1ee1qn9sB2rrA3vVRe2BqGgzQef8Oe/BiiFvS KaXBQQzQBGU+mtdvj66JbCXrKbiiaaHW0JuKBlyi2lwtLTP7IxSpge6ZGsY4J9kJePKs Y2IpJIgy3IMXqKs/rsrtZz1dWNT1DHG+XO0yJnJQVTfR9sr44cSLNabf/kJQjjlSVBbL oWeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=7Uuf0LVs+pzHcF3nyh4GxvEPQsOE1NPnxZxuLZkBYcE=; b=fFiPnMsbdHw4m+pwUFC5fGrUbHs3luVyIQIIp7em4DgFqoPIGPUi6dvvjEyUE3WW5W Jtli58MR+alxb5+CpJ559niN9erK3Hz2/k3gEQYUYiX68hAK/vFiWnMfe83DNCzlae91 N9tnXlyTVSR452qfnu2qro/RUWoL6KKxYtnkYoDl7g4vJsropBThGbeHk40L1P1rsOgA krADIh8Nfa+sw3GL4MYvgrKBH2l+9g3sPaV2quJyXtsQOLn5Ygjrq2fpBzn9oqLBRCa+ VOLuyjHOwo2gXM71rcb+dE6Y2BvEun1qMtrmuYlmkDx4mEDkK1F/zzl+XqcwttyhteS/ j9RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chrisdown.name header.s=google header.b=NWO1tpka; 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 d4si36067259pfa.150.2019.01.29.11.15.36; Tue, 29 Jan 2019 11:15:52 -0800 (PST) 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=NWO1tpka; 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 S1729364AbfA2TP3 (ORCPT + 99 others); Tue, 29 Jan 2019 14:15:29 -0500 Received: from mail-yw1-f66.google.com ([209.85.161.66]:41319 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727332AbfA2TP2 (ORCPT ); Tue, 29 Jan 2019 14:15:28 -0500 Received: by mail-yw1-f66.google.com with SMTP id f65so8630930ywc.8 for ; Tue, 29 Jan 2019 11:15:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=7Uuf0LVs+pzHcF3nyh4GxvEPQsOE1NPnxZxuLZkBYcE=; b=NWO1tpkadXDzKPLeqcckeYOXK0qRah25lv9XpFX4W/D0ZeK8WDrTZav72UjZSwm8Y5 8E9j5aDJinxsGCjkPiV9bCrYzES7wIWNC6XZjNvE3ekV4DtiuqGhAvnXih2dEIUtbjBe 5QquP/EkhMDDHWEeQGacIpCHyATrH6UAr06Rc= 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=7Uuf0LVs+pzHcF3nyh4GxvEPQsOE1NPnxZxuLZkBYcE=; b=LV3ZmXQEGxUtcxL/15oShwZSEBEQIKxr7a2n0dvui7e90FJfaa1vdLWPgQ5IHVpdtV 1AOW2aPux5VcmnuPCniI4Px4pyzSLNL7Tkjd14pWqjZ/eyfPRsj8yQ3o1XhcSva0sZ9Y 9+ub4a06tJyZs5Q1TXcXYDmF2HdreL5mcqFdEo+MIguAVJ2XHJnRUS4kxxSy24Mtf62U +jUPrlj/IR4Ra1BMQRld5QoaX3jN8CU6MLCHgSpzpS/RT51rDs+cDXn+HDDGGVcwXM+C nL8zoVA1KITLKdvPxTvLxrTcc1YmT+W9CLOKdZOXP34OaUYTpZNRF7w98CMk1/HR4HWZ udPA== X-Gm-Message-State: AJcUukeK9lEOF8LisExiOGEcradhjYnOuaOnj6BuaQD/td1XgDiMWEK9 7YNwYHlgfJx177++fp4Us+jCtA== X-Received: by 2002:a81:5b07:: with SMTP id p7mr27054908ywb.468.1548789326972; Tue, 29 Jan 2019 11:15:26 -0800 (PST) Received: from localhost ([2620:10d:c091:200::6:f1fc]) by smtp.gmail.com with ESMTPSA id k187sm12398985ywf.71.2019.01.29.11.15.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Jan 2019 11:15:26 -0800 (PST) Date: Tue, 29 Jan 2019 14:15:25 -0500 From: Chris Down To: Andrew Morton Cc: Johannes Weiner , Michal Hocko , Tejun Heo , Roman Gushchin , Dennis Zhou , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, kernel-team@fb.com Subject: Re: [PATCH v3] mm: Make memory.emin the baseline for utilisation determination Message-ID: <20190129191525.GB10430@chrisdown.name> References: <20190129182516.GA1834@chrisdown.name> <20190129190253.GA10430@chrisdown.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20190129190253.GA10430@chrisdown.name> User-Agent: Mutt/1.11.2 (2019-01-07) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Roman points out that when when we do the low reclaim pass, we scale the reclaim pressure relative to position between 0 and the maximum protection threshold. However, if the maximum protection is based on memory.elow, and memory.emin is above zero, this means we still may get binary behaviour on second-pass low reclaim. This is because we scale starting at 0, not starting at memory.emin, and since we don't scan at all below emin, we end up with cliff behaviour. This should be a fairly uncommon case since usually we don't go into the second pass, but it makes sense to scale our low reclaim pressure starting at emin. You can test this by catting two large sparse files, one in a cgroup with emin set to some moderate size compared to physical RAM, and another cgroup without any emin. In both cgroups, set an elow larger than 50% of physical RAM. The one with emin will have less page scanning, as reclaim pressure is lower. Signed-off-by: Chris Down Suggested-by: Roman Gushchin Cc: Johannes Weiner Cc: Andrew Morton Cc: Michal Hocko Cc: Tejun Heo Cc: Roman Gushchin Cc: Dennis Zhou Cc: linux-kernel@vger.kernel.org Cc: cgroups@vger.kernel.org Cc: linux-mm@kvack.org Cc: kernel-team@fb.com --- include/linux/memcontrol.h | 12 ++++++--- mm/vmscan.c | 55 +++++++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 26 deletions(-) ...well, I sent it with NULL for !CONFIG_MEMCG when I wanted 0. This is the fixed fix(tm) patch. diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 290cfbfd60cd..6f7e0e1b581d 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -333,9 +333,11 @@ static inline bool mem_cgroup_disabled(void) return !cgroup_subsys_enabled(memory_cgrp_subsys); } -static inline unsigned long mem_cgroup_protection(struct mem_cgroup *memcg) +static inline void mem_cgroup_protection(struct mem_cgroup *memcg, + unsigned long *min, unsigned long *low) { - return max(READ_ONCE(memcg->memory.emin), READ_ONCE(memcg->memory.elow)); + *min = READ_ONCE(memcg->memory.emin); + *low = READ_ONCE(memcg->memory.elow); } enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, @@ -826,9 +828,11 @@ static inline void memcg_memory_event_mm(struct mm_struct *mm, { } -static inline unsigned long mem_cgroup_protection(struct mem_cgroup *memcg) +static inline void mem_cgroup_protection(struct mem_cgroup *memcg, + unsigned long *min, unsigned long *low) { - return 0; + *min = 0; + *low = 0; } static inline enum mem_cgroup_protection mem_cgroup_protected( diff --git a/mm/vmscan.c b/mm/vmscan.c index 549251818605..f7c4ab39d5d0 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2447,12 +2447,12 @@ static void get_scan_count(struct lruvec *lruvec, struct mem_cgroup *memcg, int file = is_file_lru(lru); unsigned long lruvec_size; unsigned long scan; - unsigned long protection; + unsigned long min, low; lruvec_size = lruvec_lru_size(lruvec, lru, sc->reclaim_idx); - protection = mem_cgroup_protection(memcg); + mem_cgroup_protection(memcg, &min, &low); - if (protection > 0) { + if (min || low) { /* * Scale a cgroup's reclaim pressure by proportioning * its current usage to its memory.low or memory.min @@ -2467,28 +2467,38 @@ static void get_scan_count(struct lruvec *lruvec, struct mem_cgroup *memcg, * set it too low, which is not ideal. */ unsigned long cgroup_size = mem_cgroup_size(memcg); - unsigned long baseline = 0; /* - * During the reclaim first pass, we only consider - * cgroups in excess of their protection setting, but if - * that doesn't produce free pages, we come back for a - * second pass where we reclaim from all groups. + * If there is any protection in place, we adjust scan + * pressure in proportion to how much a group's current + * usage exceeds that, in percent. * - * To maintain fairness in both cases, the first pass - * targets groups in proportion to their overage, and - * the second pass targets groups in proportion to their - * protection utilization. - * - * So on the first pass, a group whose size is 130% of - * its protection will be targeted at 30% of its size. - * On the second pass, a group whose size is at 40% of - * its protection will be - * targeted at 40% of its size. + * There is one special case: in the first reclaim pass, + * we skip over all groups that are within their low + * protection. If that fails to reclaim enough pages to + * satisfy the reclaim goal, we come back and override + * the best-effort low protection. However, we still + * ideally want to honor how well-behaved groups are in + * that case instead of simply punishing them all + * equally. As such, we reclaim them based on how much + * of their best-effort protection they are using. Usage + * below memory.min is excluded from consideration when + * calculating utilisation, as it isn't ever + * reclaimable, so it might as well not exist for our + * purposes. */ - if (!sc->memcg_low_reclaim) - baseline = lruvec_size; - scan = lruvec_size * cgroup_size / protection - baseline; + if (sc->memcg_low_reclaim && low > min) { + /* + * Reclaim according to utilisation between min + * and low + */ + scan = lruvec_size * (cgroup_size - min) / + (low - min); + } else { + /* Reclaim according to protection overage */ + scan = lruvec_size * cgroup_size / + max(min, low) - lruvec_size; + } /* * Don't allow the scan target to exceed the lruvec @@ -2504,7 +2514,8 @@ static void get_scan_count(struct lruvec *lruvec, struct mem_cgroup *memcg, * some cases in the case of large overages. * * Also, minimally target SWAP_CLUSTER_MAX pages to keep - * reclaim moving forwards. + * reclaim moving forwards, avoiding decremeting + * sc->priority further than desirable. */ scan = clamp(scan, SWAP_CLUSTER_MAX, lruvec_size); } else { -- 2.20.1