Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug-fix macos: give free bytes to F_PREALLOCATE #17887

Merged
merged 1 commit into from
Jan 22, 2020

Conversation

kallewoof
Copy link
Contributor

@kallewoof kallewoof commented Jan 7, 2020

The macos manpage for fcntl (for F_PEOFPOSMODE) states:

Allocate from the physical end of file. In this case, fst_length indicates the number of newly allocated bytes desired.

This would result in the rev files being essentially pre-allocating 2x their necessary size (this is the case for block files as well, but these are flushed down to their right sizes every time) as they would pre-allocate pos + length free bytes, rather than allocating length bytes after pos, as expected.

Fixes #17827.

@fanquake fanquake added the macOS label Jan 7, 2020
@sipa
Copy link
Member

sipa commented Jan 7, 2020

So this code has been wrong for 7 years? Why do we only notice the effect now?

@fanquake
Copy link
Member

fanquake commented Jan 7, 2020

So this code has been wrong for 7 years? Why do we only notice the effect now?

It’s likely this issue only started occurring with the introduction of APFS, which is quite recent.

@kallewoof
Copy link
Contributor Author

kallewoof commented Jan 7, 2020

@sipa I suspect the OS eventually reclaims pre-allocated space, but it seems block files are not suffering from this kind of issue, so I'm honestly not sure. The docs clearly indicate we were using it wrong, though. (Edit: the issue is a bit more convoluted; see #17887 (comment))

Old edit:

It’s likely this issue only started occurring with the introduction of APFS, which is quite recent.

That is probably more likely.

@kallewoof
Copy link
Contributor Author

kallewoof commented Jan 7, 2020

On my machine (APFS encrypted volume), I was seeing rev00002.dat hitting 20 MB around block 135k. After this patch (running up to block 191106, then shutting down) I see

$ du -ch *.dat
128M	blk00000.dat
128M	blk00001.dat
128M	blk00002.dat
128M	blk00003.dat
128M	blk00004.dat
128M	blk00005.dat
128M	blk00006.dat
128M	blk00007.dat
128M	blk00008.dat
128M	blk00009.dat
128M	blk00010.dat
128M	blk00011.dat
128M	blk00012.dat
128M	blk00013.dat
128M	blk00014.dat
128M	blk00015.dat
128M	blk00016.dat
 48M	blk00017.dat
 20M	rev00000.dat
 17M	rev00001.dat
 17M	rev00002.dat
 17M	rev00003.dat
 17M	rev00004.dat
 18M	rev00005.dat
 18M	rev00006.dat
 19M	rev00007.dat
 19M	rev00008.dat
 18M	rev00009.dat
 18M	rev00010.dat
 19M	rev00011.dat
 19M	rev00012.dat
 19M	rev00013.dat
 19M	rev00014.dat
 18M	rev00015.dat
 19M	rev00016.dat
5.1M	rev00017.dat
2.5G	total

Master (~same block, after shutdown):

$ du -ch *.dat
128M	blk00000.dat
128M	blk00001.dat
128M	blk00002.dat
128M	blk00003.dat
128M	blk00004.dat
128M	blk00005.dat
128M	blk00006.dat
128M	blk00007.dat
128M	blk00008.dat
128M	blk00009.dat
128M	blk00010.dat
128M	blk00011.dat
128M	blk00012.dat
128M	blk00013.dat
128M	blk00014.dat
128M	blk00015.dat
128M	blk00016.dat
144M	blk00017.dat
 19M	rev00000.dat
 17M	rev00001.dat
 16M	rev00002.dat
 17M	rev00003.dat
 17M	rev00004.dat
 18M	rev00005.dat
 18M	rev00006.dat
 36M	rev00007.dat
 51M	rev00008.dat
 18M	rev00009.dat
 18M	rev00010.dat
 18M	rev00011.dat
162M	rev00012.dat
 67M	rev00013.dat
126M	rev00014.dat
 51M	rev00015.dat
 67M	rev00016.dat
 21M	rev00017.dat
3.0G	total

Both runs were after rm -rf $BITCOINDIR.

grep 'Pre-allocating' results for master run, minus a small part of the start: https://pastebin.com/dXLLcRQa

Looking closely at the run on master, the files are blowing up 2x in size until they are no longer used, at which point they are sometimes truncated to their actual size. The blow-up applies to blk files as well, but these are always truncated down after use (see blk00017.dat, which is too large because it isn't finished yet; this was after shutting Bitcoin Core down).

Running on this PR, the 2x blowup is not occurring for either files.

Running macos 10.14.6 (Mojave). User is running Catalina, so perhaps I would see the problem more often if I upgraded.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 7, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

No conflicts as of last run.

@kallewoof
Copy link
Contributor Author

Enlightening read: https://www.mail-archive.com/[email protected]/msg00226.html

@IPGlider
Copy link
Contributor

IPGlider commented Jan 7, 2020

Tested on MacOS 10.15.2 on an APFS volume and the problem disappears. Also tested on a mounted HFS+ disk volume and the problem disappears.

@fanquake
Copy link
Member

fanquake commented Jan 8, 2020

Concept ACK

@eriknylund
Copy link
Contributor

I ran this on machine 2 in the issue report and can confirm that there is no blowup.

  • MacBook Pro (15-inch, 2018)
  • 2,6 GHz 6-Core Intel Core i7
  • 32 GB 2400 MHz DDR4
  • macOS Catalina 10.15.2 (upgraded from Mojave)

Tested on an APFS unencrypted disk image with 3 GB in size and let it run until the image was full:

$ ./bitcoind -datadir=/Volumes/APFS
2020-01-09T19:43:17Z UpdateTip: 
new best=000000000000059cfb1620756c7a88b679dfcbedc1d3c255dbc0f09481f8021b
height=191055 version=0x00000001 log2_work=68.451374 tx=5349799 
date='2012-07-27T17:15:53Z' progress=0.010844 cache=292.8MiB(2160691txo)
2020-01-09T19:43:19Z *** Disk space is too low!

$ cd /Volumes/APFS/blocks/

$ du -ch *.dat
128M	blk00000.dat
128M	blk00001.dat
128M	blk00002.dat
128M	blk00003.dat
128M	blk00004.dat
128M	blk00005.dat
128M	blk00006.dat
128M	blk00007.dat
128M	blk00008.dat
128M	blk00009.dat
128M	blk00010.dat
128M	blk00011.dat
128M	blk00012.dat
128M	blk00013.dat
128M	blk00014.dat
128M	blk00015.dat
128M	blk00016.dat
 48M	blk00017.dat
 20M	rev00000.dat
 17M	rev00001.dat
 16M	rev00002.dat
 17M	rev00003.dat
 18M	rev00004.dat
 18M	rev00005.dat
 19M	rev00006.dat
 18M	rev00007.dat
 19M	rev00008.dat
 18M	rev00009.dat
 19M	rev00010.dat
 18M	rev00011.dat
 18M	rev00012.dat
 18M	rev00013.dat
 19M	rev00014.dat
 18M	rev00015.dat
 19M	rev00016.dat
5.0M	rev00017.dat
2.5G	total

Tested on a Mac OS Extended (HFS+) unencrypted disk image with 3 GB in size:

$ ./bitcoind -datadir=/Volumes/HFS+/
2020-01-09T20:13:51Z UpdateTip: 
new best=00000000000004e055fbb153a6371891f7dc52adbe525b3a5cf3b9413fde7551 
height=189775 version=0x00000001 log2_work=68.414219 tx=5084658 
date='2012-07-19T07:39:48Z' progress=0.010306 cache=285.6MiB(2101977txo)
2020-01-09T20:13:51Z Error: Disk space is too low!

$ cd /Volumes/HFS+/blocks/

$ du -ch *.dat
128M	blk00000.dat
128M	blk00001.dat
128M	blk00002.dat
128M	blk00003.dat
128M	blk00004.dat
128M	blk00005.dat
128M	blk00006.dat
128M	blk00007.dat
128M	blk00008.dat
128M	blk00009.dat
128M	blk00010.dat
128M	blk00011.dat
128M	blk00012.dat
128M	blk00013.dat
128M	blk00014.dat
128M	blk00015.dat
 64M	blk00016.dat
 19M	rev00000.dat
 17M	rev00001.dat
 16M	rev00002.dat
 16M	rev00003.dat
 17M	rev00004.dat
 17M	rev00005.dat
 18M	rev00006.dat
 18M	rev00007.dat
 18M	rev00008.dat
 18M	rev00009.dat
 18M	rev00010.dat
 18M	rev00011.dat
 18M	rev00012.dat
 18M	rev00013.dat
 18M	rev00014.dat
 18M	rev00015.dat
8.0M	rev00016.dat
2.3G	total

@eriknylund
Copy link
Contributor

I also built a Bitcoin-Qt.dmg and started a fresh download on machine 1 in the issue report, to verify that I can successfully complete the initial block download on the Mac mini with 480 GB of free disk space at the start. ETA 3 days.

@fanquake
Copy link
Member

I've just finished a from scratch sync using this PR + 17892, on an macOS (APFS) machine. Data directory is the expected size. No longer seeing very large rev*.dat files, most are between 16 and 21mb.

@eriknylund
Copy link
Contributor

eriknylund commented Jan 12, 2020

I also built a Bitcoin-Qt.dmg and started a fresh download on machine 1 in the issue report, to verify that I can successfully complete the initial block download on the Mac mini with 480 GB of free disk space at the start. ETA 3 days.

I've just finished a from scratch sync using this PR + 17892, on an macOS (APFS) machine. Data directory is the expected size. No longer seeing very large rev*.dat files, most are between 16 and 21mb.

The IBD is now complete and the estimate is spot on. 280 GB of disk space is used. The rev*.dat file sizes are in the range 12-27 MB.

Bitcoin % pwd
/Users/erik/Library/Application Support/Bitcoin

Bitcoin % du -h .
 92M	./blocks/index
276G	./blocks
3.7G	./chainstate
2.0M	./wallets/database
4.0M	./wallets
280G	.

Bitcoin % tail debug.log
2020-01-12T17:17:44Z UpdateTip: 
new best=000000000000000000141d63c0a927235c7e21b39f8c632f9b7e70a9f3fb1659 
height=612543 version=0x3fffe000 log2_work=91.544872 tx=492581053 
date='2020-01-12T17:17:13Z' progress=1.000000 cache=259.8MiB(1712729txo) 
warning='71 of last 100 blocks have unexpected version'

Bitcoin % du -ch blocks/rev*.dat | sort -n
 12M	blocks/rev00311.dat
 12M	blocks/rev01927.dat
 14M	blocks/rev00314.dat
...
 23M	blocks/rev00337.dat
 24M	blocks/rev01037.dat
 27M	blocks/rev01036.dat
 35G	total

@eriknylund
Copy link
Contributor

Looking a bit more into the rev files I see what is most likely the truncation issue @kallewoof discovered in #17890

Bitcoin % du -h blocks/rev00337.dat blocks/rev01037.dat blocks/rev01036.dat
 23M	blocks/rev00337.dat
 24M	blocks/rev01037.dat
 27M	blocks/rev01036.dat
Bitcoin % ls -lh blocks/rev00337.dat blocks/rev01037.dat blocks/rev01036.dat
-rw-------  1 erik  staff    21M Jan 10 10:46 blocks/rev00337.dat
-rw-------  1 erik  staff    23M Jan 11 12:56 blocks/rev01036.dat
-rw-------  1 erik  staff    21M Jan 11 12:58 blocks/rev01037.dat

@kallewoof
Copy link
Contributor Author

Thanks! Yeah, we will have to do a one time run-through of all the rev files to clean up the excess use, or we will end up with wasted space for everyone.. I'm honestly not sure why this isn't affecting other systems though. The finalize issue is not mac specific (only the over-preallocating issue is).

@kallewoof
Copy link
Contributor Author

kallewoof commented Jan 13, 2020

This made me realize that this actually is a bug in the operating system. I couldn't explain why this didn't happen to earlier versions, but I believe I can now.

The bug is that ftruncate does not return pre-allocated disk space.

Before, we would over-preallocate and then immediately truncate back down to the expected size. This worked in pre-APFS land, but APFS has a bug which leaves the pre-allocated space as occupied by the file, even though we call ftruncate.

I will make a minimal test case displaying this behavior and submit a report to Apple.

Edit: https://openradar.appspot.com/radar?id=4930713610616832

Edit: I updated the bug report above with information on F_PUNCHHOLE, which appears to be the way to un-preallocate (return) space; this does nothing, however.

fst.fst_bytesalloc = 0;
if (fcntl(fileno(file), F_PREALLOCATE, &fst) == -1) {
fst.fst_flags = F_ALLOCATEALL;
fcntl(fileno(file), F_PREALLOCATE, &fst);
}
ftruncate(fileno(file), fst.fst_length);
ftruncate(fileno(file), (off_t)offset + length);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could static_cast

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Empact
Copy link
Contributor

Empact commented Jan 13, 2020

Code review ACK 5de93dc also checked man fcntl locally

@kallewoof kallewoof force-pushed the macos-f_preallocate_fix branch from 5de93dc to 2db88bd Compare January 14, 2020 02:02
@fanquake
Copy link
Member

@arvidn Any chance you could comment here, given you patched an APFS related issue in libtorrent some time ago?

@arvidn
Copy link

arvidn commented Jan 14, 2020

This patch changes the behavior of AllocateFileRange(), which is documented to:

this function tries to make a particular range of a file allocated (corresponding to disk space) it is advisory, and the range specified in the arguments will never contain live data

It doesn't seem like this patch correctly implements the documented behavior. It might fix an issue in how AllocateFileRange() is used, but there still seems to be a mismatch in how AllocateFileRange() behaves on other operating systems and what it's documented to do.

If I understand the mailing list post Dominic Giampaolo correctly, in order to implement the documented behavior of AllocateFileRange() you would also need to stat() the file and set:

fst.fst_length = offset + length - st_size;

and if offset + length < st_size, skip the fcntl() call entirely.

@kallewoof
Copy link
Contributor Author

kallewoof commented Jan 14, 2020

Edit: nevermind, I see what you're saying, but I believe offset is already (supposed to be) equal to st_size, so I don't think it matters.

@arvidn
Copy link

arvidn commented Jan 14, 2020

but I believe offset is already (supposed to be) equal to st_size

Right, this patch makes that assumption. The windows implementation does not make this assumption, nor does the documentation state it will make this assumption.

@kallewoof
Copy link
Contributor Author

I see what you mean. I don't think it matters in this case either way, but it's worth pointing out.

@kallewoof
Copy link
Contributor Author

Either way, that's unrelated to the question which is how to properly pre-allocate (and more importantly, how to return unused space at the end) on APFS.

The macos manpage for fcntl (for F_PEOFPOSMODE) states:

> Allocate from the physical end of file.  In this case, fst_length indicates the number of newly allocated bytes desired.
@kallewoof kallewoof force-pushed the macos-f_preallocate_fix branch from 2db88bd to 75163f4 Compare January 14, 2020 23:57
@bg002h
Copy link

bg002h commented Jan 21, 2020

My sizes using this pull request, running Catalina and an unencrypted APFS disk:

https://pastebin.com/W53SX4xg

Running master:

https://pastebin.com/0Sj2XXny

All file sizes for both this PR and master don't seem any different while running or after shutdown.

@Sjors
Copy link
Member

Sjors commented Jan 21, 2020

@bg002h ls -alFh won't see the issue. Try du -ch instead.

@bg002h
Copy link

bg002h commented Jan 21, 2020

@Sjors Thx for the tip!

I reformatted my NVME raid to APFS, encrypted, case sensitive since the above.

For master, I see:
https://pastebin.com/GeqsZhmh (rev 50 was 45M)

running this PR (pastern is down):
bcg@Brians-MacBook-Pro blocks % du -ch *
128M blk00000.dat
.
.
.
128M blk00052.dat
16M blk00053.dat
8.0K index
19M rev00000.dat
16M rev00001.dat
16M rev00002.dat
16M rev00003.dat
16M rev00004.dat
17M rev00005.dat
17M rev00006.dat
17M rev00007.dat
18M rev00008.dat
18M rev00009.dat
17M rev00010.dat
17M rev00011.dat
18M rev00012.dat
18M rev00013.dat
17M rev00014.dat
17M rev00015.dat
18M rev00016.dat
17M rev00017.dat
17M rev00018.dat
17M rev00019.dat
17M rev00020.dat
17M rev00021.dat
17M rev00022.dat
17M rev00023.dat
17M rev00024.dat
17M rev00025.dat
17M rev00026.dat
17M rev00027.dat
17M rev00028.dat
17M rev00029.dat
17M rev00030.dat
17M rev00031.dat
17M rev00032.dat
17M rev00033.dat
17M rev00034.dat
17M rev00035.dat
17M rev00036.dat
17M rev00037.dat
17M rev00038.dat
17M rev00039.dat
17M rev00040.dat
17M rev00041.dat
17M rev00042.dat
17M rev00043.dat
17M rev00044.dat
17M rev00045.dat
17M rev00046.dat
17M rev00047.dat
17M rev00048.dat
17M rev00049.dat
17M rev00050.dat
17M rev00051.dat
17M rev00052.dat
2.0M rev00053.dat in progress
7.5G total

@bg002h
Copy link

bg002h commented Jan 21, 2020

using master, and checking du repeatedly during blk1, rev1 gets pretty big before being trimmed back:

cg@Brians-MacBook-Pro blocks % du -ch *
576M blk00000.dat
8.0K index
190M rev00000.dat
766M total

The behavior is not observed using this PR:

bcg@Brians-MacBook-Pro blocks % du -ch *
128M blk00000.dat
8.0K index
17M rev00000.dat
145M total
bcg@Brians-MacBook-Pro blocks % du -ch *
128M blk00000.dat
8.0K index
18M rev00000.dat
146M total
bcg@Brians-MacBook-Pro blocks % du -ch *
128M blk00000.dat
8.0K index
19M rev00000.dat
147M total
bcg@Brians-MacBook-Pro blocks % du -ch *
128M blk00000.dat
8.0K index
19M rev00000.dat
147M total
bcg@Brians-MacBook-Pro blocks % du -ch *
128M blk00000.dat
8.0K index
19M rev00000.dat
147M total
bcg@Brians-MacBook-Pro blocks % du -ch *
128M blk00000.dat
16M blk00001.dat
8.0K index
19M rev00000.dat
1.0M rev00001.dat
164M total
bcg@Brians-MacBook-Pro blocks % du -ch *
128M blk00000.dat
16M blk00001.dat
8.0K index
19M rev00000.dat
1.0M rev00001.dat
164M total
bcg@Brians-MacBook-Pro blocks %
bcg@Brians-MacBook-Pro blocks % du -ch *
128M blk00000.dat
96M blk00001.dat
8.0K index
19M rev00000.dat
12M rev00001.dat
255M total

@fjahr
Copy link
Contributor

fjahr commented Jan 21, 2020

I ran with --enable-debug though.

Strange, I double checked and still not seeing any large rev files with --enable-debug...

@kallewoof
Copy link
Contributor Author

--enable-debug should not matter in this case.

@maaku
Copy link
Contributor

maaku commented Jan 22, 2020

FWIW I'm able to reproduce this on gitian-built clients as far back as 0.12.

@laanwj
Copy link
Member

laanwj commented Jan 22, 2020

code review ACK 75163f4
I have checked the documentation that the new use of F_PREALLOCATE is correct (and the old one is wrong).

Thanks everyone for testing!

laanwj added a commit that referenced this pull request Jan 22, 2020
75163f4 bug-fix macos: give free bytes to F_PREALLOCATE (Karl-Johan Alm)

Pull request description:

  The macos manpage for `fcntl` (for `F_PEOFPOSMODE`) states:

  > Allocate from the physical end of file.  In this case, fst_length indicates the number of newly allocated bytes desired.

  This would result in the rev files being essentially pre-allocating 2x their necessary size (this is the case for block files as well, but these are flushed down to their right sizes every time) as they would pre-allocate `pos + length` **free** bytes, rather than allocating `length` bytes after `pos`, as expected.

  Fixes #17827.

ACKs for top commit:
  eriknylund:
    ACK 75163f4 built locally. All tests passing. Manual test as per my previous comment above on an older commit, using an APFS unencrypted disk image with 3 GB.
  laanwj:
    code review ACK 75163f4

Tree-SHA512: 105c8d56c20acad8febdf0583f1e5721b63376ace325a7a62c2e4b15a442c7131404ed604c32c0cda716791d7ca5aa9f5b6a774ff86e39838bc7e87ca3c42760
@laanwj laanwj merged commit 75163f4 into bitcoin:master Jan 22, 2020
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Jan 23, 2020
The macos manpage for fcntl (for F_PEOFPOSMODE) states:

> Allocate from the physical end of file.  In this case, fst_length indicates the number of newly allocated bytes desired.

Github-Pull: bitcoin#17887
Rebased-From: 75163f4
@fanquake
Copy link
Member

Being backported to 0.19 in #17988.

laanwj added a commit that referenced this pull request Jan 23, 2020
daf2fff test: add missing #include to fix compiler errors (Karl-Johan Alm)
c8ad23c bug-fix macos: give free bytes to F_PREALLOCATE (Karl-Johan Alm)

Pull request description:

  We're about ready to do a [0.19.1 release](https://github.com/bitcoin/bitcoin/milestone/44); so I've opened this to collect the last remaining backports.

  If there's something that's been missed / or isn't tagged ["Needs backport (0.19)"](https://github.com/bitcoin/bitcoin/issues?q=is%3Aopen+label%3A%22Needs+backport+%280.19%29%22) that you think should be, please comment.

  Currently backports:
  * #17887 - bug-fix macos: give free bytes to F_PREALLOCATE
  * #17980 - test: add missing #include to fix compiler errors

ACKs for top commit:
  laanwj:
    ACK daf2fff

Tree-SHA512: 8438f992d0c39315a4da4c3f8ab5c92acefada4b0ba5a5cec3775dea2541492d386bf4e7c9e76e1494a6d4cf16a9205287d27ffd23d9c3056f213d733605eeee
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 24, 2020
75163f4 bug-fix macos: give free bytes to F_PREALLOCATE (Karl-Johan Alm)

Pull request description:

  The macos manpage for `fcntl` (for `F_PEOFPOSMODE`) states:

  > Allocate from the physical end of file.  In this case, fst_length indicates the number of newly allocated bytes desired.

  This would result in the rev files being essentially pre-allocating 2x their necessary size (this is the case for block files as well, but these are flushed down to their right sizes every time) as they would pre-allocate `pos + length` **free** bytes, rather than allocating `length` bytes after `pos`, as expected.

  Fixes bitcoin#17827.

ACKs for top commit:
  eriknylund:
    ACK 75163f4 built locally. All tests passing. Manual test as per my previous comment above on an older commit, using an APFS unencrypted disk image with 3 GB.
  laanwj:
    code review ACK 75163f4

Tree-SHA512: 105c8d56c20acad8febdf0583f1e5721b63376ace325a7a62c2e4b15a442c7131404ed604c32c0cda716791d7ca5aa9f5b6a774ff86e39838bc7e87ca3c42760
MarkLTZ added a commit to litecoinz-core/litecoinz that referenced this pull request Feb 13, 2020
- [0.19] wallet: Reset reused transactions cache bitcoin#18083
- 0.19: Backports bitcoin#17792
- psbt: handle unspendable psbts bitcoin#17524
- qt: Fix comparison function signature bitcoin#17634
- psbt: check that various indexes and amounts are within bounds bitcoin#17156
- [0.19] psbt: check that various indexes and amounts are within bounds bitcoin#18079
- [0.19] Final backports for 0.19.1 bitcoin#17988
- Bug: IsUsedDestination shouldn't use key id as script id for ScriptHash bitcoin#17924
- qt: Fix deprecated QCharRef usage bitcoin#18101
- gui: Throttle GUI update pace when -reindex bitcoin#18121
- gui: Fix race in WalletModel::pollBalanceChanged bitcoin#18123
- gui: Fix unintialized WalletView::progressDialog bitcoin#18062
- Bugfix: GUI: Hide the HD/encrypt icons earlier so they get re-shown if another wallet is open bitcoin#18007
- bug-fix macos: give free bytes to F_PREALLOCATE bitcoin#17887
- test: add missing #include to fix compiler errors bitcoin#17980
- zmq: Fix due to invalid argument and multiple notifiers bitcoin#17445
@kallewoof kallewoof deleted the macos-f_preallocate_fix branch September 2, 2020 04:00
@kallewoof
Copy link
Contributor Author

Apple responded to my bug report regarding this, in case people are curious: https://openradar.appspot.com/radar?id=4930713610616832

jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Sep 23, 2020
Summary:
The Initial Block Download (IBD) on macOS Catalina uses a lot more disk space than expected.

The macos manpage for fcntl (for F_PEOFPOSMODE) states:

> Allocate from the physical end of file.  In this case, fst_length indicates the number of newly allocated bytes desired.

This would result in the rev files being essentially pre-allocating 2x their necessary size (this is the case for block files as well, but these are flushed down to their right sizes every time) as they would pre-allocate pos + length free bytes, rather than allocating length bytes after pos, as expected.

Note: more explanations on the issue from Apple in this bug report
https://openradar.appspot.com/radar?id=4930713610616832

Backport of Bitcoin Core [[bitcoin/bitcoin#17887 | PR17887]]

Test Plan:
`ninja check` to verify that the patch does not accidentaly break anything else.
But I do not have a MacOS to run the tests on, and try to replicate the issue.

Reviewers: O1 Bitcoin ABC, #bitcoin_abc, deadalnix

Reviewed By: O1 Bitcoin ABC, #bitcoin_abc, deadalnix

Subscribers: deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D7526
sidhujag pushed a commit to syscoin-core/syscoin that referenced this pull request Nov 10, 2020
75163f4 bug-fix macos: give free bytes to F_PREALLOCATE (Karl-Johan Alm)

Pull request description:

  The macos manpage for `fcntl` (for `F_PEOFPOSMODE`) states:

  > Allocate from the physical end of file.  In this case, fst_length indicates the number of newly allocated bytes desired.

  This would result in the rev files being essentially pre-allocating 2x their necessary size (this is the case for block files as well, but these are flushed down to their right sizes every time) as they would pre-allocate `pos + length` **free** bytes, rather than allocating `length` bytes after `pos`, as expected.

  Fixes bitcoin#17827.

ACKs for top commit:
  eriknylund:
    ACK 75163f4 built locally. All tests passing. Manual test as per my previous comment above on an older commit, using an APFS unencrypted disk image with 3 GB.
  laanwj:
    code review ACK 75163f4

Tree-SHA512: 105c8d56c20acad8febdf0583f1e5721b63376ace325a7a62c2e4b15a442c7131404ed604c32c0cda716791d7ca5aa9f5b6a774ff86e39838bc7e87ca3c42760
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 17, 2021
75163f4 bug-fix macos: give free bytes to F_PREALLOCATE (Karl-Johan Alm)

Pull request description:

  The macos manpage for `fcntl` (for `F_PEOFPOSMODE`) states:

  > Allocate from the physical end of file.  In this case, fst_length indicates the number of newly allocated bytes desired.

  This would result in the rev files being essentially pre-allocating 2x their necessary size (this is the case for block files as well, but these are flushed down to their right sizes every time) as they would pre-allocate `pos + length` **free** bytes, rather than allocating `length` bytes after `pos`, as expected.

  Fixes bitcoin#17827.

ACKs for top commit:
  eriknylund:
    ACK 75163f4 built locally. All tests passing. Manual test as per my previous comment above on an older commit, using an APFS unencrypted disk image with 3 GB.
  laanwj:
    code review ACK 75163f4

Tree-SHA512: 105c8d56c20acad8febdf0583f1e5721b63376ace325a7a62c2e4b15a442c7131404ed604c32c0cda716791d7ca5aa9f5b6a774ff86e39838bc7e87ca3c42760
thelazier pushed a commit to thelazier/dash that referenced this pull request Sep 25, 2021
75163f4 bug-fix macos: give free bytes to F_PREALLOCATE (Karl-Johan Alm)

Pull request description:

  The macos manpage for `fcntl` (for `F_PEOFPOSMODE`) states:

  > Allocate from the physical end of file.  In this case, fst_length indicates the number of newly allocated bytes desired.

  This would result in the rev files being essentially pre-allocating 2x their necessary size (this is the case for block files as well, but these are flushed down to their right sizes every time) as they would pre-allocate `pos + length` **free** bytes, rather than allocating `length` bytes after `pos`, as expected.

  Fixes bitcoin#17827.

ACKs for top commit:
  eriknylund:
    ACK 75163f4 built locally. All tests passing. Manual test as per my previous comment above on an older commit, using an APFS unencrypted disk image with 3 GB.
  laanwj:
    code review ACK 75163f4

Tree-SHA512: 105c8d56c20acad8febdf0583f1e5721b63376ace325a7a62c2e4b15a442c7131404ed604c32c0cda716791d7ca5aa9f5b6a774ff86e39838bc7e87ca3c42760
Munkybooty pushed a commit to Munkybooty/dash that referenced this pull request Dec 9, 2021
daf2fff test: add missing #include to fix compiler errors (Karl-Johan Alm)
c8ad23c bug-fix macos: give free bytes to F_PREALLOCATE (Karl-Johan Alm)

Pull request description:

  We're about ready to do a [0.19.1 release](https://github.com/bitcoin/bitcoin/milestone/44); so I've opened this to collect the last remaining backports.

  If there's something that's been missed / or isn't tagged ["Needs backport (0.19)"](https://github.com/bitcoin/bitcoin/issues?q=is%3Aopen+label%3A%22Needs+backport+%280.19%29%22) that you think should be, please comment.

  Currently backports:
  * bitcoin#17887 - bug-fix macos: give free bytes to F_PREALLOCATE
  * bitcoin#17980 - test: add missing #include to fix compiler errors

ACKs for top commit:
  laanwj:
    ACK daf2fff

Tree-SHA512: 8438f992d0c39315a4da4c3f8ab5c92acefada4b0ba5a5cec3775dea2541492d386bf4e7c9e76e1494a6d4cf16a9205287d27ffd23d9c3056f213d733605eeee
Munkybooty pushed a commit to Munkybooty/dash that referenced this pull request Dec 9, 2021
daf2fff test: add missing #include to fix compiler errors (Karl-Johan Alm)
c8ad23c bug-fix macos: give free bytes to F_PREALLOCATE (Karl-Johan Alm)

Pull request description:

  We're about ready to do a [0.19.1 release](https://github.com/bitcoin/bitcoin/milestone/44); so I've opened this to collect the last remaining backports.

  If there's something that's been missed / or isn't tagged ["Needs backport (0.19)"](https://github.com/bitcoin/bitcoin/issues?q=is%3Aopen+label%3A%22Needs+backport+%280.19%29%22) that you think should be, please comment.

  Currently backports:
  * bitcoin#17887 - bug-fix macos: give free bytes to F_PREALLOCATE
  * bitcoin#17980 - test: add missing #include to fix compiler errors

ACKs for top commit:
  laanwj:
    ACK daf2fff

Tree-SHA512: 8438f992d0c39315a4da4c3f8ab5c92acefada4b0ba5a5cec3775dea2541492d386bf4e7c9e76e1494a6d4cf16a9205287d27ffd23d9c3056f213d733605eeee
Munkybooty pushed a commit to Munkybooty/dash that referenced this pull request Dec 9, 2021
daf2fff test: add missing #include to fix compiler errors (Karl-Johan Alm)
c8ad23c bug-fix macos: give free bytes to F_PREALLOCATE (Karl-Johan Alm)

Pull request description:

  We're about ready to do a [0.19.1 release](https://github.com/bitcoin/bitcoin/milestone/44); so I've opened this to collect the last remaining backports.

  If there's something that's been missed / or isn't tagged ["Needs backport (0.19)"](https://github.com/bitcoin/bitcoin/issues?q=is%3Aopen+label%3A%22Needs+backport+%280.19%29%22) that you think should be, please comment.

  Currently backports:
  * bitcoin#17887 - bug-fix macos: give free bytes to F_PREALLOCATE
  * bitcoin#17980 - test: add missing #include to fix compiler errors

ACKs for top commit:
  laanwj:
    ACK daf2fff

Tree-SHA512: 8438f992d0c39315a4da4c3f8ab5c92acefada4b0ba5a5cec3775dea2541492d386bf4e7c9e76e1494a6d4cf16a9205287d27ffd23d9c3056f213d733605eeee
Munkybooty pushed a commit to Munkybooty/dash that referenced this pull request Dec 23, 2021
daf2fff test: add missing #include to fix compiler errors (Karl-Johan Alm)
c8ad23c bug-fix macos: give free bytes to F_PREALLOCATE (Karl-Johan Alm)

Pull request description:

  We're about ready to do a [0.19.1 release](https://github.com/bitcoin/bitcoin/milestone/44); so I've opened this to collect the last remaining backports.

  If there's something that's been missed / or isn't tagged ["Needs backport (0.19)"](https://github.com/bitcoin/bitcoin/issues?q=is%3Aopen+label%3A%22Needs+backport+%280.19%29%22) that you think should be, please comment.

  Currently backports:
  * bitcoin#17887 - bug-fix macos: give free bytes to F_PREALLOCATE
  * bitcoin#17980 - test: add missing #include to fix compiler errors

ACKs for top commit:
  laanwj:
    ACK daf2fff

Tree-SHA512: 8438f992d0c39315a4da4c3f8ab5c92acefada4b0ba5a5cec3775dea2541492d386bf4e7c9e76e1494a6d4cf16a9205287d27ffd23d9c3056f213d733605eeee
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blocks directory on macOS uses more disk space than expected