bcachefs icon indicating copy to clipboard operation
bcachefs copied to clipboard

Exporting extents / file location on block device

Open thememika opened this issue 1 year ago • 4 comments

Hello. Assuming I create a file with the nocow attribute and fully pre-allocate all of needed space (by writing zeroes to the file), and assuming that I have no reflink and no snapshots enabled, is there a way to export the block-layer location of the file from bcachefs, and to safely write there on block level? The original problem is that I created a filesystem that is too big, but shrinking is not supported. Thanks. Loop device on bcachefs is too slow, and causes deadlock if used as Swap, because access through bcachefs is RAM hungry...

thememika avatar Nov 02 '24 15:11 thememika

The old good interface used by filefrag utility reports more than 23 thousands of extents for my file. It's just not possible to set up such a table in DeviceMapper, for example. Anyways I'm not sure if it's safe to write to them. i.e. if they can suddenly be relocated and that place can become reused for something else -then it's def not safe.

thememika avatar Nov 02 '24 16:11 thememika

DeviceMapper (linear) didn't mind that the table was so huge. I have parsed the filefrag output, and successfully created the mapping to my block device. I just still really want to know from someone knowledgeable in bcachefs, if this is a safe thing to do.

thememika avatar Nov 02 '24 19:11 thememika

For now works ok. I'll post here if something bad happens.

thememika avatar Nov 03 '24 05:11 thememika

Putting your swap there seems crazy risky, because bcachefs could move the extents at any point (think rebalance, compaction), and you'll be scribbling over data that backs your mounted filesystem. You would have to tackle #368 to do this safely. The way btrfs does it with swap_activate/swap_deactivate could be a good template.

g2p avatar Nov 09 '24 20:11 g2p