# Cache calculating erroneous size

**URL:** <https://www.ruby-forum.com/t/cache-calculating-erroneous-size/244908>\
**Category:** NGINX\
**Created:** [July 5, 2016, 9:44pm UTC](https://www.ruby-forum.com/t/cache-calculating-erroneous-size/244908 "2016-07-05T21:44:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [July 5, 2016, 9:44pm UTC](https://www.ruby-forum.com/t/cache-calculating-erroneous-size/244908/1 "2016-07-05T21:44:33Z")

</div>

Hello,

I’ve been experiencing a rather strange situation regarding the cache  
size  
occupation (calculated by nginx’s cache manager and reported in debug  
logs)  
versus the real occupied size as reported by `df`. Just exemplifying:

- reported by cache manager: 76009.340M disk space used, 19458391 disk  
blocks (4K) used, 2583292 unique files in cache.
- reported by df: 64203.512M of disk space used, 16436099 disk blocks  
(4K)  
used, 2583861 unique files in cache (this number is an approximation,  
due  
to find command taking more time to return).

So, in resume, Nginx is counting files correctly, but not their  
sizes/blocks used (it is my understanding that it count blocks, not  
bytes).

As a consequence, when the calculated cache size reaches the max\_size  
defined in proxy\_cache\_path, forced evictions start occurring. I must  
point  
out that these evictions are due to max\_size reached and not inactive  
time  
(I differentiate both of these cases in debug log messages) or file  
count  
watermark (related to keyzone capacity) being reached.

Here’s the configuration of my proxy cache:

proxy\_cache\_path /xfs/http levels=1:2 keys\_zone=smallfiles:800m

> max\_size=100g inactive=90d;

proxy\_temp\_path /tmp;

> 

First I thought this could be related to allocsize in XFS (  
[#157 (cache max\_size limit applied incorrectly with xfs) – nginx](https://trac.nginx.org/nginx/ticket/157)), but the problem persists even  
when utilizing 4K instead of the default (64K).

Also I must point out that there’s another cache zone being utilized  
(also  
with XFS but in another disk) by the same nginx servers, though it is  
utilized for caching larger files (more than 1Mb in size in average),  
and  
it does not suffer from this cache size discrepancy.

Restarting Nginx (or upgrading it) solves temporarily the problem, as  
the  
cache loader correctly calculates the total cache size.

Thanks,
