Merge branch 'vendor/LIBRESSL'
[dragonfly.git] / share / doc / smm / 04.quotas / quotas.ms
1 .\" Copyright (c) 1983, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)quotas.ms   8.1 (Berkeley) 6/8/93
29 .\"
30 .EH 'SMM:4-%''Disc Quotas in a \s-2UNIX\s+2 Environment'
31 .OH 'Disc Quotas in a \s-2UNIX\s+2 Environment''SMM:4-%'
32 .ND 5th July, 1983
33 .TL
34 Disc Quotas in a \s-2UNIX\s+2\s-3\u*\d\s0 Environment
35 .FS
36 * UNIX is a trademark of Bell Laboratories.
37 .FE
38 .AU
39 Robert Elz
40 .AI
41 Department of Computer Science
42 University of Melbourne,
43 Parkville,
44 Victoria,
45 Australia.
46 .AB
47 .PP
48 In most computing environments, disc space is not
49 infinite.
50 The disc quota system provides a mechanism
51 to control usage of disc space, on an
52 individual basis.
53 .PP
54 Quotas may be set for each individual user, on any, or
55 all filesystems.
56 .PP
57 The quota system will warn users when they
58 exceed their allotted limit, but allow some
59 extra space for current work.
60 Repeatedly remaining over quota at logout,
61 will cause a fatal over quota condition eventually.
62 .PP
63 The quota system is an optional part of
64 \s-2VMUNIX\s0 that may be included when the
65 system is configured.
66 .AE
67 .NH 1
68 Users' view of disc quotas
69 .PP
70 To most users, disc quotas will either be of no concern,
71 or a fact of life that cannot be avoided.
72 The
73 \fIquota\fP\|(1)
74 command will provide information on any disc quotas
75 that may have been imposed upon a user.
76 .PP
77 There are two individual possible quotas that may be
78 imposed, usually if one is, both will be.
79 A limit can be set on the amount of space a user
80 can occupy, and there may be a limit on the number
81 of files (inodes) he can own.
82 .PP
83 .I Quota
84 provides information on the quotas that have
85 been set by the system administrators, in each
86 of these areas, and current usage.
87 .PP
88 There are four numbers for each limit, the current
89 usage, soft limit (quota), hard limit, and number
90 of remaining login warnings.
91 The soft limit is the number of 1K blocks (or files)
92 that the user is expected to remain below.
93 Each time the user's usage goes past this limit,
94 he will be warned.
95 The hard limit cannot be exceeded.
96 If a user's usage reaches this number, further
97 requests for space (or attempts to create a file)
98 will fail with an EDQUOT error, and the first time
99 this occurs, a message will be written to the user's
100 terminal.
101 Only one message will be output, until space occupied
102 is reduced below the limit, and reaches it again,
103 in order to avoid continual noise from those
104 programs that ignore write errors.
105 .PP
106 Whenever a user logs in with a usage greater than
107 his soft limit, he will be warned, and his login
108 warning count decremented.
109 When he logs in under quota, the counter is reset
110 to its maximum value (which is a system configuration
111 parameter, that is typically 3).
112 If the warning count should ever reach zero (caused
113 by three successive logins over quota), the
114 particular limit that has been exceeded will be treated
115 as if the hard limit has been reached, and no
116 more resources will be allocated to the user.
117 The \fBonly\fP way to reset this condition is
118 to reduce usage below quota, then log in again.
119 .NH 2
120 Surviving when quota limit is reached
121 .PP
122 In most cases, the only way to recover from over
123 quota conditions, is to abort whatever activity was in progress
124 on the filesystem that has reached its limit, remove
125 sufficient files to bring the limit back below quota,
126 and retry the failed program.
127 .PP
128 However, if you are in the editor and a write fails
129 because of an over quota situation, that is not
130 a suitable course of action, as it is most likely
131 that initially attempting to write the file
132 will have truncated its previous contents, so should
133 the editor be aborted without correctly writing the
134 file not only will the recent changes be lost, but
135 possibly much, or even all, of the data
136 that previously existed.
137 .PP
138 There are several possible safe exits for a user
139 caught in this situation.
140 He may use the editor \fB!\fP shell escape command to
141 examine his file space, and remove surplus files.
142 Alternatively, using \fIcsh\fP, he may suspend the
143 editor, remove some files, then resume it.
144 A third possibility, is to write the file to
145 some other filesystem (perhaps to a file on /tmp)
146 where the user's quota has not been exceeded.
147 Then after rectifying the quota situation,
148 the file can be moved back to the filesystem
149 it belongs on.
150 .NH 1
151 Administering the quota system
152 .PP
153 To set up and establish the disc quota system,
154 there are several steps necessary to be performed
155 by the system administrator.
156 .PP
157 First, the system must be configured to include
158 the disc quota sub-system.
159 This is done by including the line:
160 .DS
161 options   QUOTA
162 .DE
163 in the system configuration file, then running
164 \fIconfig\fP\|(8)
165 followed by a system configuration\s-3\u*\d\s0.
166 .FS
167 * See also the document ``Building 4.2BSD UNIX Systems with Config''.
168 .FE
169 .PP
170 Second, a decision as to what filesystems need to have
171 quotas applied needs to be made.
172 Usually, only filesystems that house users' home directories,
173 or other user files, will need to be subjected to
174 the quota system, though it may also prove useful to
175 also include \fB/usr\fR.
176 If possible, \fB/tmp\fP should usually be free of quotas.
177 .PP
178 Having decided on which filesystems quotas need to be
179 set upon, the administrator should then allocate the
180 available space amongst the competing needs. How this
181 should be done is (way) beyond the scope of this document.
182 .PP
183 Then, the
184 \fIedquota\fP\|(8)
185 command can be used to actually set the limits desired upon
186 each user. Where a number of users are to be given the
187 same quotas (a common occurrence) the \fB\-p\fP switch
188 to edquota will allow this to be easily accomplished.
189 .PP
190 Once the quotas are set, ready to operate, the system
191 must be informed to enforce quotas on the desired filesystems.
192 This is accomplished with the
193 \fIquotaon\fP\|(8)
194 command.
195 .I Quotaon
196 will either enable quotas for a particular filesystem, or
197 with the \fB\-a\fP switch, will enable quotas for each
198 filesystem indicated in \fB/etc/fstab\fP as using quotas.
199 See
200 \fIfstab\fP\|(5)
201 for details.
202 Most sites using the quota system, will include the
203 line
204 .DS C
205 /etc/quotaon -a
206 .DE
207 in \fB/etc/rc.local\fP.
208 .PP
209 Should quotas need to be disabled, the
210 \fIquotaoff\fP(8)
211 command will do that, however, should the filesystem be
212 about to be dismounted, the
213 \fIumount\fP\|(8)
214 command will disable quotas immediately before the
215 filesystem is unmounted.
216 This is actually an effect of the
217 \fIumount\fP\|(2)
218 system call, and it guarantees that the quota system
219 will not be disabled if the umount would fail
220 because the filesystem is not idle.
221 .PP
222 Periodically (certainly after each reboot, and when quotas
223 are first enabled for a filesystem), the records retained
224 in the quota file should be checked for consistency with
225 the actual number of blocks and files allocated to
226 the user.
227 The
228 \fIquotacheck\fP\|(8)
229 command can be used to accomplish this.
230 It is not necessary to dismount the filesystem, or disable
231 the quota system to run this command, though on
232 active filesystems inaccurate results may occur.
233 This does no real harm in most cases, another run of
234 .I quotacheck
235 when the filesystem is idle will certainly correct any inaccuracy.
236 .PP
237 The super-user may use the
238 \fIquota\fP\|(1)
239 command to examine the usage and quotas of any user, and
240 the
241 \fIrepquota\fP\|(8)
242 command may be used to check the usages and limits for
243 all users on a filesystem.
244 .NH 1
245 Some implementation detail.
246 .PP
247 Disc quota usage and information is stored in a file on the
248 filesystem that the quotas are to be applied to.
249 Conventionally, this file is \fBquotas\fR in the root of
250 the filesystem.
251 While this name is not known to the system in any way,
252 several of the user level utilities "know" it, and
253 choosing any other name would not be wise.
254 .PP
255 The data in the file comprises an array of structures, indexed
256 by uid, one structure for each user on the system (whether
257 the user has a quota on this filesystem or not).
258 If the uid space is sparse, then the file may have holes
259 in it, which would be lost by copying, so it is best to
260 avoid this.
261 .PP
262 The system is informed of the existence of the quota
263 file by the
264 \fIsetquota\fP\|(2)
265 system call.
266 It then reads the quota entries for each user currently
267 active, then for any files open owned by users who
268 are not currently active.
269 Each subsequent open of a file on the filesystem, will
270 be accompanied by a pairing with its quota information.
271 In most cases this information will be retained in core,
272 either because the user who owns the file is running some
273 process, because other files are open owned by the same
274 user, or because some file (perhaps this one) was recently
275 accessed.
276 In memory, the quota information is kept hashed by user-id
277 and filesystem, and retained in an LRU chain so recently
278 released data can be easily reclaimed.
279 Information about those users whose last process has
280 recently terminated is also retained in this way.
281 .PP
282 Each time a block is accessed or released, and each time an inode
283 is allocated or freed, the quota system gets told
284 about it, and in the case of allocations, gets the
285 opportunity to object.
286 .PP
287 Measurements have shown
288 that the quota code uses a very small percentage of the system
289 cpu time consumed in writing a new block to disc.
290 .NH 1
291 Acknowledgments
292 .PP
293 The current disc quota system is loosely based upon a very
294 early scheme implemented at the University of New South
295 Wales, and Sydney University in the mid 70's. That system
296 implemented a single combined limit for both files and blocks
297 on all filesystems.
298 .PP
299 A later system was implemented at the University of Melbourne
300 by the author, but was not kept highly accurately, eg:
301 chown's (etc) did not affect quotas, nor did i/o to a file
302 other than one owned by the instigator.
303 .PP
304 The current system has been running (with only minor modifications)
305 since January 82 at Melbourne.
306 It is actually just a small part of a much broader resource
307 control scheme, which is capable of controlling almost
308 anything that is usually uncontrolled in unix. The rest
309 of this is, as yet, still in a state where it is far too
310 subject to change to be considered for distribution.
311 .PP
312 For the 4.2BSD release, much work has been done to clean
313 up and sanely incorporate the quota code by Sam Leffler and
314 Kirk McKusick at The University of California at Berkeley.