Skip to contentSkip to conversation

how many chunk trees and extent trees present

DISCUSSION sri 5 participants 10 messages Apr 17, 2015 – Mar 4, 2016 Btrfs file system

lore
Share & tools
lore

sri

author
#0 lore raw

Hi,
I have below queries. Could somebody help me in understanding.

1)
As per my understanding btrfs file system uses one chunk tree and one extent tree for entire btrfs disk allocation.

Is this correct?

In, some article i read that future there will be more chunk tree/ extent tree for single btrfs. Is this true.
If yes, I would like to know why more than one chunk / extent tree is required to represent one btrfs file system.

2)

Also I would like to know for a subvolume / snapshot , is there a provision to ask btrfs , represent all blocks belongs to that subvolume/snapshot should handle with a separate chunk tree and extent tree?

I am looking for a way to traverse a subvolume preferably a snapshot and identify all disk blocks (extents) allocated for that particular subvolume / snapshot.

#1 lore raw
Quoted 8 lines · sri

Hi,
I have below queries. Could somebody help me in understanding.

1)
As per my understanding btrfs file system uses one chunk tree and one extent tree for entire btrfs disk allocation.

Is this correct?

Yes.

Quoted 2 lines

In, some article i read that future there will be more chunk tree/ extent tree for single btrfs. Is this true.

I recall, many moons ago, Chris saying that there probably wouldn't
be.

Quoted 2 lines

If yes, I would like to know why more than one chunk / extent tree is required to represent one btrfs file system.

I think the original idea was that it would reduce lock contention
on the tree root.

Quoted 6 lines

2)

Also I would like to know for a subvolume / snapshot , is there a provision to ask btrfs , represent all blocks belongs to that subvolume/snapshot should handle with a separate chunk tree and extent tree?

No.

Quoted 3 lines

I am looking for a way to traverse a subvolume preferably a snapshot and identify all disk blocks (extents) allocated for that particular subvolume / snapshot.

Do you mean allocated to any file in the subvolume, or do you mean
*exclusively* allocated to that subvolume and not shared with any other?

The former is easy -- just walk the file tree, and read the extents
for each file. The latter is harder, because you have to look for extents that are not shared, and extents that are only shared within the current subvolume (think reflink copies within a subvol). I think you can do that by counting backrefs, but there may be big race conditions involved on a filesystem that's being written to (because the backrefs aren't created immediately, but delayed for performance reasons).

Note that if all you want is the count of those blocks (rather than
the block numbers themselves), then it's already been done with qgroups, and you don't need to write any btrfs code at all.

What exactly are you going to be doing with this information?

Hugo.

Signature · 4 lines
Hugo Mills             | O tempura! O moresushi!
hugo@... carfax.org.uk |
http://carfax.org.uk/  |
PGP: E2AB1DE4          |
author
#2 lore raw
Quoted 7 lines · Hugo Mills <hugo <at> carfax.org.uk> writes:
Quoted 5 lines · sri

Hi,
I have below queries. Could somebody help me in understanding.

1)
As per my understanding btrfs file system uses one chunk tree and

one

Quoted 7 lines
Quoted 3 lines

extent tree for entire btrfs disk allocation.

Is this correct?

Yes.

Quoted 1 line

In, some article i read that future there will be more chunk tree/

extent

Quoted 6 lines
Quoted 1 line

tree for single btrfs. Is this true.

I recall, many moons ago, Chris saying that there probably wouldn't
be.

Quoted 1 line

If yes, I would like to know why more than one chunk / extent tree

is

Quoted 10 lines
Quoted 1 line

required to represent one btrfs file system.

I think the original idea was that it would reduce lock contention
on the tree root.

Quoted 5 lines

2)

Also I would like to know for a subvolume / snapshot , is there a provision to ask btrfs , represent all blocks belongs to that subvolume/snapshot should handle with a separate chunk tree and

extent

Quoted 5 lines
Quoted 1 line

tree?

   No.
Quoted 1 line

I am looking for a way to traverse a subvolume preferably a snapshot

and

Quoted 1 line
Quoted 1 line

identify all disk blocks (extents) allocated for that particular

subvolume

Quoted 15 lines
Quoted 1 line

/ snapshot.

Do you mean allocated to any file in the subvolume, or do you mean
*exclusively* allocated to that subvolume and not shared with any other?

The former is easy -- just walk the file tree, and read the extents
for each file. The latter is harder, because you have to look for extents that are not shared, and extents that are only shared within the current subvolume (think reflink copies within a subvol). I think you can do that by counting backrefs, but there may be big race conditions involved on a filesystem that's being written to (because the backrefs aren't created immediately, but delayed for performance reasons).

Quoted 8 lines

Note that if all you want is the count of those blocks (rather than
the block numbers themselves), then it's already been done with qgroups, and you don't need to write any btrfs code at all.

What exactly are you going to be doing with this information?

Hugo.

I am trying a way to get all files and folders of a snapshot volume without making file system level calls (fopen etc..)

I want to write code to understand the corresponding snapshot btree and used related chunk tree and extent tree, and find out for each file (inode) all extent blocks.
If I want to backup, I will use above method to traverse snapshot subvolume at disk level and copy all blocks of files/directories.

Thank you
sri

#5 lore raw
In reply to Hugo Mills
Quoted 5 lines · Hugo Mills
Quoted 2 lines

In, some article i read that future there will be more chunk tree/ extent tree for single btrfs. Is this true.

I recall, many moons ago, Chris saying that there probably wouldn't
be.

More extent trees tied to a set of fs trees/subvolumes would be very useful for certain usecases *cough*encryption*cough*.

author
#3 lore raw
In reply to sri

Do you mean allocated to any file in the subvolume, or do you mean

Quoted 2 lines
Quoted 2 lines

*exclusively* allocated to that subvolume and not shared with any other?

Hi,
Like ext3/ext4, I can find all used blocks of the file system. Once identified, I can just copy those blocks for backup. The bit map provided by ext3/ext4 includes blocks allocated for both metadata and data, backup/recovery won't consume much space.

For btrfs, multiple subvolumes can be created on pool of disks and each subvolume can consider as individual file system, I want to know a mechanism of identifying blocks allocated for the the subvolume through its snapshot so that for recovery, i can able to recovery those blocks only.

If btrfs is created on 10 disks each of 100gb and one subvolume is 10GB, backup window will be less for just backing up the subvolume.

I checked btrfs send/receive but the problem with send/receive is
1. It is file level dump
2. previous snapshot should be present to get incremental otherwise it generates full backup again.

Quoted 11 lines · sri <toyours_sridhar <at> yahoo.co.in> writes:
Quoted 7 lines · Hugo Mills <hugo <at> carfax.org.uk> writes:
Quoted 5 lines · sri

Hi,
I have below queries. Could somebody help me in understanding.

1)
As per my understanding btrfs file system uses one chunk tree and

one

Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

extent tree for entire btrfs disk allocation.

Is this correct?

Yes.

Quoted 1 line

In, some article i read that future there will be more chunk tree/

extent

Quoted 3 lines
Quoted 1 line

tree for single btrfs. Is this true.

I recall, many moons ago, Chris saying that there probably

wouldn't

Quoted 7 lines
Quoted 3 lines

be.

Quoted 1 line

If yes, I would like to know why more than one chunk / extent tree

is

Quoted 3 lines
Quoted 1 line

required to represent one btrfs file system.

I think the original idea was that it would reduce lock

contention

Quoted 13 lines
Quoted 7 lines

on the tree root.

Quoted 5 lines

2)

Also I would like to know for a subvolume / snapshot , is there a provision to ask btrfs , represent all blocks belongs to that subvolume/snapshot should handle with a separate chunk tree and

extent

Quoted 5 lines
Quoted 1 line

tree?

   No.
Quoted 1 line

I am looking for a way to traverse a subvolume preferably a

snapshot

Quoted 6 lines

and

Quoted 1 line
Quoted 1 line

identify all disk blocks (extents) allocated for that particular

subvolume

Quoted 3 lines
Quoted 1 line

/ snapshot.

Do you mean allocated to any file in the subvolume, or do you

mean

Quoted 4 lines
Quoted 4 lines

*exclusively* allocated to that subvolume and not shared with any other?

The former is easy -- just walk the file tree, and read the

extents

Quoted 3 lines
Quoted 3 lines

for each file. The latter is harder, because you have to look for extents that are not shared, and extents that are only shared within the current subvolume (think reflink copies within a subvol). I

think

Quoted 6 lines
Quoted 6 lines

you can do that by counting backrefs, but there may be big race conditions involved on a filesystem that's being written to (because the backrefs aren't created immediately, but delayed for performance reasons).

Note that if all you want is the count of those blocks (rather

than

Quoted 5 lines
Quoted 5 lines

the block numbers themselves), then it's already been done with qgroups, and you don't need to write any btrfs code at all.

What exactly are you going to be doing with this information?

Quoted 7 lines
Quoted 2 lines

Hugo.

I am trying a way to get all files and folders of a snapshot volume without making file system level calls (fopen etc..)

I want to write code to understand the corresponding snapshot btree

and

Quoted 10 lines

used related chunk tree and extent tree, and find out for each file (inode) all extent blocks.
If I want to backup, I will use above method to traverse snapshot subvolume at disk level and copy all blocks of files/directories.

Thank you
sri

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs"

in

Quoted 4 lines

the body of a message to majordomo <at> vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

sri wrote on 2016/02/25 12:16 +0000:

Quoted 7 lines

Do you mean allocated to any file in the subvolume, or do you mean

Quoted 2 lines
Quoted 2 lines

*exclusively* allocated to that subvolume and not shared with any other?

Hi,
Like ext3/ext4, I can find all used blocks of the file system. Once identified, I can just copy those blocks for backup.

In btrfs, it's also very easy to find, just iterate all items in extent tree. All metadata/data blocks have its METADATA_ITEM/EXTENT_ITEM in extent tree. Your only concern to copy all these data should be btrfs chunk mapping.

Btrfs already has a tool to do such backup for metadata. Btrfs-image. Although it's mainly used for debug, so it doesn't backup data though.

Quoted 9 lines

The bit map
provided by ext3/ext4 includes blocks allocated for both metadata and data, backup/recovery won't consume much space.

For btrfs, multiple subvolumes can be created on pool of disks and each subvolume can consider as individual file system, I want to know a mechanism of identifying blocks allocated for the the subvolume through its snapshot so that for recovery, i can able to recovery those blocks only.

Unfortunately, all btrfs subvolumes/snapshots shares the same extent tree. And that's why btrfs subvolume is called *sub* volume, not volume. One subvolume can't function completely independently.

Although you can mount them as individual filesystem, it's still not full filesystem.

BTW, about separate extent/chunk tree, just as Hugo mentioned, it's planned to just reduce lock concurrency. IMHO, it would be per-chunk extent/chunk tree design.

For me, it's almost impossible to do per-subvolume extent/chunk tree.
Things like incoming btrfs in-band de-duplication and existing btrfs_clone/reflink can easily refer data outside a subvolume. Such design will just reduce the advantage of btrfs.

Quoted 6 lines

If btrfs is created on 10 disks each of 100gb and one subvolume is 10GB, backup window will be less for just backing up the subvolume.

I checked btrfs send/receive but the problem with send/receive is
1. It is file level dump

Isn't it done at subvolume/snapshot level?

Quoted 2 lines

2. previous snapshot should be present to get incremental otherwise it generates full backup again.

IMHO that's what incremental means.
The point is, btrfs snapshot can, and in most case, share metadata btree with its source subvolume/snapshot. This design makes btrfs snapshot small and fast(16K for one snapshot, and creation is very fast). But that's require strict incremental send, so we need its source snapshot in the filesystem.

At least for me, I still don't quite get the point of your goal.

If you want to incremental backup, then either use send of btrfs, or use more generic rsync method.

For understanding btrfs extent layout (including chunk and extent tree), I'd recommend to use btrfs-debug-tree and refer to btrfs wiki (https://btrfs.wiki.kernel.org/index.php/Btree_Items) as a start point.

Thanks,
Qu

Quoted 110 lines
Quoted 11 lines · sri <toyours_sridhar <at> yahoo.co.in> writes:
Quoted 7 lines · Hugo Mills <hugo <at> carfax.org.uk> writes:
Quoted 5 lines · sri

Hi,
I have below queries. Could somebody help me in understanding.

1)
As per my understanding btrfs file system uses one chunk tree and

one

Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

extent tree for entire btrfs disk allocation.

Is this correct?

Yes.

Quoted 1 line

In, some article i read that future there will be more chunk tree/

extent

Quoted 3 lines
Quoted 1 line

tree for single btrfs. Is this true.

I recall, many moons ago, Chris saying that there probably

wouldn't

Quoted 7 lines
Quoted 3 lines

be.

Quoted 1 line

If yes, I would like to know why more than one chunk / extent tree

is

Quoted 3 lines
Quoted 1 line

required to represent one btrfs file system.

I think the original idea was that it would reduce lock

contention

Quoted 13 lines
Quoted 7 lines

on the tree root.

Quoted 5 lines

2)

Also I would like to know for a subvolume / snapshot , is there a provision to ask btrfs , represent all blocks belongs to that subvolume/snapshot should handle with a separate chunk tree and

extent

Quoted 5 lines
Quoted 1 line

tree?

    No.
Quoted 1 line

I am looking for a way to traverse a subvolume preferably a

snapshot

Quoted 6 lines

and

Quoted 1 line
Quoted 1 line

identify all disk blocks (extents) allocated for that particular

subvolume

Quoted 3 lines
Quoted 1 line

/ snapshot.

Do you mean allocated to any file in the subvolume, or do you

mean

Quoted 4 lines
Quoted 4 lines

*exclusively* allocated to that subvolume and not shared with any other?

The former is easy -- just walk the file tree, and read the

extents

Quoted 3 lines
Quoted 3 lines

for each file. The latter is harder, because you have to look for extents that are not shared, and extents that are only shared within the current subvolume (think reflink copies within a subvol). I

think

Quoted 6 lines
Quoted 6 lines

you can do that by counting backrefs, but there may be big race conditions involved on a filesystem that's being written to (because the backrefs aren't created immediately, but delayed for performance reasons).

Note that if all you want is the count of those blocks (rather

than

Quoted 5 lines
Quoted 5 lines

the block numbers themselves), then it's already been done with qgroups, and you don't need to write any btrfs code at all.

What exactly are you going to be doing with this information?

Quoted 7 lines
Quoted 2 lines

Hugo.

I am trying a way to get all files and folders of a snapshot volume without making file system level calls (fopen etc..)

I want to write code to understand the corresponding snapshot btree

and

Quoted 10 lines

used related chunk tree and extent tree, and find out for each file (inode) all extent blocks.
If I want to backup, I will use above method to traverse snapshot subvolume at disk level and copy all blocks of files/directories.

Thank you
sri

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs"

in

Quoted 4 lines

the body of a message to majordomo <at> vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
In reply to David Sterba

David Sterba wrote on 2015/04/17 19:29 +0200:

Quoted 9 lines · Hugo Mills
Quoted 5 lines
Quoted 2 lines

In, some article i read that future there will be more chunk tree/ extent tree for single btrfs. Is this true.

I recall, many moons ago, Chris saying that there probably wouldn't
be.

More extent trees tied to a set of fs trees/subvolumes would be very useful for certain usecases *cough*encryption*cough*.

BTW, will such design makes reflink between different set of extents fallback to normal copy?

And I'm pretty sure that inband dedup will be affected too...

Thanks,
Qu

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw
Quoted 7 lines · Qu Wenruo

David Sterba wrote on 2015/04/17 19:29 +0200:

Quoted 4 lines · Hugo Mills
Quoted 3 lines
Quoted 2 lines

In, some article i read that future there will be more chunk tree/ extent tree for single btrfs. Is this true.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

I recall, many moons ago, Chris saying that there probably wouldn't
be.

More extent trees tied to a set of fs trees/subvolumes would be very useful for certain usecases *cough*encryption*cough*.

BTW, will such design makes reflink between different set of extents fallback to normal copy?

Yes, the actual reflink will not be possible.

Quoted 1 line

And I'm pretty sure that inband dedup will be affected too...

Yes.

#8 lore raw
In reply to David Sterba
Quoted 9 lines · David Sterba
Quoted 5 lines · Hugo Mills
Quoted 2 lines

In, some article i read that future there will be more chunk tree/ extent tree for single btrfs. Is this true.

I recall, many moons ago, Chris saying that there probably wouldn't
be.

More extent trees tied to a set of fs trees/subvolumes would be very useful for certain usecases *cough*encryption*cough*.

I didn't understand in full what's the idea here, but let met try.. would it not defeat the purpose of encryption which is not to let disk have the un-encrypted data ? Looks like I am missing something here.

Thanks, Anand

#9 lore raw
Quoted 10 lines · Anand Jain
Quoted 7 lines · David Sterba
Quoted 5 lines · Hugo Mills
Quoted 2 lines

In, some article i read that future there will be more chunk tree/ extent tree for single btrfs. Is this true.

I recall, many moons ago, Chris saying that there probably wouldn't
be.

Quoted 7 lines
Quoted 2 lines

More extent trees tied to a set of fs trees/subvolumes would be very useful for certain usecases *cough*encryption*cough*.

I didn't understand in full what's the idea here, but let met try.. would it not defeat the purpose of encryption which is not to let disk have the un-encrypted data ? Looks like I am missing something here.

Depends how the encryption is designed. The separate extent trees would allow to have mixed data in the filesystem, encrypted or not.

I can start with a normal filesystem, and then create encrypted subvolumes any time later.

The idea of multiple extent trees:

Currently we have only one, all subvolume share the extent tree, can do reflinks freely. We can create a subvolume (S1) and ask for a separate extent tree (E1). Now we can create snapshots of S1 that would share E1, and reflink accross snapshots that share E1.

Why is this useful to encryption: all data _and_ metadata blocks tied to E1 and the attached subvolums are encrypted, the plain text is not accessible without the key.

But the separate extent trees are useful on itself.