Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp670712ybc; Tue, 12 Nov 2019 07:29:58 -0800 (PST) X-Google-Smtp-Source: APXvYqwOwNWTpoq3PLzHgSWNfyM7XQ+rF/cQzLCpAtf9t4wxqGWowbsAB1uR/TirnXKr6SAJOJi1 X-Received: by 2002:a17:906:a411:: with SMTP id l17mr29041194ejz.274.1573572598204; Tue, 12 Nov 2019 07:29:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573572598; cv=none; d=google.com; s=arc-20160816; b=cluJ8ag3J/+DFg4/4fbQZhFCDyF6pXlfOJo/Hksv+WTtIoLeNY/Uc/wBryuONHvSDy CcO7IaO0+NTz3kqDyziEcfXVl0yirxS6dpvNwngrZIFHpV6mh5pX19JJIrTIdJ6O3ELN qtpuet1icR9JdYT3y8R1pEnKfXd60oxVM/OR4MD6dGyhYVneWj67MvG/731x1+79VIHe dIzM2NwN146slIa1bRWHI0IRRedcXe5CD/OqHjcQlGqwNlcH7htWjuyNPnmnXo3cVDd2 Kqbdij4e1QlY6hSsrvNNk7b4kV+H1iT7XFVbY7gzHTKCJCZ5xecECLCTEWOfbgw9Pw3m ZU0w== 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; bh=C572eUoO0NRJwJ6Vtn2QGn5ZE9RwRZHrEMc48YDU4gk=; b=mWi1F4qpOdtqUlUXfVOSBaNhPGO5zyIlpQAFhTtRDPfFEtqStT2WlE5XhLGRYrk9JX cHrO5kXucN4a07HXali7ePCbBVI3+ewb02rLq+zQ2nEh6Agbdsh3n5gOFxSim0fmV86J Xe5ejcm/Lt7ytunRYpGjFrGGp0itZBKHKlvZPOLB4hrxUHFHVFHyy1c2eYDsJfnHLMtU obuIOD9eomjXITxuKzIifzNhSa1uow0xVyh4Ee2nLEOywQCUXa1+DvUyvw2nnbv4ede3 sE8um0rU2A8U9JaCiSlVDvqMJ2PXh9AYqj0zyd8JjBkdOxiUJkE9MhrfvzSXmZ0yf1oo sSsw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d15si13043612edn.49.2019.11.12.07.29.33; Tue, 12 Nov 2019 07:29:58 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727440AbfKLP1z (ORCPT + 99 others); Tue, 12 Nov 2019 10:27:55 -0500 Received: from mx2.suse.de ([195.135.220.15]:41666 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725954AbfKLP1z (ORCPT ); Tue, 12 Nov 2019 10:27:55 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id BD40FB327; Tue, 12 Nov 2019 15:27:52 +0000 (UTC) Date: Tue, 12 Nov 2019 16:27:50 +0100 From: Michal Hocko To: Johannes Weiner Cc: Chris Down , Qian Cai , akpm@linux-foundation.org, guro@fb.com, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH -next] mm/vmscan: fix an undefined behavior for zone id Message-ID: <20191112152750.GA512@dhcp22.suse.cz> References: <20191108204407.1435-1-cai@lca.pw> <64E60F6F-7582-427B-8DD5-EF97B1656F5A@lca.pw> <20191111130516.GA891635@chrisdown.name> <20191111131427.GB891635@chrisdown.name> <20191111132812.GK1396@dhcp22.suse.cz> <20191112145942.GA168812@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191112145942.GA168812@cmpxchg.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 12-11-19 06:59:42, Johannes Weiner wrote: > Qian, thanks for the report and the fix. > > On Mon, Nov 11, 2019 at 02:28:12PM +0100, Michal Hocko wrote: > > On Mon 11-11-19 13:14:27, Chris Down wrote: > > > Chris Down writes: > > > > Ah, I just saw this in my local checkout and thought it was from my > > > > changes, until I saw it's also on clean mmots checkout. Thanks for the > > > > fixup! > > > > > > Also, does this mean we should change callers that may pass through > > > zone_idx=MAX_NR_ZONES to become MAX_NR_ZONES-1 in a separate commit, then > > > remove this interim fixup? I'm worried otherwise we might paper over real > > > issues in future. > > > > Yes, removing this special casing is reasonable. I am not sure > > MAX_NR_ZONES - 1 is a better choice though. It is error prone and > > zone_idx is the highest zone we should consider and MAX_NR_ZONES - 1 > > be ZONE_DEVICE if it is configured. But ZONE_DEVICE is really standing > > outside of MM reclaim code AFAIK. It would be probably better to have > > MAX_LRU_ZONE (equal to MOVABLE) and use it instead. > > We already use MAX_NR_ZONES - 1 everywhere else in vmscan.c to mean > "no zone restrictions" - get_scan_count() is the odd one out: > > - mem_cgroup_shrink_node() > - try_to_free_mem_cgroup_pages() > - balance_pgdat() > - kswapd() > - shrink_all_memory() > > It's a little odd that it points to ZONE_DEVICE, but it's MUCH less > subtle than handling both inclusive and exclusive range delimiters. > > So I think the better fix would be this: lruvec_lru_size is explicitly documented to use MAX_NR_ZONES for all LRUs and git grep says there are more instances outside of get_scan_count. So all of them have to be fixed. I still think that MAX_NR_ZONES - 1 is a very error prone and subtle construct IMHO and an alias would be better readable. Anyway I definitely do agree that we do not want to use both (MAX_NR_ZONES and MAX_NR_ZONES - 1) because that is even more confusing. > --- > >From 1566a255eef7c2165d435125231ad1eeecac7959 Mon Sep 17 00:00:00 2001 > From: Johannes Weiner > Date: Mon, 11 Nov 2019 13:46:25 -0800 > Subject: [PATCH] mm: vmscan: simplify lruvec_lru_size() fix > > get_scan_count() passes MAX_NR_ZONES for the reclaim index, which is > beyond the range of valid zone indexes, but used to be handled before > the patch. Every other callsite in vmscan.c passes MAX_NR_ZONES - 1 to > express "all zones, please", so do the same here. > > Reported-by: Qian Cai > Reported-by: Chris Down > Signed-off-by: Johannes Weiner > --- > mm/vmscan.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/mm/vmscan.c b/mm/vmscan.c > index df859b1d583c..34ad8a0f3f27 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -2322,10 +2322,10 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, > * anon in [0], file in [1] > */ > > - anon = lruvec_lru_size(lruvec, LRU_ACTIVE_ANON, MAX_NR_ZONES) + > - lruvec_lru_size(lruvec, LRU_INACTIVE_ANON, MAX_NR_ZONES); > - file = lruvec_lru_size(lruvec, LRU_ACTIVE_FILE, MAX_NR_ZONES) + > - lruvec_lru_size(lruvec, LRU_INACTIVE_FILE, MAX_NR_ZONES); > + anon = lruvec_lru_size(lruvec, LRU_ACTIVE_ANON, MAX_NR_ZONES - 1) + > + lruvec_lru_size(lruvec, LRU_INACTIVE_ANON, MAX_NR_ZONES - 1); > + file = lruvec_lru_size(lruvec, LRU_ACTIVE_FILE, MAX_NR_ZONES - 1) + > + lruvec_lru_size(lruvec, LRU_INACTIVE_FILE, MAX_NR_ZONES - 1); > > spin_lock_irq(&pgdat->lru_lock); > if (unlikely(reclaim_stat->recent_scanned[0] > anon / 4)) { > -- > 2.24.0 -- Michal Hocko SUSE Labs