@@ -1170,6 +1170,8 @@ cplist_update()
11701170 cp->ramcache_enabled = config_vol->ramcache_enabled ;
11711171 cp->avg_obj_size = config_vol->avg_obj_size ;
11721172 cp->fragment_size = config_vol->fragment_size ;
1173+ cp->ram_cache_size = config_vol->ram_cache_size ;
1174+ cp->ram_cache_cutoff = config_vol->ram_cache_cutoff ;
11731175 config_vol->cachep = cp;
11741176 } else {
11751177 /* delete this volume from all the disks */
@@ -1442,22 +1444,54 @@ CacheProcessor::cacheInitialized()
14421444 }
14431445 }
14441446
1447+ // Calculate total private RAM allocations from per-volume configurations
14451448 int64_t http_ram_cache_size = 0 ;
1449+ int64_t total_private_ram = 0 ;
1450+
1451+ if (cache_config_ram_cache_size != AUTO_SIZE_RAM_CACHE) {
1452+ CacheVol *cp = cp_list.head ;
1453+
1454+ for (; cp; cp = cp->link .next ) {
1455+ if (cp->ram_cache_size > 0 ) {
1456+ total_private_ram += cp->ram_cache_size ;
1457+ Dbg (dbg_ctl_cache_init, " Volume %d has private RAM allocation: %" PRId64 " bytes (%" PRId64 " MB)" , cp->vol_number ,
1458+ cp->ram_cache_size , cp->ram_cache_size / (1024 * 1024 ));
1459+ }
1460+ }
1461+
1462+ if (total_private_ram > 0 ) {
1463+ Dbg (dbg_ctl_cache_init, " Total private RAM allocations: %" PRId64 " bytes (%" PRId64 " MB)" , total_private_ram,
1464+ total_private_ram / (1024 * 1024 ));
1465+ }
1466+ }
14461467
1447- // let us calculate the Size
14481468 if (cache_config_ram_cache_size == AUTO_SIZE_RAM_CACHE) {
14491469 Dbg (dbg_ctl_cache_init, " cache_config_ram_cache_size == AUTO_SIZE_RAM_CACHE" );
14501470 } else {
14511471 // we got configured memory size
14521472 // TODO, should we check the available system memories, or you will
14531473 // OOM or swapout, that is not a good situation for the server
14541474 Dbg (dbg_ctl_cache_init, " %" PRId64 " != AUTO_SIZE_RAM_CACHE" , cache_config_ram_cache_size);
1455- http_ram_cache_size =
1456- static_cast <int64_t >((static_cast <double >(theCache->cache_size ) / total_size) * cache_config_ram_cache_size);
1475+
1476+ // Calculate shared pool: global RAM cache size minus private allocations
1477+ int64_t shared_pool = cache_config_ram_cache_size - total_private_ram;
1478+
1479+ if (shared_pool < 0 ) {
1480+ Warning (" Total private RAM cache allocations (%" PRId64 " bytes) exceed global ram_cache.size (%" PRId64 " bytes). "
1481+ " Using global limit. Consider increasing proxy.config.cache.ram_cache.size." ,
1482+ total_private_ram, cache_config_ram_cache_size);
1483+ shared_pool = cache_config_ram_cache_size; // Fall back to using the global pool for all
1484+ total_private_ram = 0 ; // Disable private allocations
1485+ } else if (total_private_ram > 0 ) {
1486+ Dbg (dbg_ctl_cache_init, " Shared RAM cache pool (after private allocations): %" PRId64 " bytes (%" PRId64 " MB)" ,
1487+ shared_pool, shared_pool / (1024 * 1024 ));
1488+ }
1489+
1490+ http_ram_cache_size = static_cast <int64_t >((static_cast <double >(theCache->cache_size ) / total_size) * shared_pool);
14571491
14581492 Dbg (dbg_ctl_cache_init, " http_ram_cache_size = %" PRId64 " = %" PRId64 " Mb" , http_ram_cache_size,
14591493 http_ram_cache_size / (1024 * 1024 ));
1460- int64_t stream_ram_cache_size = cache_config_ram_cache_size - http_ram_cache_size;
1494+ int64_t stream_ram_cache_size = shared_pool - http_ram_cache_size;
14611495
14621496 Dbg (dbg_ctl_cache_init, " stream_ram_cache_size = %" PRId64 " = %" PRId64 " Mb" , stream_ram_cache_size,
14631497 stream_ram_cache_size / (1024 * 1024 ));
@@ -1470,22 +1504,49 @@ CacheProcessor::cacheInitialized()
14701504 uint64_t total_cache_bytes = 0 ; // bytes that can used in total_size
14711505 uint64_t total_direntries = 0 ; // all the direntries in the cache
14721506 uint64_t used_direntries = 0 ; // and used
1473- uint64_t total_ram_cache_bytes = 0 ;
1507+ uint64_t total_ram_cache_bytes = 0 ; // Total RAM cache size across all volumes
1508+ uint64_t shared_cache_size = 0 ; // Total cache size of volumes without explicit RAM allocations
1509+
1510+ // Calculate total cache size of volumes without explicit RAM allocations
1511+ if (http_ram_cache_size > 0 ) {
1512+ for (int i = 0 ; i < gnstripes; i++) {
1513+ if (gstripes[i]->cache_vol ->ram_cache_size <= 0 ) {
1514+ shared_cache_size += (gstripes[i]->len >> STORE_BLOCK_SHIFT);
1515+ }
1516+ }
1517+ Dbg (dbg_ctl_cache_init, " Shared cache size (for RAM pool distribution): %" PRId64 " blocks" , shared_cache_size);
1518+ }
14741519
14751520 for (int i = 0 ; i < gnstripes; i++) {
14761521 StripeSM *stripe = gstripes[i];
14771522 int64_t ram_cache_bytes = 0 ;
14781523
1479- if (stripe->cache_vol ->ramcache_enabled ) {
1480- if (http_ram_cache_size == 0 ) {
1524+ // If RAM cache enabled, check if this volume has a private RAM cache allocation
1525+ if (stripe->cache_vol ->ramcache_enabled && stripe->cache_vol ->ram_cache_size != 0 ) {
1526+ if (stripe->cache_vol ->ram_cache_size > 0 ) {
1527+ int64_t volume_stripe_count = 0 ;
1528+
1529+ for (int j = 0 ; j < gnstripes; j++) {
1530+ if (gstripes[j]->cache_vol == stripe->cache_vol ) {
1531+ volume_stripe_count++;
1532+ }
1533+ }
1534+
1535+ if (volume_stripe_count > 0 ) {
1536+ ram_cache_bytes = stripe->cache_vol ->ram_cache_size / volume_stripe_count;
1537+ Dbg (dbg_ctl_cache_init, " Volume %d stripe %d using private RAM allocation: %" PRId64 " bytes (%" PRId64 " MB)" ,
1538+ stripe->cache_vol ->vol_number , i, ram_cache_bytes, ram_cache_bytes / (1024 * 1024 ));
1539+ }
1540+ } else if (http_ram_cache_size == 0 ) {
14811541 // AUTO_SIZE_RAM_CACHE
14821542 ram_cache_bytes = stripe->dirlen () * DEFAULT_RAM_CACHE_MULTIPLIER;
14831543 } else {
1544+ // Use shared pool allocation - distribute only among volumes without explicit allocations
14841545 ink_assert (stripe->cache != nullptr );
1546+ int64_t divisor = (shared_cache_size > 0 ) ? shared_cache_size : theCache->cache_size ;
1547+ double factor = static_cast <double >(static_cast <int64_t >(stripe->len >> STORE_BLOCK_SHIFT)) / divisor;
14851548
1486- double factor = static_cast <double >(static_cast <int64_t >(stripe->len >> STORE_BLOCK_SHIFT)) / theCache->cache_size ;
1487- Dbg (dbg_ctl_cache_init, " factor = %f" , factor);
1488-
1549+ Dbg (dbg_ctl_cache_init, " factor = %f (divisor = %" PRId64 " )" , factor, divisor);
14891550 ram_cache_bytes = static_cast <int64_t >(http_ram_cache_size * factor);
14901551 }
14911552
@@ -1497,19 +1558,19 @@ CacheProcessor::cacheInitialized()
14971558 ram_cache_bytes, ram_cache_bytes / (1024 * 1024 ));
14981559 }
14991560
1500- uint64_t vol_total_cache_bytes = stripe->len - stripe->dirlen ();
1501- total_cache_bytes += vol_total_cache_bytes;
1561+ uint64_t vol_total_cache_bytes = stripe->len - stripe->dirlen ();
1562+ uint64_t vol_total_direntries = stripe->directory .entries ();
1563+ uint64_t vol_used_direntries = stripe->directory .entries_used ();
1564+
1565+ total_cache_bytes += vol_total_cache_bytes;
15021566 ts::Metrics::Gauge::increment (stripe->cache_vol ->vol_rsb .bytes_total , vol_total_cache_bytes);
15031567 ts::Metrics::Gauge::increment (stripe->cache_vol ->vol_rsb .stripes );
15041568
15051569 Dbg (dbg_ctl_cache_init, " total_cache_bytes = %" PRId64 " = %" PRId64 " Mb" , total_cache_bytes,
15061570 total_cache_bytes / (1024 * 1024 ));
15071571
1508- uint64_t vol_total_direntries = stripe->directory .entries ();
1509- total_direntries += vol_total_direntries;
1572+ total_direntries += vol_total_direntries;
15101573 ts::Metrics::Gauge::increment (stripe->cache_vol ->vol_rsb .direntries_total , vol_total_direntries);
1511-
1512- uint64_t vol_used_direntries = stripe->directory .entries_used ();
15131574 ts::Metrics::Gauge::increment (stripe->cache_vol ->vol_rsb .direntries_used , vol_used_direntries);
15141575 used_direntries += vol_used_direntries;
15151576 }
0 commit comments