Your Search Bar For Shrewd Tips

How Do I Clear Zfs Cache?


If you’re wondering how to clear the ZFS cache, first identify which cache you mean. ZFS uses several kinds of caching, and the right action depends on whether you want to free memory, troubleshoot a performance issue, or remove a cache device. Clearing cache does not delete files or repair a pool, and it is rarely necessary during normal operation.

For most users, “ZFS cache” means the ARC, the memory-based cache that stores frequently used data and metadata. This guide explains how to check ARC usage, request memory reclamation, restart ZFS by rebooting, and handle the separate L2ARC cache safely.

What Does the ZFS Cache Do?

ZFS uses the Adaptive Replacement Cache, or ARC, to keep recently and frequently accessed data in RAM. It also caches metadata, such as directory and file information. When an application asks for data already in the ARC, ZFS can serve it from memory instead of reading it from a disk or SSD. This can make repeated reads much faster.

ARC usage can look high even when the system is healthy. ZFS generally uses available memory for caching and can give memory back when applications or the operating system need it. A large ARC is not automatically a memory leak, and reducing it may make later reads slower while the cache warms up again.

Some pools also use an L2ARC, a secondary cache on an SSD or other device. It can hold cached data that does not fit in the ARC. The ZFS Intent Log (ZIL) and a separate log device (SLOG) are different mechanisms: they support synchronous writes and should not be treated as ordinary read caches.

Check ARC Usage Before Clearing It

Before taking action, check whether ARC usage is actually causing a problem. On many OpenZFS systems, the arc_summary command displays ARC size, cache hits, cache misses, and other useful statistics:

arc_summary

On Linux, you can also inspect the ARC statistics file directly:

cat /proc/spl/kstat/zfs/arcstats

Look at values such as the current ARC size and the configured ARC maximum. The exact tools and statistic names vary by OpenZFS release and operating system. You can also check overall memory and pool status using your system’s usual monitoring tools and zpool status.

If the system is responsive and applications have enough memory, there may be no reason to clear anything. If memory pressure is affecting applications, consider adjusting the ARC limit rather than repeatedly flushing the cache.

How to Clear the ZFS ARC Cache

There is no single, portable command that instantly and completely empties the ARC on every ZFS platform. The most reliable general-purpose way to reset the in-memory ARC is to reboot the system. This interrupts services and workloads, however, so schedule a restart and confirm that applications and storage are ready before doing it.

On Linux, you can often encourage ARC to shrink by temporarily lowering its maximum size. The parameter is commonly available here:

/sys/module/zfs/parameters/zfs_arc_max

First read and record the existing value. Then, as root, set a lower limit appropriate for the machine. For example, this sets a temporary maximum of 2 GiB:

echo 2147483648 > /sys/module/zfs/parameters/zfs_arc_max

The value is in bytes. Choose a limit based on total RAM and the needs of your applications; 2 GiB is only an example, not a universal recommendation. ZFS may take time to reclaim memory, and lowering the limit is not the same as instantly emptying every cached entry. After testing, restore the value you recorded, or configure an appropriate persistent setting using the method supported by your Linux distribution.

On FreeBSD, the corresponding ARC limit is commonly managed with the vfs.zfs.arc_max sysctl. You can inspect it with sysctl vfs.zfs.arc_max and adjust it with a suitable value for your system. Consult your FreeBSD and OpenZFS documentation before making the setting persistent, because configuration methods and supported tunables can differ by version.

Do not copy a memory limit from another server without checking its workload. Setting the ARC maximum too low can reduce performance, while changing system parameters incorrectly can cause operational issues. If you only need to test whether cached reads are influencing a benchmark, use a controlled test plan and record the original settings.

Does Linux Drop Caches Clear ZFS ARC?

Linux administrators sometimes run echo 3 > /proc/sys/vm/drop_caches to ask the kernel to release certain filesystem caches, including page cache and reclaimable directory and inode entries. This is not a dependable command for completely clearing the ZFS ARC. ZFS manages its own cache, and behavior can vary with kernel and OpenZFS versions.

Do not use this command as a routine ZFS maintenance step or assume that it has reset ARC statistics. It can also make subsequent file access slower by discarding useful operating-system caches. If you are trying to reduce ZFS memory use, check the ZFS-specific ARC controls and your platform documentation instead.

How to Handle the L2ARC Cache

The L2ARC is a cache device assigned to a pool. It is optional and does not store the only copy of pool data. If you are troubleshooting ordinary ARC memory use, removing an L2ARC device is usually not the answer: L2ARC is on a separate device, and removing it will not directly clear the RAM used by the ARC.

If your goal is to remove an L2ARC device from a pool, first confirm its role with:

zpool status

Only proceed if you have identified the device as a cache device and intend to remove it. Depending on your OpenZFS version and pool configuration, a cache device can generally be removed with a command in this form:

zpool remove poolname cache-device

Replace the example names with the actual pool and device names. Verify the command syntax for your OpenZFS version, review the pool status before and after, and never guess which device to remove. Removing an L2ARC device should not delete the pool’s primary data, but it can reduce read performance until the cache is rebuilt or the workload is served from other storage.

L2ARC behavior across restarts depends on the OpenZFS version and configuration. A reboot resets the in-memory ARC, but it may not mean that every L2ARC cache entry is discarded. If you specifically need to remove a cache device or change its contents, follow the supported pool-management procedure rather than relying on a reboot.

Do Not Confuse Cache Clearing with Pool Recovery

The command zpool clear is not a command for emptying the ARC. It is used to clear recorded device errors on a pool or device after the underlying issue has been addressed. It does not flush cached file data. Likewise, clearing ARC is not a way to repair corruption, resolve a failing disk, or fix a damaged pool.

If zpool status reports errors, investigate the specific device, cabling, controller, or underlying storage problem. Follow the appropriate recovery steps for your system, and ensure you have a current backup before making changes. Do not remove or replace pool devices simply to “clear the cache.”

The ZIL and SLOG also should not be manually flushed as if they were disposable caches. They are involved in preserving the semantics of synchronous writes. ZFS manages their operation; use the documented procedures for your platform if you are changing a log device.

When Should You Clear or Limit ZFS Cache?

Clearing or limiting ARC can make sense in a few situations: you are testing performance under controlled conditions, an application has a documented memory requirement, or the host is under genuine memory pressure and you need to reserve RAM for other services. Even then, setting an appropriate ARC maximum is usually more useful than repeatedly emptying the cache.

It is usually unnecessary to clear ARC after creating or deleting files, after a routine pool scrub, or because a memory monitor shows that ZFS is using available RAM. Cached data is not a second copy that needs periodic cleanup. ZFS will manage cache contents as its workload and available memory change.

  • Check ARC statistics and overall system memory before changing settings.
  • Use a temporary, measured ARC limit if you need to test memory behavior.
  • Reboot only when a full in-memory reset is needed and downtime is acceptable.
  • Manage an L2ARC device separately from the ARC.
  • Use backups and documented recovery steps for pool or device errors.

Conclusion

To clear the ZFS cache, first determine whether you mean the RAM-based ARC or a separate L2ARC device. A planned reboot is the most straightforward way to reset the in-memory ARC, while temporarily lowering the ARC maximum can encourage it to release memory on supported systems. Neither action is normally needed for a healthy pool, and Linux’s general cache-dropping command is not a reliable way to empty the ZFS ARC.

Check ARC statistics, make changes only for a clear reason, and distinguish cache management from pool recovery. ZFS uses cache to improve performance, and allowing it to manage that memory is usually the best choice.


Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.

Shrewdnia

Shrewdnia

Shrewdnia is a destination for curious minds seeking clarity, knowledge, and informed perspectives. Through insightful articles and practical guides our passionate team explores a wide range of topics designed to help readers understand the world around them, make smarter decisions, and stay informed in an ever-changing landscape.


💡 Every question sparks discovery, and every perspective enriches the conversation. Share your thoughts and insights in the comments 👇

Back to blog

Leave a comment

JOIN THE SHREWDNIA COMMUNITY FORUM

What do you think?

Have an opinion, experience, or question about this topic? Join the Shrewdnia Forum and share your thoughts with other readers.

Join the Forum →