From patchwork Thu Jul 19 13:27:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10534419 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 8B920601D2 for ; Thu, 19 Jul 2018 13:27:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7573B298CC for ; Thu, 19 Jul 2018 13:27:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69A47298DD; Thu, 19 Jul 2018 13:27:56 +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=unavailable 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 0584D298CC for ; Thu, 19 Jul 2018 13:27:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B6E446B026B; Thu, 19 Jul 2018 09:27:49 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B03276B026C; Thu, 19 Jul 2018 09:27:49 -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 843106B026E; Thu, 19 Jul 2018 09:27:49 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by kanga.kvack.org (Postfix) with ESMTP id 0CF3F6B026B for ; Thu, 19 Jul 2018 09:27:49 -0400 (EDT) Received: by mail-wr1-f72.google.com with SMTP id d10-v6so3659656wrw.6 for ; Thu, 19 Jul 2018 06:27:48 -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:from:to:cc :subject:date:message-id:in-reply-to:references; bh=9kGTuFtM1X19n3S4sGAGaBCTvUCGMgulE2XHKU/6q7c=; b=b/ltwW3/pSbjD0NlI8ZoV7+X6MwbOZPEA0qZfeZ8cKz877+wi+aokBKmm0n3ZKbEO1 1Ixo1z1f7lB8HVHJsrlIwKsR0Q/hfALCZtY/XqJ7B8Qw/TdZX56N4rZWcCHn8RAnXSSt h2Q8onI5V345aVkwxECzF/fZAxcB6Nble/eXBY2/HZivqRcrm6MVa9a6nzi34c53hBVL ynG6NdX7w+9H5XiQO1nb39UKqGp4dLwmREZWnEuvZuED7whiyvOrhVFHEOCplG6yg8iA rM1DgRXvDQKcThGKVkpeaa+jm+enfbT9TIZo9jtROUy9p4NlZa7tuY0HQtibGZ7qfNCM oEhQ== 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: AOUpUlH21u9LlIkrrc0VP6sIKGPKoXhMoJamZ6yhpHzXKuiPqqbJ0wud ZatwY4Cnq3znQE2w5o3LaWNcBK3LRQ+UwWBrwFXlv7OeboV0aTqYJ/ScRsdGREK+V3JsDo+pxvQ Q4o6shZoR8wEbQy12/T7nMSdSP5aNJ4rZ9aiR66wIouaCKBVS2F4lsk+OHeNIGvriIrU1SBK9mC zbgfGMaIWb5zUYKYtvZ/wmsU/kGBqtUWeWqTTsRTpOGv+DHjf9AebnJrF3nDsPKcavSJI72bVtl 6N8oTaXi2VCrjKELafJHUQa2CamTtzRkiTQ9c8V7zdfOUaJwQIUIrQoXRZbCB5hyVcscfR/Acpc QKL7yINqgBkE/lyaMtWlCsCZO0MGKS5LfVSdiZGWJGaf0M+GT/Jvss2Ng1+2A+STpVI0R+KuIQ= = X-Received: by 2002:adf:ed41:: with SMTP id u1-v6mr7214493wro.262.1532006868614; Thu, 19 Jul 2018 06:27:48 -0700 (PDT) X-Received: by 2002:adf:ed41:: with SMTP id u1-v6mr7214474wro.262.1532006867924; Thu, 19 Jul 2018 06:27:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532006867; cv=none; d=google.com; s=arc-20160816; b=Mrn2jUD7ntE0y0o4xQM0dE4TY3QkVgPiEWbhxu6/Sx/U05qaetdNn5Cfm8JNhWwVpF Dbzdb5k80Cgjb5tYLAUZQbkqX8yv0ST9FWh5qxBONKFDXTTXWa7d5qLPDwTQflEIo20U 5AFDV6U+wvI2Q39rcVfNhwO4APhIQVK709raYb6ACF5IEJ701iRUr3Stf3yugFXOzFPD qf5WtBg3wDOExg9Zoa1zkULQE9tGJVWH+IhspE5zj/4xPwjilLhQq8ryIazDbcdXp3Pz Ky9Kk8Z+n85SoM+A0JCuaDzkvA08lbT86WaB1ixZ/O4Ah2PjRtpFM73zcoA+CY5XHH1s 65yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=9kGTuFtM1X19n3S4sGAGaBCTvUCGMgulE2XHKU/6q7c=; b=pBO6uBKXTf985d9F4drOafnEAnbDj8hPRK8Ijecg66u2FQldiBAetZnP2a9YvjtBux JNDBttb+Y0pnrSYPR5P1QSxA7Vh5OggfJ0JZSmbvBJ+H0eOzarEAzNJROIqmajMBvIW3 G1BrDQvPMWuxAF8luYY600C+qfyqz8I5deT6f/7DiQfz6xyONa5dIonmqdL4DS2i1wik f5WsjYXDM+8QcQVQD+GOgy9Dp+Lr0AV2nEieKZJZ/Y1N5/w+1nAYrq86Xi7cyqi5wUl1 OsuNwx7eBpKNQryDo+e+rMa0+I4bKNYsixYMhSNUVSo5Pj9kb/6+//80qHPZbrJGszU/ cwvw== 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 l5-v6sor1201560wml.63.2018.07.19.06.27.47 for (Google Transport Security); Thu, 19 Jul 2018 06:27:47 -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: AAOMgpc7ZXs6UFZ2/S4nyQsO9knxurZ94Yr7I07UsL4tjXrgWQPdaIzpWGEwK0TULJaR+Y8bPxdP3w== X-Received: by 2002:a1c:5c93:: with SMTP id q141-v6mr4324508wmb.133.1532006867605; Thu, 19 Jul 2018 06:27:47 -0700 (PDT) Received: from techadventures.net (techadventures.net. [62.201.165.239]) by smtp.gmail.com with ESMTPSA id o4-v6sm11094930wra.3.2018.07.19.06.27.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 06:27:45 -0700 (PDT) Received: from d104.suse.de (charybdis-ext.suse.de [195.135.221.2]) by techadventures.net (Postfix) with ESMTPA id 250BB124174; Thu, 19 Jul 2018 15:27:45 +0200 (CEST) From: osalvador@techadventures.net To: akpm@linux-foundation.org Cc: pasha.tatashin@oracle.com, mhocko@suse.com, vbabka@suse.cz, aaron.lu@intel.com, iamjoonsoo.kim@lge.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Oscar Salvador Subject: [PATCH v2 3/5] mm/page_alloc: Optimize free_area_init_core Date: Thu, 19 Jul 2018 15:27:38 +0200 Message-Id: <20180719132740.32743-4-osalvador@techadventures.net> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180719132740.32743-1-osalvador@techadventures.net> References: <20180719132740.32743-1-osalvador@techadventures.net> 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 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. 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