From patchwork Tue Oct 3 20:57:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 114718 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp2316145qgn; Tue, 3 Oct 2017 13:57:54 -0700 (PDT) X-Received: by 10.101.85.4 with SMTP id f4mr16307866pgr.10.1507064274023; Tue, 03 Oct 2017 13:57:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507064274; cv=none; d=google.com; s=arc-20160816; b=bwI+QMZtf6btY9DQM48iggmoUMuIk+OPDcaE/C6mUl/0UHzulJmerQtI6eEvZNeDTj L/sXcLSTIvCyhv+zkKCYdQDtvqTdv3iqOSUbVmR4MskNWdAjH9yMAyJe2UyT7KWe2f+I oHna73UNiSBUVGh+3MJwik4F3/LNjL+ZKARXU2K2nBXbo10azpmq73ySI8pZ/ZLt4EXw NBoH04AY1GLwE2VfixP1nfQvkqjfZ9Y1HUTQQauF0+bPabVya/fMcftaC+wv5UgzskVt 5II/7SEZ8QqHI3JRDyZ+y+Ie02MwOg5yAiPy7zVFayBYtJXirDTRsQmQqJZFmXfK68kQ yoSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :subject:cc:to:from:date:dkim-signature:arc-authentication-results; bh=hputbSEb75pM1URSWzUes7sfv6ZB7RPdPGhQjrURng8=; b=0mNAV93PH+4Bm+38G9nWKX6U0wQTMJ5ubawcNvl5MXpCirZqNtl+8bzUuEF6G3VWEa zuH/yxyUJx6C4O7NroTAqq+N7mrGaiF9ymtRU5wJotTtOfP4HAYJVGeB7qgrqhPTlrkj lGb8gLD+C4qcVSR7x+GlPrJlYzljLAxhcyPh7YOYJUmbrx5K/Cj1E7QvdvNR+cvrH/Ki p7BAEzMECvZDiqS8y2TdQOH49y+gkeF8L14w9r11vwbDa4SxsdDK60ZmAaNaOZ6qV+LV ZWXM6qiI/MEQFbqJVU6Vi5H4OybZWUSRzpBeTfhDjsHt2SSBiquAbsG00hygIPTaMbIN k8fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=It39GShh; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z6si11372505plk.136.2017.10.03.13.57.53; Tue, 03 Oct 2017 13:57:54 -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; dkim=pass header.i=@linaro.org header.s=google header.b=It39GShh; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751811AbdJCU5w (ORCPT + 26 others); Tue, 3 Oct 2017 16:57:52 -0400 Received: from mail-qk0-f169.google.com ([209.85.220.169]:54159 "EHLO mail-qk0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751393AbdJCU5q (ORCPT ); Tue, 3 Oct 2017 16:57:46 -0400 Received: by mail-qk0-f169.google.com with SMTP id w63so9610262qkd.10 for ; Tue, 03 Oct 2017 13:57:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:user-agent:mime-version; bh=hputbSEb75pM1URSWzUes7sfv6ZB7RPdPGhQjrURng8=; b=It39GShh9jOu2DibHGWm5dCR9bHVFXZkildUCCySr8hyqSYGlsFUO3+M/DltMfo31h PFg4gGImAV4GHjvlL7BYKiUs0jAzK1OBiQ4Bx8wde19h/BQyWbN46MFtl83bImX/VyI1 byDEvGqaxlYaucAroPfLio6LHAETqKfspTtKs= 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:user-agent :mime-version; bh=hputbSEb75pM1URSWzUes7sfv6ZB7RPdPGhQjrURng8=; b=qc5a0CVgXAqOblmrqSY++Nias3birTWhsuegCOkp4SwNHsBl/ECV6rX/yGC5Y1U53s vNceUfj7lngqWZWTjcZ2ndxbAt2WPbNA63bvZDt0BjZZU8jdPnt5LR3HlUtMljohDqIW KLV0bMt8LyaKu5p9mmTfZaDo0lB/a/r6j3HRun5BewOaQffzUK3bgV9fFBMxGO1PQp0k l4LZz3OuG2W7ruR5weLcI1tHmXZcTWIZVCdW3v2MJ2EX3jdxMzc7jgXX3WAeuz1qnSPS hLjS3A6ES6bMetHmd2gMQkBZTBTK9Ng3AHiq4K7FzslzAdGM/TrWt6ATnF2Umg+JRrqe ZsPQ== X-Gm-Message-State: AMCzsaWm55AS0YDzlX3ZSXLLsaiNP/VyFG4pyGOJ1gXrOzR3o0G8C04T VMJVLOcPlNW3wzNaUmgPOVA55A== X-Google-Smtp-Source: AOwi7QBCAQraVqgkD8HDRNnsbmeXzastelIenxpzy6dqtS3vywDIWHGPTiEQyEGTxiFKuMDSw1jpHw== X-Received: by 10.55.36.7 with SMTP id w7mr21890372qkg.1.1507064266227; Tue, 03 Oct 2017 13:57:46 -0700 (PDT) Received: from xanadu.home (modemcable045.234-175-137.mc.videotron.ca. [137.175.234.45]) by smtp.gmail.com with ESMTPSA id h29sm9234410qtk.29.2017.10.03.13.57.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Oct 2017 13:57:45 -0700 (PDT) Date: Tue, 3 Oct 2017 16:57:44 -0400 (EDT) From: Nicolas Pitre To: Tejun Heo , Christoph Lameter cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/percpu.c: use smarter memory allocation for struct pcpu_alloc_info Message-ID: User-Agent: Alpine 2.21 (LFD 202 2017-01-01) MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This can be much smaller than a page on very small memory systems. Always rounding up the size to a page is wasteful in that case, and required alignment is smaller than the memblock default. Let's round things up to a page size only when the actual size is >= page size, and then it makes sense to page-align for a nicer allocation pattern. Signed-off-by: Nicolas Pitre Signed-off-by: Nicolas Pitre Signed-off-by: Nicolas Pitre diff --git a/mm/percpu.c b/mm/percpu.c index 434844415d..fe37f85cc2 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -1410,13 +1410,17 @@ struct pcpu_alloc_info * __init pcpu_alloc_alloc_info(int nr_groups, struct pcpu_alloc_info *ai; size_t base_size, ai_size; void *ptr; - int unit; + int unit, align; - base_size = ALIGN(sizeof(*ai) + nr_groups * sizeof(ai->groups[0]), - __alignof__(ai->groups[0].cpu_map[0])); + align = __alignof__(ai->groups[0].cpu_map[0]); + base_size = ALIGN(sizeof(*ai) + nr_groups * sizeof(ai->groups[0]), align); ai_size = base_size + nr_units * sizeof(ai->groups[0].cpu_map[0]); + if (ai_size >= PAGE_SIZE) { + ai_size = PFN_ALIGN(ai_size); + align = PAGE_SIZE; + } - ptr = memblock_virt_alloc_nopanic(PFN_ALIGN(ai_size), 0); + ptr = memblock_virt_alloc_nopanic(ai_size, align); if (!ptr) return NULL; ai = ptr; @@ -1428,7 +1432,7 @@ struct pcpu_alloc_info * __init pcpu_alloc_alloc_info(int nr_groups, ai->groups[0].cpu_map[unit] = NR_CPUS; ai->nr_groups = nr_groups; - ai->__ai_size = PFN_ALIGN(ai_size); + ai->__ai_size = ai_size; return ai; }