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