Optimizing Storage in Anaconda: The Hard-Link Package Architecture
Learn how Anaconda uses hard-links and a central package cache to prevent disk space duplication across multiple environments, and how to verify this behavior using inode checks.
03 Oct 2026, 18:53 UTC

The Storage Redundancy Problem
Data science environments often require large binaries—such as PyTorch, TensorFlow, or NumPy—that can consume gigabytes of space. Creating five different project environments with the same version of these libraries would normally quintuple the disk space required, leading to rapid storage exhaustion and slow environment setup times.
The takeaway: Anaconda solves this by using a central package cache and hard-links. Instead of copying files, Anaconda creates a pointer to a single physical copy of the package on the disk, allowing multiple environments to share the same data without duplicating it.
The Minimalist Design
The architecture relies on two primary directory structures: the Package Cache (pkgs) and the Environment Prefix (the specific folder for a project).
The Package Cache (Read-Only Boundary)
When you run conda install, the package is first downloaded and extracted into the central cache. This directory serves as the single source of truth. In a healthy setup, this area is treated as read-only by the user to prevent corruption of shared dependencies.
The Environment Prefix (Mutable Boundary)
The environment prefix is the directory where your specific project lives. Rather than containing the actual binaries, it contains hard-links to the files in the cache. A hard-link is a filesystem entry that associates a filename with a specific inode (the physical location on the disk). Because both the cache and the environment point to the same inode, the file exists only once physically but appears in both folders.
Operational Requirements and Constraints
For this architecture to function, specific filesystem conditions must be met. If these conditions are not satisfied, Anaconda falls back to copying files, which increases disk usage and installation time.
| Requirement | Technical Reason | Failure Result |
|---|---|---|
| Same Partition/Mount | Hard-links cannot cross filesystem boundaries. | Fallback to full file copy. |
| Inode Support | The filesystem must support multiple directory entries for one inode. | Fallback to full file copy. |
| Write Permissions | The user must have permission to write to both the cache and the prefix. | Installation failure. |
Verification and Diagnostics
To verify if your environments are sharing physical space or duplicating data, you can check the inode numbers of a specific library file across two different environments.
Unix-based Systems (Linux/macOS)
Run the following command in your terminal. Replace the paths with the actual paths to a shared library (e.g., a .so file) in two different environments:
# Run as a standard user
ls -i /path/to/env1/lib/python3.x/site-packages/numpy/core/_multiarray_umath.cpython-xxx.so
ls -i /path/to/env2/lib/python3.x/site-packages/numpy/core/_multiarray_umath.cpython-xxx.soExpected Result: If the inode numbers (the first column of output) are identical, the environments are hard-linked and sharing disk space.
Windows Systems
Use the fsutil command in an Administrative Command Prompt:
# Run as Administrator
fsutil hardlink list C:\path\to\env1\Lib\site-packages\numpy\...Expected Result: The output will list all directory entries pointing to that specific file. If multiple paths appear, hard-linking is active.
Failure Modes and Risks
The "Shared Mutation" Risk
Because a hard-link is not a shortcut (symbolic link) but a direct reference to the data, modifying a file within an environment can inadvertently modify the source file in the package cache. This effectively "poisons" the package for every other environment that links to it.
Inode Exhaustion
On some older Linux filesystems (like ext3), there is a fixed number of available inodes. Creating thousands of small environments with many small files can exhaust the inode table even if the disk has plenty of GBs remaining, leading to "No space left on device" errors despite available capacity.
Design Pivot Points
The current hard-link design is optimal for single-disk workstations. However, the design must change in the following scenarios:
- Network File Systems (NFS): If the package cache is on a network drive and the environment is local, hard-linking is impossible. The system must switch to copying or symbolic linking.
- Containerization (Docker): In a container image, hard-links provide no benefit if the image is exported as a flat layer. In these cases, multi-stage builds are preferred over relying on the Conda cache.
- Read-Only Filesystems: If the environment prefix is on a read-only mount, the system cannot create the necessary links, requiring a relocation of the environment to a writable partition.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.