Retries after failed transcoding jobs and repeated writes from data collection programs can cause temporary workspaces to grow continuously. Checking free space only before a job starts does not prevent it from filling the data disk while running. User quotas also cannot easily account for individual projects when several run under the same account. ext4 project quotas track space and inode usage by project ID, making them suitable for setting independent limits on batch-processing directories.
The two 1TB NVMe drives in UdpAmd dedicated servers are directly attached, with no hardware RAID. Quotas bound workspace growth; they do not provide disk redundancy or backups. The following lab uses a newly created disk image on Ubuntu 24.04 and does not format any real disk.
1. Define what to limit and the scope of the lab
Project quotas are not directory-size scanners. They are filesystem accounting for inodes that share a project ID. Block limits constrain allocated space, while inode limits constrain the number of filesystem objects. A large number of empty files can hit the latter even when they consume almost no data space.
This example assigns project 1001 a hard capacity limit of 64MiB and a hard limit of 32 inodes. These numbers are for demonstration only, not production recommendations. The directory itself also consumes an inode, so the limit does not mean that exactly 32 regular files can be created.
A quota is not a security sandbox. Processes with administrative privileges can change the limits. If the same account can write to directories outside the project, it can also bypass the workspace's capacity limit. Production jobs should run under unprivileged accounts, with other writable paths restricted.
You need sudo privileges, about 2GiB of free space, and the quota, e2fsprogs, and python3 packages. Run the following commands in order within the same Bash session, retaining the WORK and MNT variables.
2. Create an isolated ext4 lab filesystem
First, create a dedicated directory and disk image. truncate creates a sparse file: its logical size does not mean that an equal amount of physical space has been reserved. Check the free space on the filesystem containing the directory before starting the lab.
sudo apt-get update
sudo apt-get install quota e2fsprogs python3
df -h /var/tmp
WORK=$(mktemp -d /var/tmp/ext4-quota.XXXXXX)
MNT="$WORK/mnt"
chmod 755 "$WORK"
mkdir "$MNT"
truncate -s 2G "$WORK/disk.img"
mkfs.ext4 -F -O project,quota "$WORK/disk.img"
tune2fs -Q prjquota "$WORK/disk.img"
sudo mount -o loop,prjquota "$WORK/disk.img" "$MNT"
findmnt -no SOURCE,FSTYPE,OPTIONS --target "$MNT"
sudo quotaon -P -p "$MNT"
Verify that the filesystem type is ext4, the mount options include prjquota, and project quotas are enabled. If a tool does not recognize an option, the kernel does not support project quotas, or the mount fails, stop the lab. Do not proceed to create the test directory, and never substitute a real disk device for the image path to try again.
This setup uses internal filesystem quotas, so there is no need to create an aquota.project file manually. If the relevant features are not yet enabled on a production disk, do not copy this lab procedure to modify it online. First check its current state, independent backups, and recovery procedures.
3. Assign a project ID and verify inheritance
Create an empty workspace, assign its project ID, enable project inheritance, and then hand ownership to an unprivileged account. nobody is used only for this isolated lab; use a dedicated job account in production.
sudo mkdir "$MNT/job-a"
sudo chattr -p 1001 "$MNT/job-a"
sudo chattr +P "$MNT/job-a"
sudo chown nobody:nogroup "$MNT/job-a"
sudo setquota -P 1001 0 65536 0 32 "$MNT"
sudo lsattr -pd "$MNT/job-a"
sudo -u nobody touch "$MNT/job-a/probe"
sudo lsattr -p "$MNT/job-a/probe"
sudo repquota -P "$MNT"
sudo rm "$MNT/job-a/probe"
The four numbers passed to setquota are, in order, the block soft limit, block hard limit, inode soft limit, and inode hard limit. Block limits are entered in KiB, so 65536 corresponds to 64MiB. Setting the soft limits to zero means this example does not use a grace period and tests the hard limits directly.
Check that the directory has the P attribute and that both the directory and the new file have project ID 1001. A quota record alone is not enough: files without the correct project assignment will not be counted toward the intended project.
An inheritance flag alone is not enough for an existing directory
+P affects newly created objects; it does not automatically reclassify an entire existing directory tree. Existing files' project IDs, hard links, and moves between directories require a separate audit. A safer migration is to stop writes, copy the data into a new directory with inheritance already enabled, verify project assignments and usage, and then switch the job's working path. Simply renaming the old directory does not complete the migration.
4. Trigger the capacity and file-count limits separately
First, write more data than the capacity limit allows as an unprivileged user. Do not use truncate for this test: a sparse file can have a large logical size without allocating enough data blocks.
sudo -u nobody dd if=/dev/zero of="$MNT/job-a/payload" \
bs=1M count=80 conv=fsync status=none
rc=$?
printf 'write_exit=%s\n' "$rc"
sudo repquota -P "$MNT"
sudo rm "$MNT/job-a/payload"
The write should fail with a nonzero exit code and a quota-related error. ext4 may preallocate space, so do not expect the failure to occur at an exact byte boundary. The partial file left after the failure still consumes quota. Handle it according to your application's rules before retrying, rather than generating new filenames indefinitely.
Next, create empty files to test the inode limit separately:
sudo -u nobody python3 - "$MNT/job-a" <<'PY'
import errno
import pathlib
import sys
root = pathlib.Path(sys.argv[1])
for index in range(100):
try:
(root / f"empty-{index:03d}").touch(exist_ok=False)
except OSError as exc:
print(f"created={index} errno={exc.errno}")
if exc.errno != errno.EDQUOT:
raise
break
else:
raise SystemExit("Expected quota rejection")
PY
sudo repquota -P "$MNT"
The script should catch EDQUOT before creating all the files. If it receives ENOSPC, also check whether either the filesystem hosting the image or the lab filesystem has run out of space or inodes. Not every write failure is caused by a project quota. Applications should also log the error type so that insufficient capacity is not mistaken for a network failure and retried repeatedly.
5. Clean up and verify production readiness
After deleting the empty files created in this lab, use repquota -P to confirm that usage has dropped. The directory still consumes an inode, so the reported usage may not return to zero. Compare usage before and after cleanup rather than looking only for a zero value.
sudo find "$MNT/job-a" -maxdepth 1 -type f \
-name 'empty-*' -delete
sudo repquota -P "$MNT"
sudo umount "$MNT" &&
rmdir "$MNT" &&
rm "$WORK/disk.img" &&
rmdir "$WORK"
If unmounting fails, keep the image and identify the processes still using the mount point. Do not forcibly delete the files. Production acceptance checks should also include the following:
- Confirm that mount options and project quota status remain consistent after a reboot, and check the workspace before starting a job.
- Use a separate ID for each project, and record its directory, responsible account, limits, and cleanup rules.
- Monitor block usage, inode usage, and free space across the entire filesystem. Do not let the sum of project limits obscure a shortage of physical capacity.
- Treat quota rejection as part of job failure handling, preserve inputs and diagnostic information, and prohibit unbounded retries.
- Include outputs, caches, and failure leftovers outside the workspace in the audit of writable paths.
Successful command execution is not the final acceptance criterion. New files must belong to the correct project, writes that exceed either limit must be rejected, cleanup must release quota, and the application must clearly report why it failed. Only when this entire chain works does a workspace quota become an effective boundary for batch processing.
Frequently asked questions
How do project quotas differ from user quotas?
Project quotas account for inodes carrying a particular project ID. One user can therefore own several workspaces with separate limits. Directory inheritance assigns the ID to new files; existing files are not automatically reclassified.
Why does a write fail when the filesystem still has free space?
The project may have reached its block or inode hard limit independently of overall free space. Inspect both counters with repquota -P rather than relying on df alone.
Can these lab commands be run against the system disk?
No. The example formats only a newly created image file. Enabling filesystem features or changing production mount options requires a separate backup and a validated recovery procedure.
EPYC 7543P Dedicated Server
From $458/month, billed in USD.