Questions tagged [fallocate]
18 questions
7
votes
1 answer
How to implement or emulate MADV_ZERO?
I would like to be able to zero out a range of a file memory-mapping without invoking any io (in order to efficiently sequentially overwrite huge files without incurring any disk read io).
Doing std::memset(ptr, 0, length) will cause pages to be…

ronag
- 49,529
- 25
- 126
- 221
6
votes
1 answer
Allocate file on disk without zeroing
I need to allocate huge file without zeroing it's content. I'm producing this steps fopen => ftruncate => fclose => mmap => (...work...) => munmap with huge file sizes (hundreds of gigabytes). App hangs on termination for a few minutes while system…

k06a
- 17,755
- 10
- 70
- 110
5
votes
4 answers
what's the difference between fallocate and ftruncate
They can all change file size according to my test.
why can they all change file to larger and to shorter?
what's the difference between fallocate and ftruncate?

Lenge
- 59
- 1
- 6
5
votes
1 answer
Why fallocate() on linux creates a non-empty file when it has not enough space?
Consider i have the following piece of code:
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include
#include
#include
#include
#include
#include
#include…

Scott Tiger
- 478
- 2
- 12
2
votes
0 answers
fallocate on MacOS for GridDB configure
I have been trying to install GridDB on MacOS to do some big data work, but hitting issues.
I have checked other questions on SO, and took the advice here to try from source code.
The configure step fails with:
checking whether…

jedison
- 908
- 6
- 15
2
votes
2 answers
Preallocate disk space for a file in Python without changing its size
I'm writing a program that downloads several files at once from several different servers (one download thread per server, of course!). I'm worried about having multiple files growing on disk simultaneously causing disk fragmentation and I'd like…

wallefan
- 354
- 1
- 11
2
votes
2 answers
Using fallocate() after shm_open() results in memory not being freed after shm_unlink()
I have an application that uses shared memory with memory mapped files. The target operating system is Ubuntu 14.04 (64-bit). The Linux kernel on this distro is at version 4.4.0. gcc is at version 4.8.4.
Until recently I was using the following…

simon
- 1,125
- 1
- 10
- 20
2
votes
1 answer
Difference between punch hole and zero range
I am looking at man page of fallocate and I do not understand the difference between these two. One seems to allocate blocks but without writing them, other seems to deallocate blocks without overwriting them. Either way, effect seems to be…

ArekBulski
- 4,520
- 4
- 39
- 61
1
vote
1 answer
Allocate file without zeroing and without creating a sparse file in linux
My goal is to instantly allocate a lot of space to a file without making a sparse file. Reading from the file should output the garbage left in free space, rather than 0s.
Both truncate and fallocate make sparse files.
Is this possible?

Daffy
- 841
- 9
- 23
0
votes
1 answer
Read from "edge" of file written by another process (which used fallocate)
I have two processes: a "writer" and a "reader"
The writer uses fallocate(2) to first create a fixed length file (filled with zeros) and the writer writes data to the file.
I want the reader process to read the file up to the "edge" (file offset…

Danny
- 2,482
- 3
- 34
- 48
0
votes
1 answer
Truncate file in linux with wget download active
i have background download with wget, i want, when the file is greater than 20mb, truncate the first 10mb of file, i have created this script:
if [ $filesize -ge $maxSize ]; then
echo "Truncate.."
kill -STOP $pidDwn
…

Salvosnake
- 83
- 10
0
votes
1 answer
How does linux fallocate FALLOC_FL_KEEP_SIZE affect a file after it is closed?
The linux call
fallocate(fd, FALLOC_FL_KEEP_SIZE, offset, len);
can be used to preallocate space for the file after the end of the file without increasing the length of the file. (right?)
Question: what happens to this disk space when fd is…

Acorn
- 768
- 6
- 15
0
votes
0 answers
undeclared identifier posix_fallocate() and fallocate() in macOS, clang 12.00
I tried using the fallocate() or the posix_fallocate() function in my CPP program, but my compiler kept telling me, that it couldn't find that function. So I created this minimal program:
#include
int main() {
int fd = open("lol",…

Jere
- 1,196
- 1
- 9
- 31
0
votes
1 answer
Wrong results when reading a txt file into an allocatable array using Fortran 90
I'm trying to solve problems related to retaining values, when I use de/allocate in the code shown below (fortran), making a copy array, but the problem persists. I've already seen links related with the topic:
Fortran array automatically growing…

user
- 309
- 1
- 9
0
votes
1 answer
How to quickly create large files in C in Linux?
Following this question:
How to quickly create large files in C?
I remember 4-5 years ago, I was able to use fallocate shell utility in Linux to create files without holes/gaps.
Disk filesystem was either ext3, ext4 or xfs.
At that time, fallocate…

Nick
- 9,962
- 4
- 42
- 80