Using fallocate and mkfs.ext4 can exceed available disk space

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite
1












Background: We have a computer cluster and on node allocation a job gets its own tmp directory of requested size. I noticed however I could send two jobs to the same machine with total requested disk space greater than what was available. I tracked the bug down to fallocate and mkfs.ext4.



On a test node/computer with 1.1T disk space available I create virtual disks to mount tmp directories to. Using fallocate and mkfs.ext4:



# fallocate -l 900G /tmp/disk-test1
# /sbin/mkfs.ext4 -F /tmp/disk-test1
# fallocate -l 900G /tmp/disk-test2
# /sbin/mkfs.ext4 -F /tmp/disk-test2


creates two files both (seemingly) of size 900G



# ll --block-size=G /tmp/
...
-rw-r--r--. 1 root root 900G Jul 4 14:03 disk-test1
-rw-r--r--. 1 root root 900G Jul 4 14:03 disk-test2
...


and looking at available disk space



# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg.01-lv_root 1.1T 8.6G 1.1T 1% /
...


The /tmp dir:



# df -h /tmp
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg.01-lv_root 1.1T 8.6G 1.1T 1% /


I don't want this to happen. The virtual disks must not be created if there is not enough space left and once mounted writing to them should be limited by their size.



What is going on here?







share|improve this question





















  • Use filefrag to get info about how it is allocated. Also mkfs might discard / TRIM the file.
    – frostschutz
    Jul 5 at 10:06











  • And discard / TRIM also happens when mounted, if using discard mount option or fstrim. Depending on your distro fstrim might be done by a system-wide cron job or service. Since you're using LVM anyway, why not create LV of desired size rather than disk images inside LV?
    – frostschutz
    Jul 5 at 10:16











  • Using filefrag disk-test1 outputs "485 extents found". Regarding LV, I will try that.
    – Kisi
    Jul 5 at 10:24










  • Take a look at "df report incorrect free space for a filesystem (ext4)" on ServerFault.
    – AlexP
    Jul 5 at 13:16














up vote
2
down vote

favorite
1












Background: We have a computer cluster and on node allocation a job gets its own tmp directory of requested size. I noticed however I could send two jobs to the same machine with total requested disk space greater than what was available. I tracked the bug down to fallocate and mkfs.ext4.



On a test node/computer with 1.1T disk space available I create virtual disks to mount tmp directories to. Using fallocate and mkfs.ext4:



# fallocate -l 900G /tmp/disk-test1
# /sbin/mkfs.ext4 -F /tmp/disk-test1
# fallocate -l 900G /tmp/disk-test2
# /sbin/mkfs.ext4 -F /tmp/disk-test2


creates two files both (seemingly) of size 900G



# ll --block-size=G /tmp/
...
-rw-r--r--. 1 root root 900G Jul 4 14:03 disk-test1
-rw-r--r--. 1 root root 900G Jul 4 14:03 disk-test2
...


and looking at available disk space



# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg.01-lv_root 1.1T 8.6G 1.1T 1% /
...


The /tmp dir:



# df -h /tmp
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg.01-lv_root 1.1T 8.6G 1.1T 1% /


I don't want this to happen. The virtual disks must not be created if there is not enough space left and once mounted writing to them should be limited by their size.



What is going on here?







share|improve this question





















  • Use filefrag to get info about how it is allocated. Also mkfs might discard / TRIM the file.
    – frostschutz
    Jul 5 at 10:06











  • And discard / TRIM also happens when mounted, if using discard mount option or fstrim. Depending on your distro fstrim might be done by a system-wide cron job or service. Since you're using LVM anyway, why not create LV of desired size rather than disk images inside LV?
    – frostschutz
    Jul 5 at 10:16











  • Using filefrag disk-test1 outputs "485 extents found". Regarding LV, I will try that.
    – Kisi
    Jul 5 at 10:24










  • Take a look at "df report incorrect free space for a filesystem (ext4)" on ServerFault.
    – AlexP
    Jul 5 at 13:16












up vote
2
down vote

favorite
1









up vote
2
down vote

favorite
1






1





Background: We have a computer cluster and on node allocation a job gets its own tmp directory of requested size. I noticed however I could send two jobs to the same machine with total requested disk space greater than what was available. I tracked the bug down to fallocate and mkfs.ext4.



On a test node/computer with 1.1T disk space available I create virtual disks to mount tmp directories to. Using fallocate and mkfs.ext4:



# fallocate -l 900G /tmp/disk-test1
# /sbin/mkfs.ext4 -F /tmp/disk-test1
# fallocate -l 900G /tmp/disk-test2
# /sbin/mkfs.ext4 -F /tmp/disk-test2


creates two files both (seemingly) of size 900G



# ll --block-size=G /tmp/
...
-rw-r--r--. 1 root root 900G Jul 4 14:03 disk-test1
-rw-r--r--. 1 root root 900G Jul 4 14:03 disk-test2
...


and looking at available disk space



# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg.01-lv_root 1.1T 8.6G 1.1T 1% /
...


The /tmp dir:



# df -h /tmp
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg.01-lv_root 1.1T 8.6G 1.1T 1% /


I don't want this to happen. The virtual disks must not be created if there is not enough space left and once mounted writing to them should be limited by their size.



What is going on here?







share|improve this question













Background: We have a computer cluster and on node allocation a job gets its own tmp directory of requested size. I noticed however I could send two jobs to the same machine with total requested disk space greater than what was available. I tracked the bug down to fallocate and mkfs.ext4.



On a test node/computer with 1.1T disk space available I create virtual disks to mount tmp directories to. Using fallocate and mkfs.ext4:



# fallocate -l 900G /tmp/disk-test1
# /sbin/mkfs.ext4 -F /tmp/disk-test1
# fallocate -l 900G /tmp/disk-test2
# /sbin/mkfs.ext4 -F /tmp/disk-test2


creates two files both (seemingly) of size 900G



# ll --block-size=G /tmp/
...
-rw-r--r--. 1 root root 900G Jul 4 14:03 disk-test1
-rw-r--r--. 1 root root 900G Jul 4 14:03 disk-test2
...


and looking at available disk space



# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg.01-lv_root 1.1T 8.6G 1.1T 1% /
...


The /tmp dir:



# df -h /tmp
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg.01-lv_root 1.1T 8.6G 1.1T 1% /


I don't want this to happen. The virtual disks must not be created if there is not enough space left and once mounted writing to them should be limited by their size.



What is going on here?









share|improve this question












share|improve this question




share|improve this question








edited Jul 5 at 10:10
























asked Jul 5 at 9:49









Kisi

133




133











  • Use filefrag to get info about how it is allocated. Also mkfs might discard / TRIM the file.
    – frostschutz
    Jul 5 at 10:06











  • And discard / TRIM also happens when mounted, if using discard mount option or fstrim. Depending on your distro fstrim might be done by a system-wide cron job or service. Since you're using LVM anyway, why not create LV of desired size rather than disk images inside LV?
    – frostschutz
    Jul 5 at 10:16











  • Using filefrag disk-test1 outputs "485 extents found". Regarding LV, I will try that.
    – Kisi
    Jul 5 at 10:24










  • Take a look at "df report incorrect free space for a filesystem (ext4)" on ServerFault.
    – AlexP
    Jul 5 at 13:16
















  • Use filefrag to get info about how it is allocated. Also mkfs might discard / TRIM the file.
    – frostschutz
    Jul 5 at 10:06











  • And discard / TRIM also happens when mounted, if using discard mount option or fstrim. Depending on your distro fstrim might be done by a system-wide cron job or service. Since you're using LVM anyway, why not create LV of desired size rather than disk images inside LV?
    – frostschutz
    Jul 5 at 10:16











  • Using filefrag disk-test1 outputs "485 extents found". Regarding LV, I will try that.
    – Kisi
    Jul 5 at 10:24










  • Take a look at "df report incorrect free space for a filesystem (ext4)" on ServerFault.
    – AlexP
    Jul 5 at 13:16















Use filefrag to get info about how it is allocated. Also mkfs might discard / TRIM the file.
– frostschutz
Jul 5 at 10:06





Use filefrag to get info about how it is allocated. Also mkfs might discard / TRIM the file.
– frostschutz
Jul 5 at 10:06













And discard / TRIM also happens when mounted, if using discard mount option or fstrim. Depending on your distro fstrim might be done by a system-wide cron job or service. Since you're using LVM anyway, why not create LV of desired size rather than disk images inside LV?
– frostschutz
Jul 5 at 10:16





And discard / TRIM also happens when mounted, if using discard mount option or fstrim. Depending on your distro fstrim might be done by a system-wide cron job or service. Since you're using LVM anyway, why not create LV of desired size rather than disk images inside LV?
– frostschutz
Jul 5 at 10:16













Using filefrag disk-test1 outputs "485 extents found". Regarding LV, I will try that.
– Kisi
Jul 5 at 10:24




Using filefrag disk-test1 outputs "485 extents found". Regarding LV, I will try that.
– Kisi
Jul 5 at 10:24












Take a look at "df report incorrect free space for a filesystem (ext4)" on ServerFault.
– AlexP
Jul 5 at 13:16




Take a look at "df report incorrect free space for a filesystem (ext4)" on ServerFault.
– AlexP
Jul 5 at 13:16










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










Yeah, I can reproduce that:



# df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 14G 14G 51% /
# fallocate -l 8G test1.disk
# df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 22G 5.8G 80% /
# mkfs -text4 test1.disk
mke2fs 1.43.4 (31-Jan-2017)
Discarding device blocks: done
Creating filesystem with 2097152 4k blocks and 524288 inodes
...
# df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 14G 14G 51% /


Disk usage goes up when the file is fallocated, but back down after mkfs. Note the "Discarding device blocks: done" in the output of mke2fs. (frostschutz mentioned this in the comments.)



The man page says of -E discard:




discard

Attempt to discard blocks at mkfs time (discarding
blocks initially is useful on solid state devices
and sparse / thin-provisioned storage). ...
This is set as default.




There's nodiscard to do the opposite, so let's try that:



# df -h .; fallocate -l 8G test2.disk; mkfs -text4 -Enodiscard test2.disk; df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 14G 14G 51% /
mke2fs 1.43.4 (31-Jan-2017)
Creating filesystem with 2097152 4k blocks and 524288 inodes
...
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 22G 5.9G 79% /


Now another fallocate -l 8G fails.






share|improve this answer























  • This works, thank you! I didn't notice this in the man page.
    – Kisi
    Jul 5 at 14:53










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f453571%2fusing-fallocate-and-mkfs-ext4-can-exceed-available-disk-space%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










Yeah, I can reproduce that:



# df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 14G 14G 51% /
# fallocate -l 8G test1.disk
# df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 22G 5.8G 80% /
# mkfs -text4 test1.disk
mke2fs 1.43.4 (31-Jan-2017)
Discarding device blocks: done
Creating filesystem with 2097152 4k blocks and 524288 inodes
...
# df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 14G 14G 51% /


Disk usage goes up when the file is fallocated, but back down after mkfs. Note the "Discarding device blocks: done" in the output of mke2fs. (frostschutz mentioned this in the comments.)



The man page says of -E discard:




discard

Attempt to discard blocks at mkfs time (discarding
blocks initially is useful on solid state devices
and sparse / thin-provisioned storage). ...
This is set as default.




There's nodiscard to do the opposite, so let's try that:



# df -h .; fallocate -l 8G test2.disk; mkfs -text4 -Enodiscard test2.disk; df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 14G 14G 51% /
mke2fs 1.43.4 (31-Jan-2017)
Creating filesystem with 2097152 4k blocks and 524288 inodes
...
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 22G 5.9G 79% /


Now another fallocate -l 8G fails.






share|improve this answer























  • This works, thank you! I didn't notice this in the man page.
    – Kisi
    Jul 5 at 14:53














up vote
2
down vote



accepted










Yeah, I can reproduce that:



# df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 14G 14G 51% /
# fallocate -l 8G test1.disk
# df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 22G 5.8G 80% /
# mkfs -text4 test1.disk
mke2fs 1.43.4 (31-Jan-2017)
Discarding device blocks: done
Creating filesystem with 2097152 4k blocks and 524288 inodes
...
# df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 14G 14G 51% /


Disk usage goes up when the file is fallocated, but back down after mkfs. Note the "Discarding device blocks: done" in the output of mke2fs. (frostschutz mentioned this in the comments.)



The man page says of -E discard:




discard

Attempt to discard blocks at mkfs time (discarding
blocks initially is useful on solid state devices
and sparse / thin-provisioned storage). ...
This is set as default.




There's nodiscard to do the opposite, so let's try that:



# df -h .; fallocate -l 8G test2.disk; mkfs -text4 -Enodiscard test2.disk; df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 14G 14G 51% /
mke2fs 1.43.4 (31-Jan-2017)
Creating filesystem with 2097152 4k blocks and 524288 inodes
...
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 22G 5.9G 79% /


Now another fallocate -l 8G fails.






share|improve this answer























  • This works, thank you! I didn't notice this in the man page.
    – Kisi
    Jul 5 at 14:53












up vote
2
down vote



accepted







up vote
2
down vote



accepted






Yeah, I can reproduce that:



# df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 14G 14G 51% /
# fallocate -l 8G test1.disk
# df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 22G 5.8G 80% /
# mkfs -text4 test1.disk
mke2fs 1.43.4 (31-Jan-2017)
Discarding device blocks: done
Creating filesystem with 2097152 4k blocks and 524288 inodes
...
# df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 14G 14G 51% /


Disk usage goes up when the file is fallocated, but back down after mkfs. Note the "Discarding device blocks: done" in the output of mke2fs. (frostschutz mentioned this in the comments.)



The man page says of -E discard:




discard

Attempt to discard blocks at mkfs time (discarding
blocks initially is useful on solid state devices
and sparse / thin-provisioned storage). ...
This is set as default.




There's nodiscard to do the opposite, so let's try that:



# df -h .; fallocate -l 8G test2.disk; mkfs -text4 -Enodiscard test2.disk; df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 14G 14G 51% /
mke2fs 1.43.4 (31-Jan-2017)
Creating filesystem with 2097152 4k blocks and 524288 inodes
...
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 22G 5.9G 79% /


Now another fallocate -l 8G fails.






share|improve this answer















Yeah, I can reproduce that:



# df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 14G 14G 51% /
# fallocate -l 8G test1.disk
# df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 22G 5.8G 80% /
# mkfs -text4 test1.disk
mke2fs 1.43.4 (31-Jan-2017)
Discarding device blocks: done
Creating filesystem with 2097152 4k blocks and 524288 inodes
...
# df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 14G 14G 51% /


Disk usage goes up when the file is fallocated, but back down after mkfs. Note the "Discarding device blocks: done" in the output of mke2fs. (frostschutz mentioned this in the comments.)



The man page says of -E discard:




discard

Attempt to discard blocks at mkfs time (discarding
blocks initially is useful on solid state devices
and sparse / thin-provisioned storage). ...
This is set as default.




There's nodiscard to do the opposite, so let's try that:



# df -h .; fallocate -l 8G test2.disk; mkfs -text4 -Enodiscard test2.disk; df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 14G 14G 51% /
mke2fs 1.43.4 (31-Jan-2017)
Creating filesystem with 2097152 4k blocks and 524288 inodes
...
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 22G 5.9G 79% /


Now another fallocate -l 8G fails.







share|improve this answer















share|improve this answer



share|improve this answer








edited Jul 5 at 15:29


























answered Jul 5 at 14:38









ilkkachu

47.3k668130




47.3k668130











  • This works, thank you! I didn't notice this in the man page.
    – Kisi
    Jul 5 at 14:53
















  • This works, thank you! I didn't notice this in the man page.
    – Kisi
    Jul 5 at 14:53















This works, thank you! I didn't notice this in the man page.
– Kisi
Jul 5 at 14:53




This works, thank you! I didn't notice this in the man page.
– Kisi
Jul 5 at 14:53












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f453571%2fusing-fallocate-and-mkfs-ext4-can-exceed-available-disk-space%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)