[Git][ghc/ghc][master] Add fragmentation statistic to GHC.Stats

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Wed Sep 21 18:30:55 UTC 2022



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
c0ba775d by Teo Camarasu at 2022-09-21T14:30:37-04:00
Add fragmentation statistic to GHC.Stats

Implements #21537

- - - - -


4 changed files:

- libraries/base/GHC/Stats.hsc
- libraries/base/changelog.md
- rts/Stats.c
- rts/include/RtsAPI.h


Changes:

=====================================
libraries/base/GHC/Stats.hsc
=====================================
@@ -159,6 +159,11 @@ data GCDetails = GCDetails {
   , gcdetails_par_max_copied_bytes :: Word64
     -- | In parallel GC, the amount of balanced data copied by all threads
   , gcdetails_par_balanced_copied_bytes :: Word64
+    -- | The amount of memory lost due to block fragmentation in bytes.
+    -- Block fragmentation is the difference between the amount of blocks retained by the RTS and the blocks that are in use.
+    -- This occurs when megablocks are only sparsely used, eg, when data that cannot be moved retains a megablock.
+    -- @since 4.17.0.0
+  , gcdetails_block_fragmentation_bytes :: Word64
     -- | The time elapsed during synchronisation before GC
   , gcdetails_sync_elapsed_ns :: RtsTime
     -- | The CPU time used during GC itself
@@ -241,6 +246,8 @@ getRTSStats = do
         (# peek GCDetails, par_max_copied_bytes) pgc
       gcdetails_par_balanced_copied_bytes <-
         (# peek GCDetails, par_balanced_copied_bytes) pgc
+      gcdetails_block_fragmentation_bytes <-
+        (# peek GCDetails, block_fragmentation_bytes) pgc
       gcdetails_sync_elapsed_ns <- (# peek GCDetails, sync_elapsed_ns) pgc
       gcdetails_cpu_ns <- (# peek GCDetails, cpu_ns) pgc
       gcdetails_elapsed_ns <- (# peek GCDetails, elapsed_ns) pgc


=====================================
libraries/base/changelog.md
=====================================
@@ -36,6 +36,7 @@
     #10](https://github.com/haskell/core-libraries-committee/issues/10) for the
     related discussion, as well as [the migration
     guide](https://github.com/haskell/core-libraries-committee/blob/main/guides/functor-combinator-instances-and-class1s.md).
+  * Add `gcdetails_block_fragmentation_bytes` to `GHC.Stats.GCDetails` to track heap fragmentation.
 
 ## 4.17.0.0 *August 2022*
 


=====================================
rts/Stats.c
=====================================
@@ -182,6 +182,7 @@ initStats0(void)
             .copied_bytes = 0,
             .par_max_copied_bytes = 0,
             .par_balanced_copied_bytes = 0,
+            .block_fragmentation_bytes = 0,
             .sync_elapsed_ns = 0,
             .cpu_ns = 0,
             .elapsed_ns = 0,
@@ -482,6 +483,9 @@ stat_endGC (Capability *cap, gc_thread *initiating_gct, W_ live, W_ copied, W_ s
     stats.gc.copied_bytes = copied * sizeof(W_);
     stats.gc.par_max_copied_bytes = par_max_copied * sizeof(W_);
     stats.gc.par_balanced_copied_bytes = par_balanced_copied * sizeof(W_);
+    stats.gc.block_fragmentation_bytes =
+        (mblocks_allocated * BLOCKS_PER_MBLOCK
+         - n_alloc_blocks) * BLOCK_SIZE;
 
     bool stats_enabled =
         RtsFlags.GcFlags.giveStats != NO_GC_STATS ||
@@ -582,9 +586,7 @@ stat_endGC (Capability *cap, gc_thread *initiating_gct, W_ live, W_ copied, W_ s
                           stats.gc.gen,
                           stats.gc.copied_bytes,
                           stats.gc.slop_bytes,
-                          /* current loss due to fragmentation */
-                          (mblocks_allocated * BLOCKS_PER_MBLOCK
-                           - n_alloc_blocks) * BLOCK_SIZE,
+                          stats.gc.block_fragmentation_bytes,
                           par_n_threads,
                           stats.gc.par_max_copied_bytes,
                           stats.gc.copied_bytes,


=====================================
rts/include/RtsAPI.h
=====================================
@@ -155,6 +155,8 @@ typedef struct GCDetails_ {
   uint64_t mem_in_use_bytes;
     // Total amount of data copied during this GC
   uint64_t copied_bytes;
+    // Memory lost due to block fragmentation
+  uint64_t block_fragmentation_bytes;
     // In parallel GC, the max amount of data copied by any one thread
   uint64_t par_max_copied_bytes;
   // In parallel GC, the amount of balanced data copied by all threads



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c0ba775dda6ddec1251363d1b73f4f3e35931dd9

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c0ba775dda6ddec1251363d1b73f4f3e35931dd9
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20220921/6e56df3b/attachment-0001.html>


More information about the ghc-commits mailing list