Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp639266imm; Wed, 18 Jul 2018 08:12:47 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdgkbuzBYzDddJqE9ip3me/lN5d8s3uXuZYxQ6mxeeKq58JDeEpVnhLgRMTlBoUkhJfM2uQ X-Received: by 2002:a63:4002:: with SMTP id n2-v6mr5986434pga.285.1531926767102; Wed, 18 Jul 2018 08:12:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531926767; cv=none; d=google.com; s=arc-20160816; b=rlfvSTSWb/3yHSLDMMMeMjeQixUoce+cZzKcE8JeGC1vF7gSHvqNAuHLF9Wxi/7u0/ N8qGmXbuF8qPhQxJsS2+nsJnfX6vu8OmViyURKJslCjP4E8xdGbCfELf8Es575SkjZ9l VzIb5U3tx2taBWBHqvC/Aa0Fr1ghlzuO9CUOM2bbscR4fUgEbH4Loeo9VpeTq8JPlqTJ 6f/cBnragoMTqZ1D2T/oiGzCHRGAp7m4vs4+uwrAsVffHi0haGIe4miVQrZUGitzAP2m qweXZnuUFwljHTDh31dbK5KV1yKW0dztxuIzhWGmOzOYYzDz3Rj5zZ+FCLnsw7IbEvBk AATg== 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=yiTp/QPwxlU6Kfz9q14e/0xmHpkGJGdDCL629dIVa/0=; b=WHfnBVZVEKCeB/3nYq2v03WyylA5VnAAM/fxE/JzhOXqBVg/1pn8XdkHvwaKE0iq6E ylVPrLB5piageQW3fBsIUDeRfkTAs1wdm7QLSIfVywbYaze1/ExMnG7voRLJROaJzKzt 2EPaykYF3ZtAnfdEhJ9QYwOgw3YYvp/+ICetQst24QlmfPZtyyZ8fhd8a8UtWLEvbH6B OvCzR2pdM/enrviX/4S4DguLFKzGyv9bOh2QbxJXW9HDv/WHXtRKTDtHfe3XYuPruRb3 rpgYWrABnTlEWN7G5h7c91EFW9TWUDUK/xQ3sQEO7ygHsc27+wKHxUob3KH2nc+H6WPZ EV+g== 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 cc1-v6si3516175plb.458.2018.07.18.08.12.32; Wed, 18 Jul 2018 08:12:47 -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 S1730899AbeGRPuT (ORCPT + 99 others); Wed, 18 Jul 2018 11:50:19 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:36301 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730651AbeGRPuT (ORCPT ); Wed, 18 Jul 2018 11:50:19 -0400 Received: by mail-wm0-f66.google.com with SMTP id s14-v6so3289183wmc.1 for ; Wed, 18 Jul 2018 08:11:56 -0700 (PDT) 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=yiTp/QPwxlU6Kfz9q14e/0xmHpkGJGdDCL629dIVa/0=; b=ATvBFbXBA2yGLbNPGKxDNqpdhEa/o/R7JS9UiYw/PnAu9dMZkGAI09HSOIL81DvZhU k2jX9VM9agDwdDlyYzh61yvuwhj1B0agdkU5D+F+vVhaSFwQyBQhARaykX+NJ76I4d9f A200rLdK7UbSnm8jvJ7+OfxZFg1yYLbYAhSPjIxbo9CY9ZB0+FhAFvnllWj6b8Qhc2yZ tKJdtcSKbxiuXzXRX8nIXHcWEG3z7AFmOMpVTGlgoEbvlGzqEFEXXmSxoQwEoiO3/Fsg o/EGEsKPj5Hq7KVx76H57nUPQGpUJiHfYTd5aqJSkhTRFBgzc1/oBEAynlwZqKuq9Dhp kacA== X-Gm-Message-State: AOUpUlElN5jYe9tK6p5Tvkh40sMGmp9nxuW4IO1OMDaAcpLKCya/ARij 7PUFP5Ktq9j9ATJyHkTV5Xc= X-Received: by 2002:a1c:b6d6:: with SMTP id g205-v6mr2010950wmf.17.1531926716332; Wed, 18 Jul 2018 08:11:56 -0700 (PDT) Received: from techadventures.net (techadventures.net. [62.201.165.239]) by smtp.gmail.com with ESMTPSA id 14-v6sm6187958wmg.0.2018.07.18.08.11.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jul 2018 08:11:55 -0700 (PDT) Received: by techadventures.net (Postfix, from userid 1000) id 042CA1240EB; Wed, 18 Jul 2018 17:11:54 +0200 (CEST) Date: Wed, 18 Jul 2018 17:11:54 +0200 From: Oscar Salvador To: Michal Hocko Cc: akpm@linux-foundation.org, pasha.tatashin@oracle.com, vbabka@suse.cz, iamjoonsoo.kim@lge.com, aaron.lu@intel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Oscar Salvador Subject: Re: [PATCH 2/3] mm/page_alloc: Refactor free_area_init_core Message-ID: <20180718151154.GA2875@techadventures.net> References: <20180718124722.9872-1-osalvador@techadventures.net> <20180718124722.9872-3-osalvador@techadventures.net> <20180718133647.GD7193@dhcp22.suse.cz> <20180718141226.GA2588@techadventures.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180718141226.GA2588@techadventures.net> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 18, 2018 at 04:12:26PM +0200, Oscar Salvador wrote: > On Wed, Jul 18, 2018 at 03:36:47PM +0200, Michal Hocko wrote: > > I really do not like this if node is offline than only perform half of > > the function. This will generate more mess in the future. Why don't you > > simply. If we can split out this code into logical units then let's do > > that but no, please do not make random ifs for hotplug code paths. > > Sooner or later somebody will simply don't know what is needed and what > > is not. > > Yes, you are right. > I gave it another thought and it was not a really good idea. > Although I think the code from free_area_init_core can be simplified. > > I will try to come up with something that makes more sense. I guess we could so something like: diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 8a73305f7c55..70fe4c80643f 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 (freesize) + So we just do the calculations with the pages (nr_kernel_pages, nr_all_pages, memmap_pages, etc...) if freesize is not 0. Otherwise it does not make sense to do it (AFAICS). -- Oscar Salvador SUSE L3