From: kettenis Date: Thu, 13 May 2021 16:08:16 +0000 (+0000) Subject: Make memreg_add() a bit smarter and have it merge adjacent regions. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=9943f01e02d3f9ce4926343f17e5035f8f368cf3;p=openbsd Make memreg_add() a bit smarter and have it merge adjacent regions. This should reduce the number of physical memory segments that we pass to uvm reducing the chance that we run out of physical memory segments and should make physical memory allocation a bit more efficient. ok patrick@ --- diff --git a/sys/arch/arm64/arm64/machdep.c b/sys/arch/arm64/arm64/machdep.c index 5ccb62e1e87..ed850519ac6 100644 --- a/sys/arch/arm64/arm64/machdep.c +++ b/sys/arch/arm64/arm64/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.63 2021/05/12 17:43:26 kettenis Exp $ */ +/* $OpenBSD: machdep.c,v 1.64 2021/05/13 16:08:16 kettenis Exp $ */ /* * Copyright (c) 2014 Patrick Wildt * Copyright (c) 2021 Mark Kettenis @@ -1189,6 +1189,20 @@ pmap_bootstrap_bs_map(bus_space_tag_t t, bus_addr_t bpa, bus_size_t size, void memreg_add(const struct fdt_reg *reg) { + int i; + + for (i = 0; i < nmemreg; i++) { + if (reg->addr == memreg[i].addr + memreg[i].size) { + memreg[i].size += reg->size; + return; + } + if (reg->addr + reg->size == memreg[i].addr) { + memreg[i].addr = reg->addr; + memreg[i].size += reg->size; + return; + } + } + if (nmemreg >= nitems(memreg)) return;