okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-mac-rel (Mac Metal support) into f-144-rel6a74320ca

main
939 B23 linesraw
1// mkfile.c - write a dense test file of N GiB with F_NOCACHE (so it is not left in the page cache):
2// the first uint32 of every 4 KiB is (offset >> 12) ^ 0x5a5a5a5a, the rest is a cheap pattern.
3#include <fcntl.h>
4#include <stdint.h>
5#include <stdio.h>
6#include <stdlib.h>
7#include <unistd.h>
8int main(int argc, char** argv) {
9    if (argc < 3) return 1;
10    const uint64_t gib = strtoull(argv[2], 0, 10);
11    int fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
12    if (fd < 0) return 2;
13    fcntl(fd, F_NOCACHE, 1);
14    const size_t B = 64u << 20;
15    uint32_t* buf = aligned_alloc(16384, B);
16    for (uint64_t off = 0; off < (gib << 30); off += B) {
17        for (size_t i = 0; i < B / 4; ++i) buf[i] = (uint32_t) (i * 2654435761u);
18        for (size_t p = 0; p < B; p += 4096) buf[p / 4] = (uint32_t) ((off + p) >> 12) ^ 0x5a5a5a5au;
19        if (write(fd, buf, B) != (ssize_t) B) return 3;
20    }
21    close(fd);
22    return 0;
23}