From patchwork Fri Jul 20 10:03:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10536393 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 D04C56053F for ; Fri, 20 Jul 2018 10:03:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B8E61293FF for ; Fri, 20 Jul 2018 10:03:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACAAA29533; Fri, 20 Jul 2018 10:03:32 +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 1C42A293FF for ; Fri, 20 Jul 2018 10:03:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C3BD56B0006; Fri, 20 Jul 2018 06:03:30 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BC5646B0007; Fri, 20 Jul 2018 06:03:30 -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 A8FB56B0266; Fri, 20 Jul 2018 06:03:30 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id 426896B0006 for ; Fri, 20 Jul 2018 06:03:30 -0400 (EDT) Received: by mail-ed1-f71.google.com with SMTP id c2-v6so4474679edi.20 for ; Fri, 20 Jul 2018 03:03:30 -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=1lcFQB3z8emiUI91XrT+zC2mcmQxznHsyGOmv+zVyIM=; b=Cp9FLHCW8y0Pu2zEjKtf1v5P9OsXv/SuULI+e9euN/IY3tvVT1LiizDLADu90apBZ+ W6F9wFXfAO5+vxzUZWw2RiWJ2rCDV93HlxbzX1CWolaLBzGeyiS/yndJJv4/2KVXUbLc chTAZqxN/XxBtk5NAqeRHuvmHMKw0pa1zwpGfZ3lmNTxL5rNvk63qVrvWjEc7PBfsX2D 8/hf3T7IO0r9rSX/VQZ3x0H9gtsSbNYZBWNVrEzNOCYu5RqL0sLZ1GdD3DVSlQoPqDKA O+PGekrbKPLT3fpEkOGnq95F/5Rn4rIuJxaCWO7A1UZK7+wkRX1bpr2/aHCk67bobyd+ 2HMw== 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: AOUpUlGSPD97LiGWaho5kKr3/wCx+JrJGp3uArFwKSzACh17hubgf7sP eQmRLphQ80B/uWCprQJfl9e3aYFxxwVvRNbJpbV+QW989aHqUlRgToQ0LLHpPBLwUIpQOzU5bUo /oGqTfpUrKrLg1phPH/OcZJ/cNIm1oAHudJaw3UcKoDGLquzF4KsK4mGV31kMYcgYbUi3HpwG7k Zi4weggMnQ6qRau6JCJgv6Deka/rIUsA2Oz/RGyx3g6LY6ZYV5MJtdTuBWU51d2V2CDKy3dFq8Z zDj/kN1RC97jikYAbG1WK3+7iTyfMRkNen4DiSP5ajtu20VHdTtAEmiuUhvGh/to/Z6zdO4BAtr Uhoo7mOEVn3AYgXUdUW3Yg/9uLnPMgzzRX0hPFCTnqwJtezasNHxRSojab8TjvSFEfQJeKY2OQ= = X-Received: by 2002:a50:f78a:: with SMTP id h10-v6mr1835813edn.37.1532081009664; Fri, 20 Jul 2018 03:03:29 -0700 (PDT) X-Received: by 2002:a50:f78a:: with SMTP id h10-v6mr1835754edn.37.1532081008795; Fri, 20 Jul 2018 03:03:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532081008; cv=none; d=google.com; s=arc-20160816; b=CDdzvqH7tw4d1Qfyl71FQggUFuH4JCFsHG3WBuCDuRi6nIhIFy37YDxTH+E8fYDaBL kwzgj3QRCUQsqIBn84f0OH4RI5S5qJF3aP91DebGVMBDUTXFw31JkpvcJ+VSP6Eju71/ 77p5e7kjzf2OhA6TdYbcGGreVay/Bfa+S387Gew1WCqZhp458XKfmAJBF1YL6efl0IJO BMt0vVrDGyeqBP48CiBbf7a3/b+xU0YCs4FJMx3NggbDe5QPybDTXV6wLoJOuwSncRRb vuK7ean6ik1EFH5F+lBns4+JqJJy6Km/LEuTFvV11g1bX+Exk4M28Z8S3EKBV5ShnZSh n/2w== 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=1lcFQB3z8emiUI91XrT+zC2mcmQxznHsyGOmv+zVyIM=; b=B+Ned40iAqOaaPKHe/aIjxAflXvBRuf4LKu8VER5SrCOMQZMJPJyffKEWZEwOxa5aP ZCOpERhzxVWbru3ANnrjgOP7c+7Q5quBYZ/9Fgg1izsdTaNQCmdHa8fyxqmp9s1q1CpG LX+ZzhBujVqD8R/sdfx0vNJtr/IiwF4x8jiwHNHkH1uIXEXSgrFYm28TaCFi9y8gq91c 4HfwEMCSaxI20vFJJo96PB3HxPtr76ZASv7SuN9H/he0qolkOOgJvan1UkzjyGXqzxsM 4VDJg+sZyhXoqwAqoEo3KDC9o9AV4Qn/0Hh7VYUGVRM8Xnm41MN3qjwkTsNETQ83nEgc grIA== 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 h4-v6sor956610edq.9.2018.07.20.03.03.28 for (Google Transport Security); Fri, 20 Jul 2018 03:03:28 -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: AAOMgpcg6YCiWXZ905uMX3xWpCPNFt7o9q8XF8uIVGNQCVjrfqB/gYq3XRbgK7StCI43UzVadKscjw== X-Received: by 2002:a50:9fe9:: with SMTP id c96-v6mr1886040edf.17.1532081008443; Fri, 20 Jul 2018 03:03:28 -0700 (PDT) Received: from techadventures.net (techadventures.net. [62.201.165.239]) by smtp.gmail.com with ESMTPSA id u3-v6sm898646edo.44.2018.07.20.03.03.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Jul 2018 03:03:27 -0700 (PDT) Received: by techadventures.net (Postfix, from userid 1000) id 2CD751241D6; Fri, 20 Jul 2018 12:03:27 +0200 (CEST) Date: Fri, 20 Jul 2018 12:03:27 +0200 From: Oscar Salvador To: Michal Hocko 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: <20180720100327.GA19478@techadventures.net> References: <20180719132740.32743-1-osalvador@techadventures.net> <20180719132740.32743-4-osalvador@techadventures.net> <20180719134417.GC7193@dhcp22.suse.cz> <20180719140327.GB10988@techadventures.net> <20180719151555.GH7193@dhcp22.suse.cz> <20180719205235.GA14010@techadventures.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180719205235.GA14010@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 Thu, Jul 19, 2018 at 10:52:35PM +0200, Oscar Salvador wrote: > On Thu, Jul 19, 2018 at 05:15:55PM +0200, Michal Hocko wrote: > > Your changelog doesn't really explain the motivation. Does the change > > help performance? Is this a pure cleanup? > > Hi Michal, > > Sorry to not have explained this better from the very beginning. > > It should help a bit in performance terms as we would be skipping those > condition checks and assignations for zones that do not have any pages. > It is not a huge win, but I think that skipping code we do not really need to run > is worh to have. > > > The function is certainly not an example of beauty. It is more an > > example of changes done on top of older ones without much thinking. But > > I do not see your change would make it so much better. I would consider > > it a much nicer cleanup if it was split into logical units each doing > > one specific thing. > > About the cleanup, I thought that moving that block of code to a separate function > would make the code easier to follow. > If you think that this is still not enough, I can try to split it and see the outcome. I tried to split it innto three logical blocks: - Substract memmap pages - Substract dma reserves - Account kernel pages (nr_kernel_pages and nr_total_pages) Is this something that makes sense to you: SUSE L3 diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 10b754fba5fa..1397dcdd4a3c 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6237,6 +6237,47 @@ static void pgdat_init_kcompactd(struct pglist_data *pgdat) static void pgdat_init_kcompactd(struct pglist_data *pgdat) {} #endif +static void account_kernel_pages(enum zone_type j, unsigned long freesize, + unsigned long memmap_pages) +{ + 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; +} + +static unsigned long substract_dma_reserves(unsigned long freesize) +{ + /* Account for reserved pages */ + if (freesize > dma_reserve) { + freesize -= dma_reserve; + printk(KERN_DEBUG " %s zone: %lu pages reserved\n", + zone_names[0], dma_reserve); + } + + return freesize; +} + +static unsigned long substract_memmap_pages(unsigned long freesize, unsigned long memmap_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 + */ + 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); + return freesize; +} + /* * Set up the zone data structures: * - mark all pages reserved @@ -6267,44 +6308,20 @@ 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); - } + if (size) { + unsigned long memmap_pages = calc_memmap_size(size, freesize); + if (!is_highmem_idx(j)) + freesize = substract_memmap_pages(freesize, memmap_pages); - /* 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 (j == ZONE_DMA) + freesize = substract_dma_reserves(freesize); + account_kernel_pages(j, freesize, memmap_pages); } - 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; Thanks -- Oscar Salvador