When 32-bit code needs to allocate memory which remains permanent after completion of the initialization phase, it doesn't care if it is allocated from high-zone or low-zone.
Currently all these cases just attempt to allocate from high-zone as low-zone memory is scarce.
However, in cases we don't have enough space left in high-zone, it makes sense to use low-zone as a fallback.
This commit fixes an issue of a VM which failed to boot when configured with 16 PVSCSI disk controllers. The VM failed to boot because pvscsi_init_rings() failed to allocate ring_dsc when high-zone didn't had enough space for it.
Reviewed-by: Mark Kanda mark.kanda@oracle.com Signed-off-by: Liran Alon liran.alon@oracle.com --- src/malloc.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/malloc.h b/src/malloc.h index 960a7f8000f8..d8bf5092dce0 100644 --- a/src/malloc.h +++ b/src/malloc.h @@ -31,7 +31,10 @@ static inline void *malloc_low(u32 size) { return _malloc(&ZoneLow, size, MALLOC_MIN_ALIGN); } static inline void *malloc_high(u32 size) { - return _malloc(&ZoneHigh, size, MALLOC_MIN_ALIGN); + void *ret = _malloc(&ZoneHigh, size, MALLOC_MIN_ALIGN); + if (ret) + return ret; + return malloc_low(size); } static inline void *malloc_fseg(u32 size) { return _malloc(&ZoneFSeg, size, MALLOC_MIN_ALIGN); @@ -52,7 +55,10 @@ static inline void *memalign_low(u32 align, u32 size) { return _malloc(&ZoneLow, size, align); } static inline void *memalign_high(u32 align, u32 size) { - return _malloc(&ZoneHigh, size, align); + void *ret = _malloc(&ZoneHigh, size, align); + if (ret) + return ret; + return memalign_low(align, size); } static inline void *memalign_tmplow(u32 align, u32 size) { return _malloc(&ZoneTmpLow, size, align);