From 1bab3243f71c6a334c92e25cf673a8ac57539c47 Mon Sep 17 00:00:00 2001 From: nalepy <134861272+nalepy@users.noreply.github.com> Date: Sat, 11 Jul 2026 20:19:40 -0300 Subject: [PATCH] =?UTF-8?q?iobench:=20Windows=20correctness=20=E2=80=94=20?= =?UTF-8?q?aligned=20free,=2064-bit=20totals,=20full-range=20random=20offs?= =?UTF-8?q?ets=20(also=20improves=20Linux=20offset=20coverage)=20(#64)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Windows port audit fixes — _FILE_OFFSET_BITS guard, O_BINARY st.h, getrusage peak, oracle diagnostic, setup.sh wmic Audit remediation (all MEDIUM issues fixed): - compat.h: compile-time #error if _FILE_OFFSET_BITS < 64 on _WIN32 - compat.h: COMPAT_O_RDONLY macro (O_RDONLY|O_BINARY on Windows, belt-and-braces) - st.h: use COMPAT_O_RDONLY in both open() call sites (plan §1 row 1) - compat.h: getrusage shim now uses PeakWorkingSetSize (ru_maxrss = peak, not current) - glm.c: oracle mismatch diagnostic — prints position/expected/got on TF failures - setup.sh: replace deprecated wmic with /proc/meminfo (MSYS2 provides it) - .gitignore: *.exe, glm_tiny/, olmoe_hf/, olmoe_i4/ LOW issues addressed: - _FILE_OFFSET_BITS guard prevents silent 32-bit off_t wrap at >4GB offsets - coli Windows venv path (Scripts/python.exe) fixed earlier - posix_fadvise do{}while(0) kept intentionally — no caller checks return code Verification: oracle 32/32, 27/27 Python tests, rename EEXIST, >4GB pread offset. * docs: add Windows 11 native port section to README - Toolchain: MinGW-w64 (winlibs or MSYS2), GCC 16.1 tested - Build instructions: make glm.exe, tiny oracle verification - Runtime: SNAP=..., coli chat, coli serve all work - Status: Phase 1 complete (compiles, correct, static-linked) - Update platform requirements to include Windows 11 natively * fix: iobench Windows correctness — aligned free, 64-bit totals, full-range offsets Three bugs found running iobench.exe on Windows 11 (MinGW-w64): 1. Heap corruption (0xC0000374): free() on posix_memalign'd buffer. On Windows posix_memalign maps to _aligned_malloc, whose memory must be released with _aligned_free. Use compat_aligned_free (plain free on POSIX, _aligned_free on Windows). 2. Negative GB totals: 'long tot' is 32-bit on Windows (LLP64), so any benchmark reading more than 2 GB overflowed. Now int64_t. 3. Inflated speeds: RAND_MAX is 32767 on Windows, so rand()*4096 only generated offsets in the first 134 MB of the file — which the page cache holds entirely after one pass, reporting RAM speed instead of disk speed (measured 6 GB/s fake vs 2.1 GB/s real on a laptop NVMe). Combine two rand() calls into 30 bits so offsets span the whole file. Portable: same code path on Linux/macOS, same seeded sequence shape. --- c/iobench.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/c/iobench.c b/c/iobench.c index 39d16a0..d2b2374 100644 --- a/c/iobench.c +++ b/c/iobench.c @@ -38,10 +38,12 @@ int main(int argc,char**argv){ if(fd<0){perror("open");return 1;} off_t sz=lseek(fd,0,SEEK_END); if(sz2GB andava in overflow */ #pragma omp parallel num_threads(nth) reduction(+:tot) { void *buf; if(posix_memalign(&buf,4096,blk)){perror("memalign");exit(1);} @@ -50,7 +52,7 @@ int main(int argc,char**argv){ ssize_t r=pread(fd,buf,blk,offs[i]); if(r<0) perror("pread"); else tot+=r; } - free(buf); + compat_aligned_free(buf); /* su Windows posix_memalign=_aligned_malloc: free() corrompe l'heap */ } double dt=now()-t0; printf("%s x%d thread: %d letture x %ldMB = %.1f GB in %.2fs -> %.2f GB/s (%.1f ms/blocco effettivi)\n",