Debian Codegraph @

upstream/opensuse-leap-16-1/man8/btrfs-quota.8

raw
1 .\" Man page generated from reStructuredText.
2 .
3 .
4 .nr rst2man-indent-level 0
5 .
6 .de1 rstReportMargin
7 \\$1 \\n[an-margin]
8 level \\n[rst2man-indent-level]
9 level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
10 -
11 \\n[rst2man-indent0]
12 \\n[rst2man-indent1]
13 \\n[rst2man-indent2]
14 ..
15 .de1 INDENT
16 .\" .rstReportMargin pre:
17 . RS \\$1
18 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
19 . nr rst2man-indent-level +1
20 .\" .rstReportMargin post:
21 ..
22 .de UNINDENT
23 . RE
24 .\" indent \\n[an-margin]
25 .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
26 .nr rst2man-indent-level -1
27 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
28 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
29 ..
30 .TH "BTRFS-QUOTA" "8" "Mar 26, 2025" "6.14" "BTRFS"
31 .SH NAME
32 btrfs-quota \- control the global quota status of a btrfs filesystem
33 .SH SYNOPSIS
34 .sp
35 \fBbtrfs quota\fP <subcommand> <args>
36 .SH DESCRIPTION
37 .sp
38 The commands under \fBbtrfs quota\fP are used to affect the global status of quotas
39 of a btrfs filesystem. The quota groups (qgroups) are managed by the subcommand
40 \fI\%btrfs\-qgroup(8)\fP\&.
41 .sp
42 \fBNOTE:\fP
43 .INDENT 0.0
44 .INDENT 3.5
45 Qgroups are different than the traditional user quotas and designed
46 to track shared and exclusive data per\-subvolume. Please refer to the section
47 \fI\%HIERARCHICAL QUOTA GROUP CONCEPTS\fP
48 for a detailed description.
49 .UNINDENT
50 .UNINDENT
51 .SS PERFORMANCE IMPLICATIONS
52 .sp
53 When quotas are activated, they affect all extent processing, which takes a
54 performance hit. Activation of qgroups is not recommended unless the user
55 intends to actually use them.
56 .SS STABILITY STATUS
57 .sp
58 The qgroup implementation has turned out to be quite difficult as it affects
59 the core of the filesystem operation. Qgroup users have hit various corner cases
60 over time, such as incorrect accounting or system instability. The situation is
61 gradually improving and issues found and fixed.
62 .SH HIERARCHICAL QUOTA GROUP CONCEPTS
63 .sp
64 The concept of quota has a long\-standing tradition in the Unix world. Ever
65 since computers allow multiple users to work simultaneously in one filesystem,
66 there is the need to prevent one user from using up the entire space. Every
67 user should get his fair share of the available resources.
68 .sp
69 In case of files, the solution is quite straightforward. Each file has an
70 \fIowner\fP recorded along with it, and it has a size. Traditional quota just
71 restricts the total size of all files that are owned by a user. The concept is
72 quite flexible: if a user hits his quota limit, the administrator can raise it
73 on the fly.
74 .sp
75 On the other hand, the traditional approach has only a poor solution to
76 restrict directories.
77 At installation time, the harddisk can be partitioned so that every directory
78 (e.g. \fB/usr\fP, \fB/var\fP, ...) that needs a limit gets its own partition. The obvious
79 problem is that those limits cannot be changed without a reinstallation. The
80 btrfs subvolume feature builds a bridge. Subvolumes correspond in many ways to
81 partitions, as every subvolume looks like its own filesystem. With subvolume
82 quota, it is now possible to restrict each subvolume like a partition, but keep
83 the flexibility of quota. The space for each subvolume can be expanded or
84 restricted on the fly.
85 .sp
86 As subvolumes are the basis for snapshots, interesting questions arise as to
87 how to account used space in the presence of snapshots. If you have a file
88 shared between a subvolume and a snapshot, whom to account the file to? The
89 creator? Both? What if the file gets modified in the snapshot, should only
90 these changes be accounted to it? But wait, both the snapshot and the subvolume
91 belong to the same user home. I just want to limit the total space used by
92 both! But somebody else might not want to charge the snapshots to the users.
93 .sp
94 Btrfs subvolume quota solves these problems by introducing groups of subvolumes
95 and let the user put limits on them. It is even possible to have groups of
96 groups. In the following, we refer to them as \fIqgroups\fP\&.
97 .sp
98 Each qgroup primarily tracks two numbers, the amount of total referenced
99 space and the amount of exclusively referenced space.
100 .INDENT 0.0
101 .TP
102 .B referenced
103 space is the amount of data that can be reached from any of the
104 subvolumes contained in the qgroup, while
105 .TP
106 .B exclusive
107 is the amount of data where all references to this data can be reached
108 from within this qgroup.
109 .UNINDENT
110 .SS Subvolume quota groups
111 .sp
112 The basic notion of the Subvolume Quota feature is the quota group, short
113 qgroup. Qgroups are notated as \fIlevel/id\fP, e.g. the qgroup 3/2 is a qgroup of
114 level 3. For level 0, the leading \fI0/\fP can be omitted.
115 Qgroups of level 0 get created automatically when a subvolume/snapshot gets
116 created. The ID of the qgroup corresponds to the ID of the subvolume, so 0/5
117 is the qgroup for the root subvolume.
118 For the \fBbtrfs qgroup\fP command, the path to the subvolume can also be used
119 instead of \fI0/ID\fP\&. For all higher levels, the ID can be chosen freely.
120 .sp
121 Each qgroup can contain a set of lower level qgroups, thus creating a hierarchy
122 of qgroups. Figure 1 shows an example qgroup tree.
123 .INDENT 0.0
124 .INDENT 3.5
125 .sp
126 .EX
127 +\-\-\-+
128 |2/1|
129 +\-\-\-+
130 / \e
131 +\-\-\-+/ \e+\-\-\-+
132 |1/1| |1/2|
133 +\-\-\-+ +\-\-\-+
134 / \e / \e
135 +\-\-\-+/ \e+\-\-\-+/ \e+\-\-\-+
136 qgroups |0/1| |0/2| |0/3|
137 +\-+\-+ +\-\-\-+ +\-\-\-+
138 | / \e / \e
139 | / \e / \e
140 | / \e / \e
141 extents 1 2 3 4
142
143 Figure 1: Sample qgroup hierarchy
144 .EE
145 .UNINDENT
146 .UNINDENT
147 .sp
148 At the bottom, some extents are depicted showing which qgroups reference which
149 extents. It is important to understand the notion of \fIreferenced\fP vs
150 \fIexclusive\fP\&. In the example, qgroup 0/2 references extents 2 and 3, while 1/2
151 references extents 2\-4, 2/1 references all extents.
152 .sp
153 On the other hand, extent 1 is exclusive to 0/1, extent 2 is exclusive to 0/2,
154 while extent 3 is neither exclusive to 0/2 nor to 0/3. But because both
155 references can be reached from 1/2, extent 3 is exclusive to 1/2. All extents
156 are exclusive to 2/1.
157 .sp
158 So exclusive does not mean there is no other way to reach the extent, but it
159 does mean that if you delete all subvolumes contained in a qgroup, the extent
160 will get deleted.
161 .sp
162 Exclusive of a qgroup conveys the useful information how much space will be
163 freed in case all subvolumes of the qgroup get deleted.
164 .sp
165 All data extents are accounted this way. Metadata that belongs to a specific
166 subvolume (i.e. its filesystem tree) is also accounted. Checksums and extent
167 allocation information are not accounted.
168 .sp
169 In turn, the referenced count of a qgroup can be limited. All writes beyond
170 this limit will lead to a \(aqQuota Exceeded\(aq error.
171 .SS Inheritance
172 .sp
173 Things get a bit more complicated when new subvolumes or snapshots are created.
174 The case of (empty) subvolumes is still quite easy. If a subvolume should be
175 part of a qgroup, it has to be added to the qgroup at creation time. To add it
176 at a later time, it would be necessary to at least rescan the full subvolume
177 for a proper accounting.
178 .sp
179 Creation of a snapshot is the hard case. Obviously, the snapshot will
180 reference the exact amount of space as its source, and both source and
181 destination now have an exclusive count of 0 (the filesystem nodesize to be
182 precise, as the roots of the trees are not shared). But what about qgroups of
183 higher levels? If the qgroup contains both the source and the destination,
184 nothing changes. If the qgroup contains only the source, it might lose some
185 exclusive.
186 .sp
187 But how much? The tempting answer is, subtract all exclusive of the source from
188 the qgroup, but that is wrong, or at least not enough. There could have been
189 an extent that is referenced from the source and another subvolume from that
190 qgroup. This extent would have been exclusive to the qgroup, but not to the
191 source subvolume. With the creation of the snapshot, the qgroup would also
192 lose this extent from its exclusive set.
193 .sp
194 So how can this problem be solved? In the instant the snapshot gets created, we
195 already have to know the correct exclusive count. We need to have a second
196 qgroup that contains all the subvolumes as the first qgroup, except the
197 subvolume we want to snapshot. The moment we create the snapshot, the
198 exclusive count from the second qgroup needs to be copied to the first qgroup,
199 as it represents the correct value. The second qgroup is called a tracking
200 qgroup. It is only there in case a snapshot is needed.
201 .SS Use cases
202 .sp
203 Below are some use cases that do not mean to be extensive. You can find your
204 own way how to integrate qgroups.
205 .SS Single\-user machine
206 .sp
207 \fBReplacement for partitions.\fP
208 The simplest use case is to use qgroups as simple replacement for partitions.
209 Btrfs takes the disk as a whole, and \fB/\fP, \fB/usr\fP, \fB/var\fP, etc. are created as
210 subvolumes. As each subvolume gets it own qgroup automatically, they can
211 simply be restricted. No hierarchy is needed for that.
212 .sp
213 \fBTrack usage of snapshots.\fP
214 When a snapshot is taken, a qgroup for it will automatically be created with
215 the correct values. \fIReferenced\fP will show how much is in it, possibly shared
216 with other subvolumes. \fIExclusive\fP will be the amount of space that gets freed
217 when the subvolume is deleted.
218 .SS Multi\-user machine
219 .sp
220 \fBRestricting homes.\fP
221 When you have several users on a machine, with home directories probably under
222 \fB/home\fP, you might want to restrict \fB/home\fP as a whole, while restricting every
223 user to an individual limit as well. This is easily accomplished by creating a
224 qgroup for \fB/home\fP , e.g. 1/1, and assigning all user subvolumes to it.
225 Restricting this qgroup will limit /home, while every user subvolume can get
226 its own (lower) limit.
227 .sp
228 \fBAccounting snapshots to the user.\fP
229 Let\(aqs say the user is allowed to create snapshots via some mechanism. It would
230 only be fair to account space used by the snapshots to the user. This does not
231 mean the user doubles his usage as soon as he takes a snapshot. Of course,
232 files that are present in his home and the snapshot should only be accounted
233 once. This can be accomplished by creating a qgroup for each user, say
234 \fI1/UID\fP\&. The user home and all snapshots are assigned to this qgroup.
235 Limiting it will extend the limit to all snapshots, counting files only once.
236 To limit \fB/home\fP as a whole, a higher level group 2/1 replacing 1/1 from the
237 previous example is needed, with all user qgroups assigned to it.
238 .sp
239 \fBDo not account snapshots.\fP
240 On the other hand, when the snapshots get created automatically, the user has
241 no chance to control them, so the space used by them should not be accounted to
242 him. This is already the case when creating snapshots in the example from
243 the previous section.
244 .sp
245 \fBSnapshots for backup purposes.\fP
246 This scenario is a mixture of the previous two. The user can create snapshots,
247 but some snapshots for backup purposes are being created by the system. The
248 user\(aqs snapshots should be accounted to the user, not the system. The solution
249 is similar to the one from section \fIAccounting snapshots to the user\fP, but do
250 not assign system snapshots to user\(aqs qgroup.
251 .SS Simple quotas (squota)
252 .sp
253 As detailed in this document, qgroups can handle many complex extent sharing
254 and unsharing scenarios while maintaining an accurate count of exclusive and
255 shared usage. However, this flexibility comes at a cost: many of the
256 computations are global, in the sense that we must count up the number of trees
257 referring to an extent after its references change. This can slow down
258 transaction commits and lead to unacceptable latencies, especially in cases
259 where snapshots scale up.
260 .sp
261 To work around this limitation of qgroups, btrfs also supports a second set of
262 quota semantics: \fIsimple quotas\fP or \fIsquotas\fP\&. Squotas fully share the qgroups API
263 and hierarchical model, but do not track shared vs. exclusive usage. Instead,
264 they account all extents to the subvolume that first allocated it. With a bit
265 of new bookkeeping, this allows all accounting decisions to be local to the
266 allocation or freeing operation that deals with the extents themselves, and
267 fully avoids the complex and costly back\-reference resolutions.
268 .sp
269 \fBExample\fP
270 .sp
271 To illustrate the difference between squotas and qgroups, consider the following
272 basic example assuming a nodesize of 16KiB.
273 .INDENT 0.0
274 .IP 1. 3
275 create subvolume 256
276 .IP 2. 3
277 rack up 1GiB of data and metadata usage in 256
278 .IP 3. 3
279 snapshot 256, creating subvolume 257
280 .IP 4. 3
281 COW 512MiB of the data and metadata in 257
282 .IP 5. 3
283 delete everything in 256
284 .UNINDENT
285 .sp
286 At each step, qgroups would have the following accounting:
287 .INDENT 0.0
288 .IP 1. 3
289 0/256: 16KiB excl 0 shared
290 .IP 2. 3
291 0/256: 1GiB excl 0 shared
292 .IP 3. 3
293 0/256: 0 excl 1GiB shared; 0/257: 0 excl 1GiB shared
294 .IP 4. 3
295 0/256: 512MiB excl 512MiB shared; 0/257: 512MiB excl 512MiB shared
296 .IP 5. 3
297 0/256: 16KiB excl 0 shared; 0/257: 1GiB excl 0 shared
298 .UNINDENT
299 .sp
300 Whereas under squotas, the accounting would look like:
301 .INDENT 0.0
302 .IP 1. 3
303 0/256: 16KiB excl 16KiB shared
304 .IP 2. 3
305 0/256: 1GiB excl 1GiB shared
306 .IP 3. 3
307 0/256: 1GiB excl 1GiB shared; 0/257: 16KiB excl 16KiB shared
308 .IP 4. 3
309 0/256: 1GiB excl 1GiB shared; 0/257: 512MiB excl 512MiB shared
310 .IP 5. 3
311 0/256: 512MiB excl 512MiB shared; 0/257: 512MiB excl 512MiB shared
312 .UNINDENT
313 .sp
314 Note that since the original snapshotted 512MiB are still referenced by 257,
315 they cannot be freed from 256, even after 256 is emptied, or even deleted.
316 .sp
317 \fBSummary\fP
318 .sp
319 If you want some of power and flexibility of quotas for tracking and limiting
320 subvolume usage, but want to avoid the performance penalty of accurately
321 tracking extent ownership life cycles, then squotas can be a useful option.
322 .sp
323 Furthermore, squotas is targeted at use cases where the original extent is
324 immutable, like image snapshotting for container startup, in which case we avoid
325 these awkward scenarios where a subvolume is empty or deleted but still has
326 significant extents accounted to it. However, as long as you are aware of the
327 accounting semantics, they can handle mutable original extents.
328 .SH SUBCOMMAND
329 .INDENT 0.0
330 .TP
331 .B disable <path>
332 Disable subvolume quota support for a filesystem.
333 .TP
334 .B enable [options] <path>
335 Enable subvolume quota support for a filesystem. At this point it\(aqs
336 possible the two modes of accounting. The \fIfull\fP means that extent
337 ownership by subvolumes will be tracked all the time, \fIsimple\fP will
338 account everything to the first owner. See the section for more details.
339 .sp
340 \fBOptions\fP
341 .INDENT 7.0
342 .TP
343 .B \-s|\-\-simple
344 use simple quotas (squotas) instead of full qgroup accounting
345 .UNINDENT
346 .TP
347 .B rescan [options] <path>
348 Trash all qgroup numbers and scan the metadata again with the current config.
349 .sp
350 \fBOptions\fP
351 .INDENT 7.0
352 .TP
353 .B \-s|\-\-status
354 show status of a running rescan operation.
355 .TP
356 .B \-w|\-\-wait
357 start rescan and wait for it to finish (can be already in progress)
358 .TP
359 .B \-W|\-\-wait\-norescan
360 wait for rescan to finish without starting it
361 .UNINDENT
362 .UNINDENT
363 .SH EXIT STATUS
364 .sp
365 \fBbtrfs quota\fP returns a zero exit status if it succeeds. Non zero is
366 returned in case of failure.
367 .SH AVAILABILITY
368 .sp
369 \fBbtrfs\fP is part of btrfs\-progs. Please refer to the documentation at
370 \X'tty: link https://btrfs.readthedocs.io'\fI\%https://btrfs.readthedocs.io\fP\X'tty: link'\&.
371 .SH SEE ALSO
372 .sp
373 \fI\%btrfs\-qgroup(8)\fP,
374 \fI\%btrfs\-subvolume(8)\fP,
375 \fI\%mkfs.btrfs(8)\fP
376 .\" Generated by docutils manpage writer.
377 .