• Marko Mäkelä's avatar
    MDEV-11520 Extending an InnoDB data file unnecessarily allocates · 81695ab8
    Marko Mäkelä authored
    a large memory buffer on Windows
    
    fil_extend_space_to_desired_size(), os_file_set_size(): Use calloc()
    for memory allocation, and handle failures. Properly check the return
    status of posix_fallocate(), and pass the correct arguments to
    posix_fallocate().
    
    On Windows, instead of extending the file by at most 1 megabyte at a time,
    write a zero-filled page at the end of the file.
    According to the Microsoft blog post
    https://blogs.msdn.microsoft.com/oldnewthing/20110922-00/?p=9573
    this will physically extend the file by writing zero bytes.
    (InnoDB never uses DeviceIoControl() to set the file sparse.)
    
    I tested that the file extension works properly with a multi-file
    system tablespace, both with --innodb-use-fallocate and
    --skip-innodb-use-fallocate (the default):
    
    ./mtr \
    --mysqld=--innodb-use-fallocate \
    --mysqld=--innodb-autoextend-increment=1 \
    --mysqld=--innodb-data-file-path='ibdata1:5M;ibdata2:5M:autoextend' \
    --parallel=auto --force --retry=0 --suite=innodb &
    
    ls -lsh mysql-test/var/*/mysqld.1/data/ibdata2
    (several samples while running the test)
    81695ab8
os0file.cc 145 KB