From adb3df05c6713518cdc6111f2f4c3f06359dce5a Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Fri, 18 Jul 2025 10:54:03 +0200 Subject: [PATCH] Allow even smaller memory limits. --- lib/std/io/io.c3 | 2 +- releasenotes.md | 1 + src/utils/vmem.c | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/std/io/io.c3 b/lib/std/io/io.c3 index b8398b942..77fbac8e4 100644 --- a/lib/std/io/io.c3 +++ b/lib/std/io/io.c3 @@ -1,4 +1,4 @@ -// Copyright (c) 2021-2022 Christoffer Lerno. All rights reserved. +// Copyright (c) 2021-2025 Christoffer Lerno. All rights reserved. // Use of this source code is governed by the MIT license // a copy of which can be found in the LICENSE_STDLIB file. module std::io; diff --git a/releasenotes.md b/releasenotes.md index e77d10405..2ab8517be 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -21,6 +21,7 @@ - `env::AUTHORS` and `env::AUTHOR_EMAILS` added. - Suppress codegen of panic printing with when panic messages are set to "off". - Implicit linking of libc math when libc math functions are used. +- Allow even smaller memory limits. ### Fixes - mkdir/rmdir would not work properly with substring paths on non-windows platforms. diff --git a/src/utils/vmem.c b/src/utils/vmem.c index b223224b1..6622cc051 100644 --- a/src/utils/vmem.c +++ b/src/utils/vmem.c @@ -28,20 +28,20 @@ static inline void mmap_init(Vmem *vmem, size_t size) } #elif PLATFORM_POSIX void* ptr = NULL; - size_t min_size = size / 32; + size_t min_size = size / 128; if (min_size < 1) min_size = size; while (size >= min_size) { ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); // It worked? - if (ptr != MAP_FAILED && ptr) break; + if (ptr != MAP_FAILED) break; // Did it fail in a non-retriable way? if (errno != ENOMEM && errno != EOVERFLOW && errno != EAGAIN) break; // Try a smaller size size /= 2; } // Check if we ended on a failure. - if ((ptr == MAP_FAILED) || !ptr) + if (ptr == MAP_FAILED) { FATAL_ERROR("Failed to map a virtual memory block."); }