Skip to content

Commit 1e18750

Browse files
Torstein-Eidekdave
authored andcommitted
btrfs-progs: docs: add balance filter examples
Add more examples and explanations how the filters can be used. Pull-request: #486 Author: Eideen Signed-off-by: David Sterba <[email protected]>
1 parent 9362803 commit 1e18750

File tree

3 files changed

+176
-24
lines changed

3 files changed

+176
-24
lines changed

Diff for: Documentation/Balance.rst

+5
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ Filters
77
-------
88

99
.. include:: ch-balance-filters.rst
10+
11+
Examples
12+
--------
13+
14+
.. include:: ch-balance-examples.rst

Diff for: Documentation/ch-balance-examples.rst

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
Adding new device
2+
^^^^^^^^^^^^^^^^^
3+
4+
The unallocated space requirements depend on the selected storage
5+
profiles. The requirements for the storage profile must be met for the
6+
selected for both data and metadata (e.g. if you have single data and
7+
RAID1 metadata, the stricter RAID1 requirements must be met or the
8+
filesystem may run out of metadata space and go read-only).
9+
10+
Before adding a drive, make sure there is enough unallocated space on
11+
existing drives to create new metadata block groups (for filesystems
12+
over 50GB, this is `1GB * (number_of_devices + 2))`.
13+
14+
If using a striped profile (`raid0`, `raid10`, `raid5`, or `raid6`), then do a
15+
full data balance of all data after adding a drive. If adding multiple
16+
drives at once, do a full data balance after adding the last one.
17+
18+
.. code-block:: bash
19+
20+
btrfs balance start -v --full-balance mnt/
21+
22+
If the balance is interrupted, it can be restarted using the *stripes*
23+
filter (i.e. `-dstripes=1..N` where *N* is the previous size of the array
24+
before the new device was added) as long as all devices are the same size.
25+
If the device sizes are different, a specialized userspace balance tool
26+
is required. The data balance must be completed before adding any new
27+
devices or increasing the size of existing ones.
28+
29+
.. code-block:: bash
30+
31+
# For going from 4 disk to 5 disks, in Raid 5
32+
btrfs balance start -v -dstripes=1..4 mnt/
33+
34+
If you are not using a striped profile now, but intend to convert to a
35+
striped profile in the future, always perform a full data balance after
36+
adding drives or replacing existing drives with larger ones. The stock
37+
*btrfs balance* tool cannot cope with special cases on filesystems with
38+
striped raid profiles, and will paint itself into a corner that will
39+
require custom userspace balancing tools to recover if you try.
40+
41+
To watch one can use the following:
42+
43+
.. code-block:: bash
44+
45+
watch "btrfs filesystem usage -T mnt/; btrfs balance status mnt/"
46+
47+
Convert RAID1 after mkfs with defaults
48+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
49+
50+
If you forgot to set the block group profile when creating the volume, run the
51+
following command:
52+
53+
.. code-block:: bash
54+
55+
btrfs balance start -v convert=raid1,soft mnt/
56+
57+
This will convert all remaining profiles that are not yet *raid1*.
58+
59+
Convert data to RAID10 with RAID1C4 for metadata
60+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
61+
62+
If you a have multi device setup, or you'd like to have different profiles on a
63+
single disk, e.g. *RAID10* for data and *RAID1C4* for metadata and system:
64+
65+
.. code-block:: bash
66+
67+
btrfs balance start -v -mconvert=raid1C4,soft -dconvert=raid10,soft mnt/
68+
69+
Compact under used chunks
70+
^^^^^^^^^^^^^^^^^^^^^^^^^
71+
72+
If the data chunks are not balanced and used only partially, the *usage* filter
73+
can be used to make them more compact:
74+
75+
.. code-block:: bash
76+
77+
btrfs balance start -v -dusage=10 mnt/
78+
79+
If the percent starts from a small number, like 5 or 10, the chunks will be
80+
processed relatively quickly and will make more space available. Increasing the
81+
percentage can then make more chunks compact by relocating the data.
82+
83+
Chunks utilized up to 50% can be relocated to other chunks while still freeing
84+
the space. With utilization higher than 50% the chunks will be basically only
85+
moved on the devices. The actual chunk layout may help to coalesce the free
86+
space but this is a secondary effect.
87+
88+
.. code-block:: bash
89+
90+
for USAGE in {10..50..10} do
91+
btrfs balance start -v -dusage=$USAGE mnt/
92+
done
93+
94+
Fix incomplete balance
95+
^^^^^^^^^^^^^^^^^^^^^^
96+
97+
If the balance is interrupted (due to reboot or cancelled) during conversion to
98+
RAID1. The following command will skip all RAID1 chunks that have been already
99+
converted and continue with what's left to convert. Note that an interrupted
100+
conversion may leave the last chunk under utilized.
101+
102+
.. code-block:: bash
103+
104+
btrfs balance start convert=raid1,soft mnt/

Diff for: Documentation/ch-balance-filters.rst

+67-24
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,58 @@
1-
From kernel 3.3 onwards, btrfs balance can limit its action to a subset of the
1+
From kernel 3.3 onwards, BTRFS balance can limit its action to a subset of the
22
whole filesystem, and can be used to change the replication configuration (e.g.
3-
moving data from single to RAID1). This functionality is accessed through the
4-
*-d*, *-m* or *-s* options to btrfs balance start, which filter on data,
5-
metadata and system blocks respectively.
3+
convert data from ``single`` to ``RAID1``).
64

7-
A filter has the following structure: *type[=params][,type=...]*
5+
Balance can be limited to a block group profile with the following options:
86

9-
The available types are:
7+
* ``-d`` for data block groups
8+
* ``-m`` for metadata block groups (also implicitly applies to *-s*)
9+
* ``-s`` for system block groups
10+
11+
The options have an optional parameter which means that the parameter must start
12+
right after the option without a space (this is mandatory getopt syntax), like
13+
``-dusage=10``. Options for all block group types can be specified in one command.
14+
15+
A filter has the following structure: ``filter[=params][,filter=...]``
16+
17+
To combine multiple filters use ``,``, without spaces. Example: ``-dconvert=raid1,soft``
18+
19+
BTRFS can have different profiles on a single device or the same profile on
20+
multiple device.
21+
22+
The main reason why you want to have different profiles for data and metadata
23+
is to provide additional protection of the filesystem's metadata when devices fail,
24+
since a single sector of unrecoverable metadata will break the filesystem,
25+
while a single sector of lost data can be trivially recovered by deleting the broken file.
26+
27+
Before changing profiles, make sure there is enough unallocated space on
28+
existing drives to create new metadata block groups (for filesystems
29+
over 50GiB, this is ``1GB * (number_of_devices + 2))``.
30+
31+
Default profiles on BTRFS are:
32+
33+
* data: ``single``
34+
* metadata:
35+
* single devices: ``dup``
36+
* multiple devices: ``raid1``
37+
38+
39+
The available filter types are:
40+
41+
Filter types
42+
^^^^^^^^^^^^
1043

1144
profiles=<profiles>
1245
Balances only block groups with the given profiles. Parameters
13-
are a list of profile names separated by "*|*" (pipe).
46+
are a list of profile names separated by ``|`` (pipe).
1447

1548
usage=<percent>, usage=<range>
1649
Balances only block groups with usage under the given percentage. The
1750
value of 0 is allowed and will clean up completely unused block groups, this
1851
should not require any new work space allocated. You may want to use *usage=0*
1952
in case balance is returning ENOSPC and your filesystem is not too full.
2053

21-
The argument may be a single value or a range. The single value *N* means *at
22-
most N percent used*, equivalent to *..N* range syntax. Kernels prior to 4.4
54+
The argument may be a single value or a range. The single value ``N`` means *at
55+
most N percent used*, equivalent to ``..N`` range syntax. Kernels prior to 4.4
2356
accept only the single value format.
2457
The minimum range boundary is inclusive, maximum is exclusive.
2558

@@ -29,44 +62,44 @@ devid=<id>
2962

3063
drange=<range>
3164
Balance only block groups which overlap with the given byte range on any
32-
device. Use in conjunction with *devid* to filter on a specific device. The
33-
parameter is a range specified as *start..end*.
65+
device. Use in conjunction with ``devid`` to filter on a specific device. The
66+
parameter is a range specified as ``start..end``.
3467

3568
vrange=<range>
3669
Balance only block groups which overlap with the given byte range in the
3770
filesystem's internal virtual address space. This is the address space that
3871
most reports from btrfs in the kernel log use. The parameter is a range
39-
specified as *start..end*.
72+
specified as ``start..end``.
4073

4174
convert=<profile>
4275
Convert each selected block group to the given profile name identified by
4376
parameters.
4477

4578
.. note::
46-
Starting with kernel 4.5, the *data* chunks can be converted to/from the
47-
*DUP* profile on a single device.
79+
Starting with kernel 4.5, the ``data`` chunks can be converted to/from the
80+
``DUP`` profile on a single device.
4881

4982
.. note::
50-
Starting with kernel 4.6, all profiles can be converted to/from *DUP* on
83+
Starting with kernel 4.6, all profiles can be converted to/from ``DUP`` on
5184
multi-device filesystems.
5285

5386
limit=<number>, limit=<range>
5487
Process only given number of chunks, after all filters are applied. This can be
55-
used to specifically target a chunk in connection with other filters (*drange*,
56-
*vrange*) or just simply limit the amount of work done by a single balance run.
88+
used to specifically target a chunk in connection with other filters (``drange``,
89+
``vrange``) or just simply limit the amount of work done by a single balance run.
5790

58-
The argument may be a single value or a range. The single value *N* means *at
59-
most N chunks*, equivalent to *..N* range syntax. Kernels prior to 4.4 accept
91+
The argument may be a single value or a range. The single value ``N`` means *at
92+
most N chunks*, equivalent to ``..N`` range syntax. Kernels prior to 4.4 accept
6093
only the single value format. The range minimum and maximum are inclusive.
6194

6295
stripes=<range>
6396
Balance only block groups which have the given number of stripes. The parameter
64-
is a range specified as *start..end*. Makes sense for block group profiles that
97+
is a range specified as ``start..end``. Makes sense for block group profiles that
6598
utilize striping, i.e. RAID0/10/5/6. The range minimum and maximum are
6699
inclusive.
67100

68101
soft
69-
Takes no parameters. Only has meaning when converting between profiles.
102+
Takes no parameters. Only has meaning when converting between profiles, or
70103
When doing convert from one profile to another and soft mode is on,
71104
chunks that already have the target profile are left untouched.
72105
This is useful e.g. when half of the filesystem was converted earlier but got
@@ -76,9 +109,19 @@ soft
76109
For example, this means that we can convert metadata chunks the "hard" way
77110
while converting data chunks selectively with soft switch.
78111

79-
Profile names, used in *profiles* and *convert* are one of: *raid0*, *raid1*,
80-
*raid1c3*, *raid1c4*, *raid10*, *raid5*, *raid6*, *dup*, *single*. The mixed
81-
data/metadata profiles can be converted in the same way, but it's conversion
112+
Profile names, used in ``profiles`` and ``convert`` are one of:
113+
114+
* ``raid0``
115+
* ``raid1``
116+
* ``raid1c3``
117+
* ``raid1c4``
118+
* ``raid10``
119+
* ``raid5``
120+
* ``raid6``
121+
* ``dup``
122+
* ``single``
123+
124+
The mixed data/metadata profiles can be converted in the same way, but conversion
82125
between mixed and non-mixed is not implemented. For the constraints of the
83126
profiles please refer to :doc:`mkfs.btrfs(8)<mkfs.btrfs>` section
84127
:ref:`PROFILES<man-mkfs-profiles>`.

0 commit comments

Comments
 (0)