okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
6a74320ca
main
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 ) { 9if (argc < 3 )return 1 ; 10const uint64_t gib = strtoull (argv [2 ],0 ,10 ); 11int fd = open (argv [1 ],O_WRONLY |O_CREAT |O_TRUNC ,0644 ); 12if (fd < 0 )return 2 ; 13fcntl (fd ,F_NOCACHE ,1 ); 14const size_t B = 64u <<20 ; 15uint32_t * buf = aligned_alloc (16384 ,B ); 16for (uint64_t off = 0 ;off < (gib <<30 );off += B ) { 17for (size_t i = 0 ;i < B /4 ;++ i )buf [i ]= (uint32_t ) (i * 2654435761u ); 18for (size_t p = 0 ;p < B ;p += 4096 )buf [p /4 ]= (uint32_t ) ((off + p ) >>12 ) ^0x5a5a5a5au ; 19if (write (fd ,buf ,B )!= (ssize_t )B )return 3 ; 20 } 21close (fd ); 22return 0 ; 23}