@@ -630,9 +630,6 @@ ZPartition::ZPartition(uint32_t numa_id, ZPageAllocator* page_allocator)
630
630
_capacity(0 ),
631
631
_claimed(0 ),
632
632
_used(0 ),
633
- _last_commit(0.0 ),
634
- _last_uncommit(0.0 ),
635
- _to_uncommit(0 ),
636
633
_numa_id(numa_id) {}
637
634
638
635
uint32_t ZPartition::numa_id () const {
@@ -650,9 +647,7 @@ size_t ZPartition::increase_capacity(size_t size) {
650
647
// Update atomically since we have concurrent readers
651
648
Atomic::add (&_capacity, increased);
652
649
653
- _last_commit = os::elapsedTime ();
654
- _last_uncommit = 0 ;
655
- _cache.reset_min ();
650
+ _uncommitter.cancel_uncommit_cycle ();
656
651
}
657
652
658
653
return increased;
@@ -787,101 +782,6 @@ bool ZPartition::claim_capacity_fast_medium(ZMemoryAllocation* allocation) {
787
782
return true ;
788
783
}
789
784
790
- size_t ZPartition::uncommit (uint64_t * timeout) {
791
- ZArray<ZVirtualMemory> flushed_vmems;
792
- size_t flushed = 0 ;
793
-
794
- {
795
- // We need to join the suspendible thread set while manipulating capacity
796
- // and used, to make sure GC safepoints will have a consistent view.
797
- SuspendibleThreadSetJoiner sts_joiner;
798
- ZLocker<ZLock> locker (&_page_allocator->_lock );
799
-
800
- const double now = os::elapsedTime ();
801
- const double time_since_last_commit = std::floor (now - _last_commit);
802
- const double time_since_last_uncommit = std::floor (now - _last_uncommit);
803
-
804
- if (time_since_last_commit < double (ZUncommitDelay)) {
805
- // We have committed within the delay, stop uncommitting.
806
- *timeout = uint64_t (double (ZUncommitDelay) - time_since_last_commit);
807
- return 0 ;
808
- }
809
-
810
- // We flush out and uncommit chunks at a time (~0.8% of the max capacity,
811
- // but at least one granule and at most 256M), in case demand for memory
812
- // increases while we are uncommitting.
813
- const size_t limit_upper_bound = MAX2 (ZGranuleSize, align_down (256 * M / ZNUMA::count (), ZGranuleSize));
814
- const size_t limit = MIN2 (align_up (_current_max_capacity >> 7 , ZGranuleSize), limit_upper_bound);
815
-
816
- if (limit == 0 ) {
817
- // This may occur if the current max capacity for this partition is 0
818
-
819
- // Set timeout to ZUncommitDelay
820
- *timeout = ZUncommitDelay;
821
- return 0 ;
822
- }
823
-
824
- if (time_since_last_uncommit < double (ZUncommitDelay)) {
825
- // We are in the uncommit phase
826
- const size_t num_uncommits_left = _to_uncommit / limit;
827
- const double time_left = double (ZUncommitDelay) - time_since_last_uncommit;
828
- if (time_left < *timeout * num_uncommits_left) {
829
- // Running out of time, speed up.
830
- uint64_t new_timeout = uint64_t (std::floor (time_left / double (num_uncommits_left + 1 )));
831
- *timeout = new_timeout;
832
- }
833
- } else {
834
- // We are about to start uncommitting
835
- _to_uncommit = _cache.reset_min ();
836
- _last_uncommit = now;
837
-
838
- const size_t split = _to_uncommit / limit + 1 ;
839
- uint64_t new_timeout = ZUncommitDelay / split;
840
- *timeout = new_timeout;
841
- }
842
-
843
- // Never uncommit below min capacity.
844
- const size_t retain = MAX2 (_used, _min_capacity);
845
- const size_t release = _capacity - retain;
846
- const size_t flush = MIN3 (release, limit, _to_uncommit);
847
-
848
- if (flush == 0 ) {
849
- // Nothing to flush
850
- return 0 ;
851
- }
852
-
853
- // Flush memory from the mapped cache to uncommit
854
- flushed = _cache.remove_from_min (flush, &flushed_vmems);
855
- if (flushed == 0 ) {
856
- // Nothing flushed
857
- return 0 ;
858
- }
859
-
860
- // Record flushed memory as claimed and how much we've flushed for this partition
861
- Atomic::add (&_claimed, flushed);
862
- _to_uncommit -= flushed;
863
- }
864
-
865
- // Unmap and uncommit flushed memory
866
- for (const ZVirtualMemory vmem : flushed_vmems) {
867
- unmap_virtual (vmem);
868
- uncommit_physical (vmem);
869
- free_physical (vmem);
870
- free_virtual (vmem);
871
- }
872
-
873
- {
874
- SuspendibleThreadSetJoiner sts_joiner;
875
- ZLocker<ZLock> locker (&_page_allocator->_lock );
876
-
877
- // Adjust claimed and capacity to reflect the uncommit
878
- Atomic::sub (&_claimed, flushed);
879
- decrease_capacity (flushed, false /* set_max_capacity */ );
880
- }
881
-
882
- return flushed;
883
- }
884
-
885
785
void ZPartition::sort_segments_physical (const ZVirtualMemory& vmem) {
886
786
verify_virtual_memory_association (vmem, true /* check_multi_partition */ );
887
787
0 commit comments