Skip to content

Commit 80424b0

Browse files
Ard BiesheuvelIngo Molnar
authored andcommitted
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 <marc.zyngier@arm.com> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Arend van Spriel <arend.vanspriel@broadcom.com> Cc: Bhupesh Sharma <bhsharma@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Eric Snowberg <eric.snowberg@oracle.com> Cc: Hans de Goede <hdegoede@redhat.com> Cc: Joe Perches <joe@perches.com> Cc: Jon Hunter <jonathanh@nvidia.com> Cc: Julien Thierry <julien.thierry@arm.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Matt Fleming <matt@codeblueprint.co.uk> Cc: Nathan Chancellor <natechancellor@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: YiFei Zhu <zhuyifei1999@gmail.com> Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/20181129171230.18699-11-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 5f0b0ec commit 80424b0

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

drivers/firmware/efi/efi.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -997,8 +997,8 @@ static int __init efi_memreserve_map_root(void)
997997
int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size)
998998
{
999999
struct linux_efi_memreserve *rsv;
1000-
int rsvsize = EFI_MEMRESERVE_SIZE(1);
1001-
int rc;
1000+
unsigned long prsv;
1001+
int rc, index;
10021002

10031003
if (efi_memreserve_root == (void *)ULONG_MAX)
10041004
return -ENODEV;
@@ -1009,11 +1009,24 @@ int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size)
10091009
return rc;
10101010
}
10111011

1012-
rsv = kmalloc(rsvsize, GFP_ATOMIC);
1012+
/* first try to find a slot in an existing linked list entry */
1013+
for (prsv = efi_memreserve_root->next; prsv; prsv = rsv->next) {
1014+
rsv = __va(prsv);
1015+
index = atomic_fetch_add_unless(&rsv->count, 1, rsv->size);
1016+
if (index < rsv->size) {
1017+
rsv->entry[index].base = addr;
1018+
rsv->entry[index].size = size;
1019+
1020+
return 0;
1021+
}
1022+
}
1023+
1024+
/* no slot found - allocate a new linked list entry */
1025+
rsv = (struct linux_efi_memreserve *)__get_free_page(GFP_ATOMIC);
10131026
if (!rsv)
10141027
return -ENOMEM;
10151028

1016-
rsv->size = 1;
1029+
rsv->size = EFI_MEMRESERVE_COUNT(PAGE_SIZE);
10171030
atomic_set(&rsv->count, 1);
10181031
rsv->entry[0].base = addr;
10191032
rsv->entry[0].size = size;

include/linux/efi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,4 +1724,7 @@ struct linux_efi_memreserve {
17241724
#define EFI_MEMRESERVE_SIZE(count) (sizeof(struct linux_efi_memreserve) + \
17251725
(count) * sizeof(((struct linux_efi_memreserve *)0)->entry[0]))
17261726

1727+
#define EFI_MEMRESERVE_COUNT(size) (((size) - sizeof(struct linux_efi_memreserve)) \
1728+
/ sizeof(((struct linux_efi_memreserve *)0)->entry[0]))
1729+
17271730
#endif /* _LINUX_EFI_H */

0 commit comments

Comments
 (0)