Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp280831imu; Fri, 16 Nov 2018 02:26:16 -0800 (PST) X-Google-Smtp-Source: AJdET5dPidtrPGMZUnDBErtjNGsUDX2HRi3krpkEvcyis7WYQdbY8GGUIaMogqtmGDilQq/Uo83f X-Received: by 2002:a17:902:bf47:: with SMTP id u7-v6mr10455537pls.10.1542363975918; Fri, 16 Nov 2018 02:26:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542363975; cv=none; d=google.com; s=arc-20160816; b=LLf3TpYxptsSm5fSOH417Y0eTK3hedVefV0TtRBBn+Ii6OqBwHwZa9nGOfhCvVJz2r c0VV4dJNfkQuCa9qfvbCXRFzzJMGLQ9Iueur3BobYjqcejuPrK45WkCt7kghSHbczyvP CL5kTGWSBfbMUf1wAojEp6ccVTy88pal/FqtBAf+M8nXKYAQ/hWvMgxSf7wT8I9qwppu 5PCNmwqT3gk2fJP/DdsYwN/weCL5aIyyeaKDxQtRQzfEJoeB3Om2a6MBpWAjFekWd+Bp RaCKypQxocGl7dGclIh+28SndgQl/wAhDSAKMgoCGcucDYp2JkgPwbWQot1zr7GkMIYu 8jKw== 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=r6AJbQyUDi4PMAwxHgeH+fNRX05iqqW7qJdovPhsSnk=; b=y8jKdtc4mF4TSf71j6JM9J9TAJGYGjocwSqZygr1Zr/wVukvxZyLl4RT/AION3uwo+ 9sFum1i/selHILIaDrwVBBDHcKjqR0FYsQsK2xz38FTihwowjtgzhzVTRAmpYcH2cCKs Xnuth1QjyNXVwbud4EAadxkwJDBgMG08bnxfKF+M6aO1OmXillAjx6zfPPnn6v9CUVk/ eZMyaAwo8xrbcCRUj6DyfkxU4waVUYoWGe+oD2bmNLxJWmY9isAERk7ApoZujIxuCwJW iX5G9oEStwbvCdgCb/Zt+fBdIuXQMAwGqvXNrhJ7j7HHpPOPqRXA33WO5bNzBqIRDNOP yf7Q== 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 s9si30325247pgv.397.2018.11.16.02.26.01; Fri, 16 Nov 2018 02:26:15 -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 S1727698AbeKPUft (ORCPT + 99 others); Fri, 16 Nov 2018 15:35:49 -0500 Received: from mx2.suse.de ([195.135.220.15]:46422 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727446AbeKPUft (ORCPT ); Fri, 16 Nov 2018 15:35:49 -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 39DBDAF3A; Fri, 16 Nov 2018 10:24:06 +0000 (UTC) Date: Fri, 16 Nov 2018 11:24:05 +0100 From: Michal Hocko To: Wei Yang Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Rafael J. Wysocki" Subject: Re: [PATCH] mm: use managed_zone() for more exact check in zone iteration Message-ID: <20181116102405.GF14706@dhcp22.suse.cz> References: <20181114235040.36180-1-richard.weiyang@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181114235040.36180-1-richard.weiyang@gmail.com> 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 Thu 15-11-18 07:50:40, Wei Yang wrote: [...] > @@ -1193,8 +1196,8 @@ static unsigned int count_free_highmem_pages(void) > struct zone *zone; > unsigned int cnt = 0; > > - for_each_populated_zone(zone) > - if (is_highmem(zone)) > + for_each_zone(zone) > + if (populated_zone(zone) && is_highmem(zone)) > cnt += zone_page_state(zone, NR_FREE_PAGES); this should be for_each_managed_zone because we only care about highmem zones which have pages in the allocator (NR_FREE_PAGES). > > return cnt; > @@ -1239,10 +1242,10 @@ static unsigned int count_highmem_pages(void) > struct zone *zone; > unsigned int n = 0; > > - for_each_populated_zone(zone) { > + for_each_zone(zone) { > unsigned long pfn, max_zone_pfn; > > - if (!is_highmem(zone)) > + if (!populated_zone(zone) || !is_highmem(zone)) > continue; > > mark_free_pages(zone); I am not familiar with this code much but I strongly suspect that we do want for_each_managed_zone here because saveable_highmem_page skips over all reserved pages which rules out the bootmem. But this should be double checked with Rafael (Cc-ed). Rafael, does this loop care about pages which are not managed by the page allocator? > @@ -1305,8 +1308,8 @@ static unsigned int count_data_pages(void) > unsigned long pfn, max_zone_pfn; > unsigned int n = 0; > > - for_each_populated_zone(zone) { > - if (is_highmem(zone)) > + for_each_zone(zone) { > + if (!populated_zone(zone) || is_highmem(zone)) > continue; > > mark_free_pages(zone); > @@ -1399,9 +1402,12 @@ static void copy_data_pages(struct memory_bitmap *copy_bm, > struct zone *zone; > unsigned long pfn; > > - for_each_populated_zone(zone) { > + for_each_zone(zone) { > unsigned long max_zone_pfn; > > + if (!populated_zone(zone)) > + continue; > + > mark_free_pages(zone); > max_zone_pfn = zone_end_pfn(zone); > for (pfn = zone->zone_start_pfn; pfn < max_zone_pfn; pfn++) > @@ -1717,7 +1723,10 @@ int hibernate_preallocate_memory(void) > saveable += save_highmem; > highmem = save_highmem; > size = 0; > - for_each_populated_zone(zone) { > + for_each_zone(zone) { > + if (!populated_zone(zone)) > + continue; > + > size += snapshot_additional_pages(zone); > if (is_highmem(zone)) > highmem += zone_page_state(zone, NR_FREE_PAGES); ditto for the above. > @@ -1863,8 +1872,8 @@ static int enough_free_mem(unsigned int nr_pages, unsigned int nr_highmem) > struct zone *zone; > unsigned int free = alloc_normal; > > - for_each_populated_zone(zone) > - if (!is_highmem(zone)) > + for_each_zone(zone) > + if (populated_zone(zone) && !is_highmem(zone)) > free += zone_page_state(zone, NR_FREE_PAGES); > > nr_pages += count_pages_for_highmem(nr_highmem); This one should be for_each_managed_zone (NR_FREE_PAGES) The rest looks good to me. -- Michal Hocko SUSE Labs