18
18
namespace NKikimr {
19
19
20
20
TSharedPageCacheCounters::TSharedPageCacheCounters (const TIntrusivePtr<::NMonitoring::TDynamicCounters> &group)
21
- : Counters(counters )
22
- , FreshBytes(counters ->GetCounter (" fresh" ))
23
- , StagingBytes(counters ->GetCounter (" staging" ))
24
- , WarmBytes(counters ->GetCounter (" warm" ))
21
+ : Counters(group )
22
+ , FreshBytes(group ->GetCounter (" fresh" ))
23
+ , StagingBytes(group ->GetCounter (" staging" ))
24
+ , WarmBytes(group ->GetCounter (" warm" ))
25
25
, MemLimitBytes(group->GetCounter (" MemLimitBytes" ))
26
26
, ConfigLimitBytes(group->GetCounter (" ConfigLimitBytes" ))
27
27
, ActivePages(group->GetCounter (" ActivePages" ))
@@ -482,7 +482,6 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> {
482
482
483
483
// 0 means unlimited
484
484
ui64 MemLimitBytes = 0 ;
485
- ui64 ConfigLimitBytes;
486
485
487
486
THolder<ICacheCache<TPage>> CreateCache () {
488
487
// TODO: pass actual limit to cache config
@@ -502,24 +501,22 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> {
502
501
}
503
502
504
503
void ActualizeCacheSizeLimit () {
505
- if ((ui64)SizeOverride != Config->CacheConfig -> Limit ) {
506
- Config->CacheConfig -> SetLimit ( SizeOverride) ;
504
+ if ((ui64)SizeOverride != Config->LimitBytes ) {
505
+ Config->LimitBytes = SizeOverride;
507
506
}
508
507
509
- ConfigLimitBytes = Config->CacheConfig ->Limit ;
510
-
511
- ui64 limit = ConfigLimitBytes;
512
- if (MemLimitBytes && ConfigLimitBytes > MemLimitBytes) {
508
+ ui64 limit = Config->LimitBytes ;
509
+ if (MemLimitBytes && Config->LimitBytes > MemLimitBytes) {
513
510
limit = MemLimitBytes;
514
511
}
515
512
516
513
// limit of cache depends only on config and mem because passive pages may go in and out arbitrary
517
514
// we may have some passive bytes, so if we fully fill this Cache we may exceed the limit
518
515
// because of that DoGC should be called to ensure limits
519
- Cache-> UpdateCacheSize (limit);
516
+ Cache. UpdateLimit (limit);
520
517
521
518
if (Config->Counters ) {
522
- Config->Counters ->ConfigLimitBytes ->Set (ConfigLimitBytes );
519
+ Config->Counters ->ConfigLimitBytes ->Set (Config-> LimitBytes );
523
520
Config->Counters ->ActiveLimitBytes ->Set (limit);
524
521
}
525
522
}
@@ -529,13 +526,13 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> {
529
526
// update StatActiveBytes + StatPassiveBytes
530
527
ProcessGCList ();
531
528
532
- ui64 configActiveReservedBytes = ConfigLimitBytes * Config->ActivePagesReservationPercent / 100 ;
529
+ ui64 configActiveReservedBytes = Config-> LimitBytes * Config->ActivePagesReservationPercent / 100 ;
533
530
534
531
THashSet<TCollection*> recheck;
535
532
while (MemLimitBytes && GetStatAllBytes () > MemLimitBytes
536
- || GetStatAllBytes () > ConfigLimitBytes && StatActiveBytes > configActiveReservedBytes) {
533
+ || GetStatAllBytes () > Config-> LimitBytes && StatActiveBytes > configActiveReservedBytes) {
537
534
TIntrusiveList<TPage> pages = Cache.EvictNext ();
538
- if (!page ) {
535
+ if (pages. Empty () ) {
539
536
break ;
540
537
}
541
538
while (!pages.Empty ()) {
@@ -575,12 +572,12 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> {
575
572
576
573
DoGC ();
577
574
578
- if (MemLimitBytes && MemLimitBytes < ConfigLimitBytes ) {
575
+ if (MemLimitBytes && MemLimitBytes < Config-> LimitBytes ) {
579
576
// in normal scenario we expect that we can fill the whole shared cache
580
- ui64 memTableReservedBytes = ConfigLimitBytes * Config->MemTableReservationPercent / 100 ;
577
+ ui64 memTableReservedBytes = Config-> LimitBytes * Config->MemTableReservationPercent / 100 ;
581
578
ui64 memTableTotal = MemTableTracker->GetTotalConsumption ();
582
579
if (memTableTotal > memTableReservedBytes) {
583
- ui64 toCompact = Min (ConfigLimitBytes - MemLimitBytes, memTableTotal - memTableReservedBytes);
580
+ ui64 toCompact = Min (Config-> LimitBytes - MemLimitBytes, memTableTotal - memTableReservedBytes);
584
581
auto registrations = MemTableTracker->SelectForCompaction (toCompact);
585
582
for (auto registration : registrations) {
586
583
Send (registration.first ->Owner , new NSharedCache::TEvMemTableCompact (registration.first ->Table , registration.second ));
@@ -1396,9 +1393,9 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> {
1396
1393
const auto * msg = ev->Get ();
1397
1394
1398
1395
if (msg->Record .GetMemoryLimit () != 0 ) {
1399
- Config->CacheConfig -> SetLimit ( msg->Record .GetMemoryLimit () );
1400
- SizeOverride = Config->CacheConfig -> Limit ;
1401
- // limit will be updated with ActualizeCacheSizeLimit call
1396
+ Config->LimitBytes = msg->Record .GetMemoryLimit ();
1397
+ SizeOverride = Config->LimitBytes ;
1398
+ ActualizeCacheSizeLimit ();
1402
1399
}
1403
1400
1404
1401
if (msg->Record .HasActivePagesReservationPercent ()) {
@@ -1491,9 +1488,8 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> {
1491
1488
: MemObserver(std::move(memObserver))
1492
1489
, MemTableTracker(std::make_shared<TSharedPageCacheMemTableTracker>(config->Counters))
1493
1490
, Config(std::move(config))
1494
- , SizeOverride(Config->CacheConfig->Limit, 1 , Max<i64>())
1495
- , ConfigLimitBytes(Config->CacheConfig->Limit)
1496
- , Cache(CreateCache())
1491
+ , Cache(1 , CreateCache(), Config->Counters->ReplacementPolicySize(Config->ReplacementPolicy))
1492
+ , SizeOverride(Config->LimitBytes, 1 , Max<i64>())
1497
1493
{
1498
1494
AsyncRequests.Limit = Config->TotalAsyncQueueInFlyLimit ;
1499
1495
ScanRequests.Limit = Config->TotalScanQueueInFlyLimit ;
0 commit comments