Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp603504ybi; Fri, 21 Jun 2019 05:11:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqymHCz5bS+Cyxr0/zIMLyZCAdCkjam6Fxjg49kA73/8EdzMFba+kbhObi2D26NJhZyS9YlC X-Received: by 2002:a63:e53:: with SMTP id 19mr17947093pgo.137.1561119086205; Fri, 21 Jun 2019 05:11:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561119086; cv=none; d=google.com; s=arc-20160816; b=dOa4nQmDznntKuF8PKkp1DTNS3Helx/X8Zn0zCPpt0lhnWE9NQX1i5qrcNRxK6FfXw JYBmmVJQ86KfO/03sfsJS8kFnwVDGaiITFKKfP8zDnQJjkCYGoStsWdrzweqSi0w6Nck tBtwEbrTs11moSdMfvWUvBlKob+fWngNTDwJMK+M7EyxumO7wLSdn2Nvkcb89j/xTmFj BCti8j8+OufGPc0sQQBsGbuQbFq4dhSYoLeCdxFGP7qfSTdyu4T3KWYMWTH+NREsi9cF v1m0R6qZRoUUwzxp9i3npnCfJxrtj32UNE/4nrnU/5wIzTD9/C4oQYfAHUs3x6zZn7xj NKYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject; bh=cb+bWGD+HBxNB97rApn/jGEHo8WyU4g8aZHvN3ZHHKo=; b=BSda3LPFtJSBboDS4myDuXvkRIXKC2fAm3s89X08zm7tg28oRl5/zCpOxSMThSAr+S rvnsFClCz4HEH3VrSqSBYgEI8W3hcWC2581D3rn+PNlqRUywOciSr5WQ6y4Z9tFox4QZ fpWQdNjE0zr0ZhMsh6YniTOe4dFRvoyT3ABsr6pYYJrCWqtWUOByIupU8vDUMKb4c4Zq ALt5CpXfDPylnwIzuiHmGzwNvb15ZSo9kDl1u8k8HUd9SFDwxj4M0gcWjTGXpQvZ7ohb YT4G+++narL9dmORvHL8nDlWoZX4mwJG6J67FnM93lTBOvKDEeuEMcDrqceWRcp+2bTj pnew== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u4si2743648pjv.38.2019.06.21.05.11.09; Fri, 21 Jun 2019 05:11:26 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726789AbfFUMJf (ORCPT + 99 others); Fri, 21 Jun 2019 08:09:35 -0400 Received: from mx2.suse.de ([195.135.220.15]:53034 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726431AbfFUMJe (ORCPT ); Fri, 21 Jun 2019 08:09:34 -0400 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 554C9AF1E; Fri, 21 Jun 2019 12:09:31 +0000 (UTC) Subject: Re: [PATCH] mm: fix setting the high and low watermarks To: Alan Jenkins , Mel Gorman Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20190621114325.711-1-alan.christopher.jenkins@gmail.com> From: Vlastimil Babka Openpgp: preference=signencrypt Autocrypt: addr=vbabka@suse.cz; prefer-encrypt=mutual; keydata= mQINBFZdmxYBEADsw/SiUSjB0dM+vSh95UkgcHjzEVBlby/Fg+g42O7LAEkCYXi/vvq31JTB KxR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underbird/60.7.1 MIME-Version: 1.0 In-Reply-To: <20190621114325.711-1-alan.christopher.jenkins@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/21/19 1:43 PM, Alan Jenkins wrote: > When setting the low and high watermarks we use min_wmark_pages(zone). > I guess this is to reduce the line length. But we forgot that this macro > includes zone->watermark_boost. We need to reset zone->watermark_boost > first. Otherwise the watermarks will be set inconsistently. > > E.g. this could cause inconsistent values if the watermarks have been > boosted, and then you change a sysctl which triggers > __setup_per_zone_wmarks(). > > I strongly suspect this explains why I have seen slightly high watermarks. > Suspicious-looking zoneinfo below - notice high-low != low-min. > > Node 0, zone Normal > pages free 74597 > min 9582 > low 34505 > high 36900 > > https://unix.stackexchange.com/questions/525674/my-low-and-high-watermarks-seem-higher-than-predicted-by-documentation-sysctl-vm/525687 > > Signed-off-by: Alan Jenkins > Fixes: 1c30844d2dfe ("mm: reclaim small amounts of memory when an external > fragmentation event occurs") > Cc: stable@vger.kernel.org Nice catch, thanks! Acked-by: Vlastimil Babka Personally I would implement it a bit differently, see below. If you agree, it's fine if you keep the authorship of the whole patch. > --- > > Tested by compiler :-). > > Ideally the commit message would be clear about what happens the > *first* time __setup_per_zone_watermarks() is called. I guess that > zone->watermark_boost is *usually* zero, or we would have noticed > some wild problems :-). However I am not familiar with how the zone > structures are allocated & initialized. Maybe there is a case where > zone->watermark_boost could contain an arbitrary unitialized value > at this point. Can we rule that out? Dunno if there's some arch override, but generic_alloc_nodedata() uses kzalloc() so it's zeroed. -----8<----- diff --git a/mm/page_alloc.c b/mm/page_alloc.c index d66bc8abe0af..3b2f0cedf78e 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7624,6 +7624,7 @@ static void __setup_per_zone_wmarks(void) for_each_zone(zone) { u64 tmp; + unsigned long wmark_min; spin_lock_irqsave(&zone->lock, flags); tmp = (u64)pages_min * zone_managed_pages(zone); @@ -7642,13 +7643,13 @@ static void __setup_per_zone_wmarks(void) min_pages = zone_managed_pages(zone) / 1024; min_pages = clamp(min_pages, SWAP_CLUSTER_MAX, 128UL); - zone->_watermark[WMARK_MIN] = min_pages; + wmark_min = min_pages; } else { /* * If it's a lowmem zone, reserve a number of pages * proportionate to the zone's size. */ - zone->_watermark[WMARK_MIN] = tmp; + wmark_min = tmp; } /* @@ -7660,8 +7661,9 @@ static void __setup_per_zone_wmarks(void) mult_frac(zone_managed_pages(zone), watermark_scale_factor, 10000)); - zone->_watermark[WMARK_LOW] = min_wmark_pages(zone) + tmp; - zone->_watermark[WMARK_HIGH] = min_wmark_pages(zone) + tmp * 2; + zone->_watermark[WMARK_MIN] = wmark_min; + zone->_watermark[WMARK_LOW] = wmark_min + tmp; + zone->_watermark[WMARK_HIGH] = wmark_min + tmp * 2; zone->watermark_boost = 0; spin_unlock_irqrestore(&zone->lock, flags);