Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3545520imu; Fri, 30 Nov 2018 02:02:47 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vso4cTirSK4Ul4R7Np4vWQvrN0hjwt+0LQKPB+g2OFsq0bUMTW1LLzEC9Tb9Ty73lkbgFb X-Received: by 2002:a65:5286:: with SMTP id y6mr4303547pgp.439.1543572167028; Fri, 30 Nov 2018 02:02:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543572167; cv=none; d=google.com; s=arc-20160816; b=KCuX0kDfXTTRD5/9J5JfpaYlo/AWcBpqrUbJN/Y9xbmZt6DHnHphjZvVCoTVvsVGRg NQOZfhjvVufjS7aafPtkYrx2mPadAl2gc0G0GX6H4Nb8pF7gRP2LaQkv7Wz6SJvat7n3 P5y/nRktw/82zzdKsRTVE3p5YZH6XYK6VpzXe+ouN2vjaLfqw10q+ZRWKYRRCZp/dKb1 XrHnNg+PVNz2cZqYmDtF7t6uFK32uEkutPRhDtwoqppGM1oNOmaKTTnb5RxOCEP4l6zb IKWNeTMLO6gbqLQIJMc4KUFj2WPl1Z8hwT5CD0im5rCSepVShiCB9SrFgYVSvHS2aTe1 HhSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=xFEoKvjcGPQh7r42S/NsMQAqQa48vXVtedyXDF6MyJw=; b=Sh+YpdlqAbmc6j4EqTiVelmqeGo0ChIKOpTt+GnKjVeqYZtjwBkHZQhgQLsU8XLr5Y jZscGyGO+lDXlFXGo3PtAUyRP7BWZTz+Ph1lUPaH9saVrKfw1eQ+hquS/xMW0TGwWjiw bB8pO2LkPAFllKbywWbZqsmMyKs37tUP48IARdeviG6U/uzF1xdK0NSzt6LGwpa0oXKd rjgC34D7OsnSb3gvR0emIv1k8sknlhu+kYFnlWxLD9wz3AQJn3fOFq9xv6eZUlCrLKAq NIfC9Rvrqo8fcq7wndAIbANJ+ZXDs7wA+27NWBDPXhg0phPXJTJh/KBIQoFxxNO47ZdF 9R3g== 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 bc7si4816293plb.120.2018.11.30.02.02.31; Fri, 30 Nov 2018 02:02:46 -0800 (PST) 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 S1726659AbeK3VKk (ORCPT + 99 others); Fri, 30 Nov 2018 16:10:40 -0500 Received: from terminus.zytor.com ([198.137.202.136]:44131 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726512AbeK3VKk (ORCPT ); Fri, 30 Nov 2018 16:10:40 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id wAUA0voR3262457 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 30 Nov 2018 02:00:57 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id wAUA0vtj3262454; Fri, 30 Nov 2018 02:00:57 -0800 Date: Fri, 30 Nov 2018 02:00:57 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Ard Biesheuvel Message-ID: Cc: marc.zyngier@arm.com, peterz@infradead.org, bhsharma@redhat.com, jonathanh@nvidia.com, arend.vanspriel@broadcom.com, julien.thierry@arm.com, natechancellor@gmail.com, bp@alien8.de, torvalds@linux-foundation.org, joe@perches.com, mingo@kernel.org, ard.biesheuvel@linaro.org, hpa@zytor.com, sai.praneeth.prakhya@intel.com, sedat.dilek@gmail.com, eric.snowberg@oracle.com, dave.hansen@intel.com, hdegoede@redhat.com, linux-kernel@vger.kernel.org, matt@codeblueprint.co.uk, luto@kernel.org, zhuyifei1999@gmail.com, tglx@linutronix.de Reply-To: julien.thierry@arm.com, arend.vanspriel@broadcom.com, natechancellor@gmail.com, bp@alien8.de, torvalds@linux-foundation.org, bhsharma@redhat.com, jonathanh@nvidia.com, peterz@infradead.org, marc.zyngier@arm.com, tglx@linutronix.de, luto@kernel.org, matt@codeblueprint.co.uk, linux-kernel@vger.kernel.org, hdegoede@redhat.com, zhuyifei1999@gmail.com, ard.biesheuvel@linaro.org, hpa@zytor.com, sai.praneeth.prakhya@intel.com, sedat.dilek@gmail.com, eric.snowberg@oracle.com, dave.hansen@intel.com, joe@perches.com, mingo@kernel.org In-Reply-To: <20181129171230.18699-11-ard.biesheuvel@linaro.org> References: <20181129171230.18699-11-ard.biesheuvel@linaro.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:efi/core] efi: Reduce the amount of memblock reservations for persistent allocations Git-Commit-ID: 80424b02d42bb22f8ff8839cb93a84ade53b39c0 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=1.6 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_48_96,FREEMAIL_FORGED_REPLYTO, FREEMAIL_REPLYTO_END_DIGIT autolearn=no autolearn_force=no version=3.4.2 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 80424b02d42bb22f8ff8839cb93a84ade53b39c0 Gitweb: https://git.kernel.org/tip/80424b02d42bb22f8ff8839cb93a84ade53b39c0 Author: Ard Biesheuvel AuthorDate: Thu, 29 Nov 2018 18:12:29 +0100 Committer: Ingo Molnar CommitDate: Fri, 30 Nov 2018 09:37:57 +0100 efi: Reduce the amount of memblock reservations for persistent allocations The current implementation of efi_mem_reserve_persistent() is rather naive, in the sense that for each invocation, it creates a separate linked list entry to describe the reservation. Since the linked list entries themselves need to persist across subsequent kexec reboots, every reservation created this way results in two memblock_reserve() calls at the next boot. On arm64 systems with 100s of CPUs, this may result in a excessive number of memblock reservations, and needless fragmentation. So instead, make use of the newly updated struct linux_efi_memreserve layout to put multiple reservations into a single linked list entry. This should get rid of the numerous tiny memblock reservations, and effectively cut the total number of reservations in half on arm64 systems with many CPUs. [ mingo: build warning fix. ] Tested-by: Marc Zyngier Signed-off-by: Ard Biesheuvel Cc: Andy Lutomirski Cc: Arend van Spriel Cc: Bhupesh Sharma Cc: Borislav Petkov Cc: Dave Hansen Cc: Eric Snowberg Cc: Hans de Goede Cc: Joe Perches Cc: Jon Hunter Cc: Julien Thierry Cc: Linus Torvalds Cc: Matt Fleming Cc: Nathan Chancellor Cc: Peter Zijlstra Cc: Sai Praneeth Prakhya Cc: Sedat Dilek Cc: Thomas Gleixner Cc: YiFei Zhu Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/20181129171230.18699-11-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar --- drivers/firmware/efi/efi.c | 21 +++++++++++++++++---- include/linux/efi.h | 3 +++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 80b11521627a..4c46ff6f2242 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -997,8 +997,8 @@ static int __init efi_memreserve_map_root(void) int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size) { struct linux_efi_memreserve *rsv; - int rsvsize = EFI_MEMRESERVE_SIZE(1); - int rc; + unsigned long prsv; + int rc, index; if (efi_memreserve_root == (void *)ULONG_MAX) return -ENODEV; @@ -1009,11 +1009,24 @@ int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size) return rc; } - rsv = kmalloc(rsvsize, GFP_ATOMIC); + /* first try to find a slot in an existing linked list entry */ + for (prsv = efi_memreserve_root->next; prsv; prsv = rsv->next) { + rsv = __va(prsv); + index = atomic_fetch_add_unless(&rsv->count, 1, rsv->size); + if (index < rsv->size) { + rsv->entry[index].base = addr; + rsv->entry[index].size = size; + + return 0; + } + } + + /* no slot found - allocate a new linked list entry */ + rsv = (struct linux_efi_memreserve *)__get_free_page(GFP_ATOMIC); if (!rsv) return -ENOMEM; - rsv->size = 1; + rsv->size = EFI_MEMRESERVE_COUNT(PAGE_SIZE); atomic_set(&rsv->count, 1); rsv->entry[0].base = addr; rsv->entry[0].size = size; diff --git a/include/linux/efi.h b/include/linux/efi.h index 4f27640fdcdc..becd5d76a207 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1724,4 +1724,7 @@ struct linux_efi_memreserve { #define EFI_MEMRESERVE_SIZE(count) (sizeof(struct linux_efi_memreserve) + \ (count) * sizeof(((struct linux_efi_memreserve *)0)->entry[0])) +#define EFI_MEMRESERVE_COUNT(size) (((size) - sizeof(struct linux_efi_memreserve)) \ + / sizeof(((struct linux_efi_memreserve *)0)->entry[0])) + #endif /* _LINUX_EFI_H */