]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Backport ggc_trim
authorJan Hubicka <hubicka@ucw.cz>
Fri, 25 Oct 2019 11:17:38 +0000 (13:17 +0200)
committerJan Hubicka <hubicka@gcc.gnu.org>
Fri, 25 Oct 2019 11:17:38 +0000 (11:17 +0000)
Backport from mainline

2019-10-18  Jakub Jelinek  <jakub@redhat.com>
PR middle-end/92153
* ggc-page.c (release_pages): Read g->alloc_size before free rather
than after it.

2019-10-11  Jan Hubicka  <hubicka@ucw.cz>

* ggc-page.c (release_pages): Output statistics when !quiet_flag.
(ggc_collect): Dump later to not interfere with release_page dump.
(ggc_trim): New function.
* ggc-none.c (ggc_trim): New.
* ggc.h (ggc_trim): Declare.

* lto-partition.c (add_symbol_to_partition_1): Update.
(undo_parittion): Update.

From-SVN: r277443

gcc/ChangeLog
gcc/ggc-none.c
gcc/ggc-page.c
gcc/ggc.h
gcc/lto/ChangeLog
gcc/lto/lto.c

index e98c5994b38845a52c6bfa6e5902c7955fc9c4b9..07d33590c77b958bf0c08b0fef230231283a13ff 100644 (file)
@@ -1,3 +1,19 @@
+2019-10-25  Jan Hubicka  <hubicka@ucw.cz>
+
+       Backport from mainline
+
+       2019-10-18  Jakub Jelinek  <jakub@redhat.com>
+       PR middle-end/92153
+       * ggc-page.c (release_pages): Read g->alloc_size before free rather
+       than after it.
+
+       2019-10-11  Jan Hubicka  <hubicka@ucw.cz>
+       * ggc-page.c (release_pages): Output statistics when !quiet_flag.
+       (ggc_collect): Dump later to not interfere with release_page dump.
+       (ggc_trim): New function.
+       * ggc-none.c (ggc_trim): New.
+       * ggc.h (ggc_trim): Declare.
+
 2019-10-24  Mihail Ionescu  <mihail.ionescu@arm.com>
 
        Backport from mainline
index 6edec27868ca40e6512b06ff0062d957ba30759b..737429f9e49a76a7c7e43cee479b36a9d2c4c48f 100644 (file)
@@ -72,3 +72,8 @@ void
 ggc_grow (void)
 {
 }
+
+void
+ggc_trim (void)
+{
+}
index cd531e5b1e6b2bf01e48a83f5e41ce7f379c953d..3c9636d0fe76f25facb1d2ea8ffa47313ae67777 100644 (file)
@@ -1016,6 +1016,8 @@ free_page (page_entry *entry)
 static void
 release_pages (void)
 {
+  size_t n1 = 0;
+  size_t n2 = 0;
 #ifdef USING_MADVISE
   page_entry *p, *start_p;
   char *start;
@@ -1061,6 +1063,7 @@ release_pages (void)
           else
             G.free_pages = p;
           G.bytes_mapped -= mapped_len;
+         n1 += len;
          continue;
         }
       prev = newprev;
@@ -1092,6 +1095,7 @@ release_pages (void)
       /* Don't count those pages as mapped to not touch the garbage collector
          unnecessarily. */
       G.bytes_mapped -= len;
+      n2 += len;
       while (start_p != p)
         {
           start_p->discarded = true;
@@ -1124,6 +1128,7 @@ release_pages (void)
        }
 
       munmap (start, len);
+      n1 += len;
       G.bytes_mapped -= len;
     }
 
@@ -1151,11 +1156,21 @@ release_pages (void)
       {
        *gp = g->next;
        G.bytes_mapped -= g->alloc_size;
+       n1 += g->alloc_size;
        free (g->allocation);
       }
     else
       gp = &g->next;
 #endif
+  if (!quiet_flag && (n1 || n2))
+    {
+      fprintf (stderr, " {GC");
+      if (n1)
+       fprintf (stderr, " released %luk", (unsigned long)(n1 / 1024));
+      if (n2)
+       fprintf (stderr, " madv_dontneed %luk", (unsigned long)(n2 / 1024));
+      fprintf (stderr, "}");
+    }
 }
 
 /* This table provides a fast way to determine ceil(log_2(size)) for
@@ -2178,19 +2193,22 @@ ggc_collect (void)
     return;
 
   timevar_push (TV_GC);
-  if (!quiet_flag)
-    fprintf (stderr, " {GC %luk -> ", (unsigned long) G.allocated / 1024);
   if (GGC_DEBUG_LEVEL >= 2)
     fprintf (G.debug_file, "BEGIN COLLECTING\n");
 
   /* Zero the total allocated bytes.  This will be recalculated in the
      sweep phase.  */
+  size_t allocated = G.allocated;
   G.allocated = 0;
 
   /* Release the pages we freed the last time we collected, but didn't
      reuse in the interim.  */
   release_pages ();
 
+  /* Output this later so we do not interfere with release_pages.  */
+  if (!quiet_flag)
+    fprintf (stderr, " {GC %luk -> ", (unsigned long) allocated / 1024);
+
   /* Indicate that we've seen collections at this context depth.  */
   G.context_depth_collections = ((unsigned long)1 << (G.context_depth + 1)) - 1;
 
@@ -2221,9 +2239,25 @@ ggc_collect (void)
     fprintf (G.debug_file, "END COLLECTING\n");
 }
 
-/* Assume that all GGC memory is reachable and grow the limits for next collection.
-   With checking, trigger GGC so -Q compilation outputs how much of memory really is
-   reachable.  */
+/* Return free pages to the system.  */
+
+void
+ggc_trim ()
+{
+  timevar_push (TV_GC);
+  G.allocated = 0;
+  sweep_pages ();
+  release_pages ();
+  if (!quiet_flag)
+    fprintf (stderr, " {GC trimmed to %luk, %luk mapped}",
+            (unsigned long) G.allocated / 1024,
+            (unsigned long) G.bytes_mapped / 1024);
+  timevar_pop (TV_GC);
+}
+
+/* Assume that all GGC memory is reachable and grow the limits for next
+   collection.  With checking, trigger GGC so -Q compilation outputs how much
+   of memory really is reachable.  */
 
 void
 ggc_grow (void)
index 60273f2e57d3bebc8dd8407fd4d906086ffa8897..31606dc843fb72186b5f13231ab6b101906efe84 100644 (file)
--- a/gcc/ggc.h
+++ b/gcc/ggc.h
@@ -243,6 +243,9 @@ extern const char *ggc_alloc_string (const char *contents, int length
    function is called, not during allocations.  */
 extern void ggc_collect        (void);
 
+/* Return unused memory pages to the system.  */
+extern void ggc_trim (void);
+
 /* Assume that all GGC memory is reachable and grow the limits for next collection. */
 extern void ggc_grow (void);
 
index eb2653be61684d9adcd479abfb7c6d87b341e3d0..e99eb1520febf5bdac35324c4ff4d77933885c85 100644 (file)
@@ -1,3 +1,9 @@
+2019-10-25  Jan Hubicka  <hubicka@ucw.cz>
+
+       Backport from mainline
+       * lto-partition.c (add_symbol_to_partition_1): Update.
+       (undo_parittion): Update.
+
 2019-08-12  Release Manager
 
        * GCC 9.2.0 released.
index 4367928a5154cdf9ebf7e78fb761fe67783bc279..be6942fce07d46e3b5d8aeea9672a305a330b273 100644 (file)
@@ -2446,6 +2446,8 @@ lto_wpa_write_files (void)
 
   timevar_push (TV_WHOPR_WPA_IO);
 
+  ggc_trim ();
+
   /* Generate a prefix for the LTRANS unit files.  */
   blen = strlen (ltrans_output_list);
   temp_filename = (char *) xmalloc (blen + sizeof ("2147483648.o"));