Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1713804imm; Thu, 19 Jul 2018 06:46:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdF8dCChYURS8pg0Pwh2uQlgFhH7QRYxd+poJOUDNzelLdosNdkF8Eoqz1ZyNJYTv+nbXi6 X-Received: by 2002:a17:902:6e09:: with SMTP id u9-v6mr10012418plk.13.1532007983986; Thu, 19 Jul 2018 06:46:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532007983; cv=none; d=google.com; s=arc-20160816; b=noU3f0TCzx/znWxNrUG9dMmdylkl2v+8z74Kj2niJDMZ7qQNXf9Yt/aepp+0SbGhqY WmSFrH+UJeEQU9NbfnRyegaokSBzZhdf+Cc589YyQ87dKkCer7U2ybBLgUXzycQxsaO2 4Il4ZDCrTW0euirXM8NyCPaaO8Us4QKq7SdYj5Z0cAaVRWs79kIc+89XuKqQOP4dgP2t TeVH1Dauf6fo2O1SSskF3bAYsCwxVQpCY+Nxr+jZRrkhgtBqzlr52Axf4wp3dGCBHQY5 syNZHSl6hFHgUXeAf2av18uUKSjmYi30d2lwOhvaPNM49l70+wEvoz6UTu8Jz9SGXsXl k17Q== 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:arc-authentication-results; bh=9uefaemWeBaBq9N6z/x9dIIcMwz8r1SeT5LjTrguLDw=; b=VXR98i2iodAEprO/pajyfS6y7ecPtq1XzIhUHvYGBi1539kW20MOy1vhBJmn24XEHy 97ZgLBYJy0SThuuzU4wgtoaQZb/yQV50Fw3ZiHI+e/QuBTz1q7njoo/SVZ6Utz7atAm8 EAOIXhGLPUxJ1/JLPzfOJNAa82uACGRgk2/5PcPodhzdqz29ZJ2AfpUhInhoGiHtff7h ig+FJM3f4gmvh1hhm8b2Mn8Rs9mfFzGF4/QN8QsGjntMsq+NyIDGe0/mRdj82CoUTQ+L qNqTayZxk48H92i4SsAJZrehfMLabBRuMa43umkC7homSUI5xla619qHdUj7miFMXBDh 8TFA== 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 f1-v6si5618269plf.453.2018.07.19.06.45.45; Thu, 19 Jul 2018 06:46:23 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731570AbeGSO1e (ORCPT + 99 others); Thu, 19 Jul 2018 10:27:34 -0400 Received: from mx2.suse.de ([195.135.220.15]:57158 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731105AbeGSO1e (ORCPT ); Thu, 19 Jul 2018 10:27: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 88C46AD5E; Thu, 19 Jul 2018 13:44:17 +0000 (UTC) Date: Thu, 19 Jul 2018 15:44:17 +0200 From: Michal Hocko To: osalvador@techadventures.net Cc: akpm@linux-foundation.org, pasha.tatashin@oracle.com, vbabka@suse.cz, aaron.lu@intel.com, iamjoonsoo.kim@lge.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Oscar Salvador Subject: Re: [PATCH v2 3/5] mm/page_alloc: Optimize free_area_init_core Message-ID: <20180719134417.GC7193@dhcp22.suse.cz> References: <20180719132740.32743-1-osalvador@techadventures.net> <20180719132740.32743-4-osalvador@techadventures.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180719132740.32743-4-osalvador@techadventures.net> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 19-07-18 15:27:38, osalvador@techadventures.net wrote: > From: Oscar Salvador > > In free_area_init_core we calculate the amount of managed pages > we are left with, by substracting the memmap pages and the pages > reserved for dma. > With the values left, we also account the total of kernel pages and > the total of pages. > > Since memmap pages are calculated from zone->spanned_pages, > let us only do these calculcations whenever zone->spanned_pages is greather > than 0. But why do we care? How do we test this? In other words, why is this worth merging? > > Signed-off-by: Oscar Salvador > --- > mm/page_alloc.c | 73 ++++++++++++++++++++++++++++++--------------------------- > 1 file changed, 38 insertions(+), 35 deletions(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 10b754fba5fa..f7a6f4e13f41 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -6237,6 +6237,40 @@ static void pgdat_init_kcompactd(struct pglist_data *pgdat) > static void pgdat_init_kcompactd(struct pglist_data *pgdat) {} > #endif > > +static unsigned long calc_remaining_pages(enum zone_type type, unsigned long freesize, > + unsigned long size) > +{ > + unsigned long memmap_pages = calc_memmap_size(size, freesize); > + > + if(!is_highmem_idx(type)) { > + if (freesize >= memmap_pages) { > + freesize -= memmap_pages; > + if (memmap_pages) > + printk(KERN_DEBUG > + " %s zone: %lu pages used for memmap\n", > + zone_names[type], memmap_pages); > + } else > + pr_warn(" %s zone: %lu pages exceeds freesize %lu\n", > + zone_names[type], memmap_pages, freesize); > + } > + > + /* Account for reserved pages */ > + if (type == 0 && freesize > dma_reserve) { > + freesize -= dma_reserve; > + printk(KERN_DEBUG " %s zone: %lu pages reserved\n", > + zone_names[0], dma_reserve); > + } > + > + if (!is_highmem_idx(type)) > + nr_kernel_pages += freesize; > + /* Charge for highmem memmap if there are enough kernel pages */ > + else if (nr_kernel_pages > memmap_pages * 2) > + nr_kernel_pages -= memmap_pages; > + nr_all_pages += freesize; > + > + return freesize; > +} > + > /* > * Set up the zone data structures: > * - mark all pages reserved > @@ -6267,43 +6301,12 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat) > > for (j = 0; j < MAX_NR_ZONES; j++) { > struct zone *zone = pgdat->node_zones + j; > - unsigned long size, freesize, memmap_pages; > + unsigned long size = zone->spanned_pages; > + unsigned long freesize = zone->present_pages; > unsigned long zone_start_pfn = zone->zone_start_pfn; > > - size = zone->spanned_pages; > - freesize = zone->present_pages; > - > - /* > - * Adjust freesize so that it accounts for how much memory > - * is used by this zone for memmap. This affects the watermark > - * and per-cpu initialisations > - */ > - memmap_pages = calc_memmap_size(size, freesize); > - if (!is_highmem_idx(j)) { > - if (freesize >= memmap_pages) { > - freesize -= memmap_pages; > - if (memmap_pages) > - printk(KERN_DEBUG > - " %s zone: %lu pages used for memmap\n", > - zone_names[j], memmap_pages); > - } else > - pr_warn(" %s zone: %lu pages exceeds freesize %lu\n", > - zone_names[j], memmap_pages, freesize); > - } > - > - /* Account for reserved pages */ > - if (j == 0 && freesize > dma_reserve) { > - freesize -= dma_reserve; > - printk(KERN_DEBUG " %s zone: %lu pages reserved\n", > - zone_names[0], dma_reserve); > - } > - > - if (!is_highmem_idx(j)) > - nr_kernel_pages += freesize; > - /* Charge for highmem memmap if there are enough kernel pages */ > - else if (nr_kernel_pages > memmap_pages * 2) > - nr_kernel_pages -= memmap_pages; > - nr_all_pages += freesize; > + if (size) > + freesize = calc_remaining_pages(j, freesize, size); > > /* > * Set an approximate value for lowmem here, it will be adjusted > -- > 2.13.6 > -- Michal Hocko SUSE Labs