10 D
\bDi
\bis
\bsc
\bc Q
\bQu
\buo
\bot
\bta
\bas
\bs i
\bin
\bn a
\ba U
\bUN
\bNI
\bIX
\bX*
\b* E
\bEn
\bnv
\bvi
\bir
\bro
\bon
\bnm
\bme
\ben
\bnt
\bt
12 _
\bR_
\bo_
\bb_
\be_
\br_
\bt _
\bE_
\bl_
\bz
13 Department of Computer Science
14 University of Melbourne,
20 _
\bA_
\bB_
\bS_
\bT_
\bR_
\bA_
\bC_
\bT
24 In most computing environments, disc space is
25 not infinite. The disc quota system provides a
26 mechanism to control usage of disc space, on an
29 Quotas may be set for each individual user,
30 on any, or all filesystems.
32 The quota system will warn users when they
33 exceed their allotted limit, but allow some extra
34 space for current work. Repeatedly remaining over
35 quota at logout, will cause a fatal over quota
38 The quota system is an optional part of VMU-
39 NIX that may be included when the system is con-
43 1
\b1.
\b. U
\bUs
\bse
\ber
\brs
\bs'
\b' v
\bvi
\bie
\bew
\bw o
\bof
\bf d
\bdi
\bis
\bsc
\bc q
\bqu
\buo
\bot
\bta
\bas
\bs
45 To most users, disc quotas will either be of no con-
46 cern, or a fact of life that cannot be avoided. The
47 _
\bq_
\bu_
\bo_
\bt_
\ba(1) command will provide information on any disc quotas
48 that may have been imposed upon a user.
50 There are two individual possible quotas that may be
51 imposed, usually if one is, both will be. A limit can be
52 set on the amount of space a user can occupy, and there may
53 be a limit on the number of files (inodes) he can own.
55 _
\bQ_
\bu_
\bo_
\bt_
\ba provides information on the quotas that have been
56 set by the system administrators, in each of these areas,
60 * UNIX is a trademark of Bell Laboratories.
70 SMM:4-2 Disc Quotas in a UNIX Environment
73 There are four numbers for each limit, the current
74 usage, soft limit (quota), hard limit, and number of remain-
75 ing login warnings. The soft limit is the number of 1K
76 blocks (or files) that the user is expected to remain below.
77 Each time the user's usage goes past this limit, he will be
78 warned. The hard limit cannot be exceeded. If a user's
79 usage reaches this number, further requests for space (or
80 attempts to create a file) will fail with an EDQUOT error,
81 and the first time this occurs, a message will be written to
82 the user's terminal. Only one message will be output, until
83 space occupied is reduced below the limit, and reaches it
84 again, in order to avoid continual noise from those programs
85 that ignore write errors.
87 Whenever a user logs in with a usage greater than his
88 soft limit, he will be warned, and his login warning count
89 decremented. When he logs in under quota, the counter is
90 reset to its maximum value (which is a system configuration
91 parameter, that is typically 3). If the warning count
92 should ever reach zero (caused by three successive logins
93 over quota), the particular limit that has been exceeded
94 will be treated as if the hard limit has been reached, and
95 no more resources will be allocated to the user. The o
\bon
\bnl
\bly
\by
96 way to reset this condition is to reduce usage below quota,
99 1
\b1.
\b.1
\b1.
\b. S
\bSu
\bur
\brv
\bvi
\biv
\bvi
\bin
\bng
\bg w
\bwh
\bhe
\ben
\bn q
\bqu
\buo
\bot
\bta
\ba l
\bli
\bim
\bmi
\bit
\bt i
\bis
\bs r
\bre
\bea
\bac
\bch
\bhe
\bed
\bd
101 In most cases, the only way to recover from over quota
102 conditions, is to abort whatever activity was in progress on
103 the filesystem that has reached its limit, remove sufficient
104 files to bring the limit back below quota, and retry the
107 However, if you are in the editor and a write fails
108 because of an over quota situation, that is not a suitable
109 course of action, as it is most likely that initially
110 attempting to write the file will have truncated its previ-
111 ous contents, so should the editor be aborted without cor-
112 rectly writing the file not only will the recent changes be
113 lost, but possibly much, or even all, of the data that pre-
116 There are several possible safe exits for a user caught
117 in this situation. He may use the editor !
\b! shell escape
118 command to examine his file space, and remove surplus files.
119 Alternatively, using _
\bc_
\bs_
\bh, he may suspend the editor, remove
120 some files, then resume it. A third possibility, is to
121 write the file to some other filesystem (perhaps to a file
122 on /tmp) where the user's quota has not been exceeded. Then
123 after rectifying the quota situation, the file can be moved
124 back to the filesystem it belongs on.
136 Disc Quotas in a UNIX Environment SMM:4-3
139 2
\b2.
\b. A
\bAd
\bdm
\bmi
\bin
\bni
\bis
\bst
\bte
\ber
\bri
\bin
\bng
\bg t
\bth
\bhe
\be q
\bqu
\buo
\bot
\bta
\ba s
\bsy
\bys
\bst
\bte
\bem
\bm
141 To set up and establish the disc quota system, there
142 are several steps necessary to be performed by the system
145 First, the system must be configured to include the
146 disc quota sub-system. This is done by including the line:
150 in the system configuration file, then running _
\bc_
\bo_
\bn_
\bf_
\bi_
\bg(8)
151 followed by a system configuration*.
153 Second, a decision as to what filesystems need to have
154 quotas applied needs to be made. Usually, only filesystems
155 that house users' home directories, or other user files,
156 will need to be subjected to the quota system, though it may
157 also prove useful to also include /
\b/u
\bus
\bsr
\br. If possible, /
\b/t
\btm
\bmp
\bp
158 should usually be free of quotas.
160 Having decided on which filesystems quotas need to be
161 set upon, the administrator should then allocate the avail-
162 able space amongst the competing needs. How this should be
163 done is (way) beyond the scope of this document.
165 Then, the _
\be_
\bd_
\bq_
\bu_
\bo_
\bt_
\ba(8) command can be used to actually
166 set the limits desired upon each user. Where a number of
167 users are to be given the same quotas (a common occurrence)
168 the -
\b-p
\bp switch to edquota will allow this to be easily accom-
171 Once the quotas are set, ready to operate, the system
172 must be informed to enforce quotas on the desired filesys-
173 tems. This is accomplished with the _
\bq_
\bu_
\bo_
\bt_
\ba_
\bo_
\bn(8) command.
174 _
\bQ_
\bu_
\bo_
\bt_
\ba_
\bo_
\bn will either enable quotas for a particular filesys-
175 tem, or with the -
\b-a
\ba switch, will enable quotas for each
176 filesystem indicated in /
\b/e
\bet
\btc
\bc/
\b/f
\bfs
\bst
\bta
\bab
\bb as using quotas. See
177 _
\bf_
\bs_
\bt_
\ba_
\bb(5) for details. Most sites using the quota system,
178 will include the line
182 in /
\b/e
\bet
\btc
\bc/
\b/r
\brc
\bc.
\b.l
\blo
\boc
\bca
\bal
\bl.
184 Should quotas need to be disabled, the _
\bq_
\bu_
\bo_
\bt_
\ba_
\bo_
\bf_
\bf(8) com-
185 mand will do that, however, should the filesystem be about
186 to be dismounted, the _
\bu_
\bm_
\bo_
\bu_
\bn_
\bt(8) command will disable quotas
187 immediately before the filesystem is unmounted. This is
188 actually an effect of the _
\bu_
\bm_
\bo_
\bu_
\bn_
\bt(2) system call, and it
189 guarantees that the quota system will not be disabled if the
191 * See also the document ``Building 4.2BSD UNIX
192 Systems with Config''.
202 SMM:4-4 Disc Quotas in a UNIX Environment
205 umount would fail because the filesystem is not idle.
207 Periodically (certainly after each reboot, and when
208 quotas are first enabled for a filesystem), the records
209 retained in the quota file should be checked for consistency
210 with the actual number of blocks and files allocated to the
211 user. The _
\bq_
\bu_
\bo_
\bt_
\ba_
\bc_
\bh_
\be_
\bc_
\bk(8) command can be used to accomplish
212 this. It is not necessary to dismount the filesystem, or
213 disable the quota system to run this command, though on
214 active filesystems inaccurate results may occur. This does
215 no real harm in most cases, another run of _
\bq_
\bu_
\bo_
\bt_
\ba_
\bc_
\bh_
\be_
\bc_
\bk when
216 the filesystem is idle will certainly correct any inaccu-
219 The super-user may use the _
\bq_
\bu_
\bo_
\bt_
\ba(1) command to examine
220 the usage and quotas of any user, and the _
\br_
\be_
\bp_
\bq_
\bu_
\bo_
\bt_
\ba(8) com-
221 mand may be used to check the usages and limits for all
222 users on a filesystem.
224 3
\b3.
\b. S
\bSo
\bom
\bme
\be i
\bim
\bmp
\bpl
\ble
\bem
\bme
\ben
\bnt
\bta
\bat
\bti
\bio
\bon
\bn d
\bde
\bet
\bta
\bai
\bil
\bl.
\b.
226 Disc quota usage and information is stored in a file on
227 the filesystem that the quotas are to be applied to. Con-
228 ventionally, this file is q
\bqu
\buo
\bot
\bta
\bas
\bs in the root of the filesys-
229 tem. While this name is not known to the system in any way,
230 several of the user level utilities "know" it, and choosing
231 any other name would not be wise.
233 The data in the file comprises an array of structures,
234 indexed by uid, one structure for each user on the system
235 (whether the user has a quota on this filesystem or not).
236 If the uid space is sparse, then the file may have holes in
237 it, which would be lost by copying, so it is best to avoid
240 The system is informed of the existence of the quota
241 file by the _
\bs_
\be_
\bt_
\bq_
\bu_
\bo_
\bt_
\ba(2) system call. It then reads the
242 quota entries for each user currently active, then for any
243 files open owned by users who are not currently active.
244 Each subsequent open of a file on the filesystem, will be
245 accompanied by a pairing with its quota information. In
246 most cases this information will be retained in core, either
247 because the user who owns the file is running some process,
248 because other files are open owned by the same user, or
249 because some file (perhaps this one) was recently accessed.
250 In memory, the quota information is kept hashed by user-id
251 and filesystem, and retained in an LRU chain so recently
252 released data can be easily reclaimed. Information about
253 those users whose last process has recently terminated is
254 also retained in this way.
256 Each time a block is accessed or released, and each
257 time an inode is allocated or freed, the quota system gets
258 told about it, and in the case of allocations, gets the
268 Disc Quotas in a UNIX Environment SMM:4-5
271 opportunity to object.
273 Measurements have shown that the quota code uses a very
274 small percentage of the system cpu time consumed in writing
277 4
\b4.
\b. A
\bAc
\bck
\bkn
\bno
\bow
\bwl
\ble
\bed
\bdg
\bgm
\bme
\ben
\bnt
\bts
\bs
279 The current disc quota system is loosely based upon a
280 very early scheme implemented at the University of New South
281 Wales, and Sydney University in the mid 70's. That system
282 implemented a single combined limit for both files and
283 blocks on all filesystems.
285 A later system was implemented at the University of
286 Melbourne by the author, but was not kept highly accurately,
287 eg: chown's (etc) did not affect quotas, nor did i/o to a
288 file other than one owned by the instigator.
290 The current system has been running (with only minor
291 modifications) since January 82 at Melbourne. It is actu-
292 ally just a small part of a much broader resource control
293 scheme, which is capable of controlling almost anything that
294 is usually uncontrolled in unix. The rest of this is, as
295 yet, still in a state where it is far too subject to change
296 to be considered for distribution.
298 For the 4.2BSD release, much work has been done to
299 clean up and sanely incorporate the quota code by Sam Lef-
300 fler and Kirk McKusick at The University of California at