From patchwork Wed Jul 18 15:11:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10532661 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 01F916020A for ; Wed, 18 Jul 2018 15:12:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E30F626538 for ; Wed, 18 Jul 2018 15:11:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D57B7284E4; Wed, 18 Jul 2018 15:11:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50B2C26538 for ; Wed, 18 Jul 2018 15:11:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6A6826B0006; Wed, 18 Jul 2018 11:11:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6554B6B0007; Wed, 18 Jul 2018 11:11:58 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 51DE16B0008; Wed, 18 Jul 2018 11:11:58 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by kanga.kvack.org (Postfix) with ESMTP id EB3C86B0006 for ; Wed, 18 Jul 2018 11:11:57 -0400 (EDT) Received: by mail-wr1-f71.google.com with SMTP id z16-v6so2011256wrs.22 for ; Wed, 18 Jul 2018 08:11:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results: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=g9Sf39iAdqzV8YkYaFdl44SnRKEIty9cYG/fbRfqQraOb7jpmqNLs5enlxWU5KEKKi ao1neW2MFJ8RLsElvZYB8g9JSk9eoKq+2N4/kvyi5xbacqGc1+hWu+v/SNn7Q9pjPHVh 8pYV4Qix0ZuEtG51nPHjv3UWF594xoy0B3BNThG6jqFF/bWpNc8khu4zrv6LXK+lufnh yKI686e+RFoLpAr5TFYKSV6/ryAVGSEBYlamRR9uE2CffxNay9m7JxBurpGJkkEotGFY ygIWgwTJ8mHx8vYRahcylop31xIj1sAa0UqXtxMZygbcaMdw7VPLgM4vMULD8qBeGxMW Ey7Q== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=osalvador.vilardaga@gmail.com X-Gm-Message-State: AOUpUlEGVT7s6X9emw2AsSoWSnDu8IweNHOU0pB79fw8tdjiKxc2xEYm oYh/hNXObRRn6kVpuaS3b6EQUhB20p2bcUwvvLcohFDy+S2ZZj0+svCYvdp4a09HeVSl6dSsk2G cJb/2n2RaRmZZ8/cShd7o5953o/tI9b1dxpOzmdqbeOl1n3b/tu0TqqYNRR3P2bzbnbh0RraWup e5EMKiUqkUAsckUfNElxT9bi+PxfRl0Oi42+tLtwkQcmVVza+BLcRFoo6mfaQTHv3Vr6H/+qqv0 JPAd5Vu6W5OPz6dx5NrUs+6yuuIizkzWATTgAgIsXtTzlT/Qiag3jBsm7Yt55BX7+E2aEsCarCn TgvWS12PpJhzqo3x3HE/KsE31pJIdPwRxbcp/mb6+KJbGGz9mCwy4rjmz21svuXRZtcFQaziPQ= = X-Received: by 2002:adf:ed8e:: with SMTP id c14-v6mr4632606wro.264.1531926717512; Wed, 18 Jul 2018 08:11:57 -0700 (PDT) X-Received: by 2002:adf:ed8e:: with SMTP id c14-v6mr4632570wro.264.1531926716660; Wed, 18 Jul 2018 08:11:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531926716; cv=none; d=google.com; s=arc-20160816; b=XXJWMRqTIr8WgV1WTo4EdkY7Gwsm1PiQjrPT1n0PAOhbROSniwetQYhXlhOfcJbMSi UE19AfN7FRTNgkZxpao+NX6Ct8e3JKUrBYDo5SoT7mXE25x5+8+Pow2aVN72yR1wdPgi dks8xAw7o4WgU4CZQsEuEbKFfDP8gMFpvE3oeFn2Ba+bpqUnrAUhXj8qu0MnbfJblP9R JOuQ25OwCEBbwtJG5zn6ClFjx7EJZp7z0dttxvQoZgcPHdZ3gaBllelo5FzuLGAE3bbc 78tgcm5PZcgtPG2Lmq2tIN5y9jysTKFo45F4cWy/5+0Q5+ArWkvxOxiGyqI8w9VqHamr bmSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=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=eUiTEvRenfgUs1ikdS+IKRM7Cj7pF1d22Gr/QNxQc7775/HjrkHe+xyJzlCNTD7eUR 15WeqmVE0XDK5OELGbZaYGR/hoAHzryhdRlgZwmkXXKzpM3KC1mGKgqWZRyFbsOWnIHL TFqcDhGoBj1VmDoDkljVh/hsv3r62CuL42c1uGbe6rwsTwdwYKYuYwP3CDdC3kFMZyRN F1bdLBHz3DFrH6S0S8nGml5Ja+JkYhoe5N+5hEl2NqR+sFe8UqW+Bxj1kyVLwJXs1quy Vwi4JAygnLxgb3l+Dwg7U3KwphohOHUelCoFLKOdcsj9+tNZZUie0bSWqs6yoq6KHYTc pUAA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=osalvador.vilardaga@gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id 185-v6sor666349wmh.86.2018.07.18.08.11.56 for (Google Transport Security); Wed, 18 Jul 2018 08:11:56 -0700 (PDT) Received-SPF: pass (google.com: domain of osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=osalvador.vilardaga@gmail.com X-Google-Smtp-Source: AAOMgpc311EbtiJc8/mmfJJTmz5FbJFdrqo/i3pnPNLk/oLVJBaZ4EpICa3wHBNggBdLPLcLZbHp5g== 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-Disposition: inline In-Reply-To: <20180718141226.GA2588@techadventures.net> User-Agent: Mutt/1.5.23 (2014-03-12) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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: if freesize is not 0. Otherwise it does not make sense to do it (AFAICS). 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...)