unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* GC Warning related to large mem block allocation - Help needed
@ 2017-12-30  1:48 David Pirotte
  2017-12-30  2:35 ` David Pirotte
  2017-12-30  4:05 ` David Pirotte
  0 siblings, 2 replies; 8+ messages in thread
From: David Pirotte @ 2017-12-30  1:48 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 3127 bytes --]

Hello,

Currently, using guile-cv upon large images triggers these warnings,
using guile guile 2.2.3:

	GC Warning: Repeated allocation of very large block (appr. size 775237632):
        May lead to memory leak and poor performance.

	... then 1 '=' above msg per block allocation, tens to hundreds, sometimes
	even thousands of these, depending on the image processing being done ...

These are totally unnecessary (I know I'm allocating these blocks), renders the
repl 'output' unreadable/unusable and actually scare users (well, I only have one
user for now).

So I am trying to understand and solve this problem. Below a (naive) attempt to
patch guile so it uses GC_malloc_ignore_off_page for objects > 100Kb, but that
did not even work: I guess I do miss most if not all of the puzzle pieces here...

While I wrote this tiny patch,  2 quiz also raised in my mind, here there are,
together with the naive patch (below):

1-    should this function return volatile ? (and how)

In bwd-gc README file you can read:

	https://github.com/ivmai/bdwgc

GC_malloc_ignore_off_page(bytes)

    Identical to GC_malloc, but the client promises to keep a pointer to the
    somewhere within the first 256 bytes of the object while it is live. (This
    pointer should normally be declared volatile to prevent interference from
    compiler optimizations.) This is the recommended way to allocate anything that
    is likely to be larger than 100 Kbytes or so. (GC_malloc may result in failure
    to reclaim such objects.)

and if yes, how would I achieve this since this function has multiple return
calls (with different pointer type) ?

2-    I don't understand the last return 'case'

    ...
      return scm_inline_gc_alloc
        (&thread->freelists[idx], idx, SCM_INLINE_GC_KIND_NORMAL);
    ...

How should that be patched so it also use GC_malloc_ignore_off_page(bytes)
when bytes > 100Kb?

Thanks,
David

;;;
;;; Below the patch that does not work :)
;;;

From 0ae4f18e478b2e390de72f560ff8428edfeda860 Mon Sep 17 00:00:00 2001
From: David PIROTTE <david@altosw.be>
Date: Fri, 29 Dec 2017 22:40:52 -0200
Subject: [PATCH] Use GC_malloc_ignore_off_page for objects > 100Kb

* libguile/gc-inline.h (scm_inline_gc_malloc): Use
  GC_malloc_ignore_off_page for objects > 100Kb.
---
 libguile/gc-inline.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libguile/gc-inline.h b/libguile/gc-inline.h
index fcbe5a54e..7d02e67cc 100644
--- a/libguile/gc-inline.h
+++ b/libguile/gc-inline.h
@@ -119,8 +119,12 @@ scm_inline_gc_malloc (scm_i_thread *thread, size_t bytes)
 {
   size_t idx = scm_inline_gc_bytes_to_freelist_index (bytes);
 
-  if (SCM_UNLIKELY (idx >= SCM_INLINE_GC_FREELIST_COUNT))
-    return GC_malloc (bytes);
+  if (SCM_UNLIKELY (idx >= SCM_INLINE_GC_FREELIST_COUNT)) {
+    if (bytes > 100000)
+      return  GC_malloc_ignore_off_page (bytes);
+    else
+      return GC_malloc (bytes);
+  }
 
   return scm_inline_gc_alloc
     (&thread->freelists[idx], idx, SCM_INLINE_GC_KIND_NORMAL);
-- 
2.15.0

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-01-01 22:05 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-30  1:48 GC Warning related to large mem block allocation - Help needed David Pirotte
2017-12-30  2:35 ` David Pirotte
2017-12-30  4:05 ` David Pirotte
2017-12-30  5:10   ` Mike Gran
2017-12-30 23:38     ` David Pirotte
2017-12-31 13:22       ` David Pirotte
2018-01-01 14:11         ` Freja Nordsiek
2018-01-01 22:05           ` Daniel Llorens

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).