X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Fgc.lisp;h=086d6836aad392ce2c58b54f5e7115303c5f7f34;hb=2db3b6b4cb740d5b6512459c223859f747807b09;hp=e9e1eb189dacbd2be21061c1de89f046f468897d;hpb=c81c32ef8a737b0cc61d3c0c6a137cab39baac73;p=sbcl.git diff --git a/src/code/gc.lisp b/src/code/gc.lisp index e9e1eb1..086d683 100644 --- a/src/code/gc.lisp +++ b/src/code/gc.lisp @@ -33,9 +33,9 @@ #!-sb-fluid (declaim (inline dynamic-usage)) ; to reduce PROFILEd call overhead -#!+(or cgc gencgc) +#!+gencgc (def-c-var-frob dynamic-usage "bytes_allocated") -#!-(or cgc gencgc) +#!-gencgc (defun dynamic-usage () (the (unsigned-byte 32) (- (sb!sys:sap-int (sb!c::dynamic-space-free-pointer)) @@ -179,19 +179,49 @@ and submit it as a patch." ;;; a limit to help catch programs which allocate too much memory, ;;; since a hard heap overflow is so hard to recover from +;;; +;;; FIXME: Like *GC-TRIGGER*, this variable (1) should probably be +;;; denominated in a larger unit than bytes and (2) should probably be +;;; renamed so that it's clear from the name what unit it's +;;; denominated in. (declaim (type (or unsigned-byte null) *soft-heap-limit*)) -(defvar *soft-heap-limit* nil) +(defvar *soft-heap-limit* + ;; As long as *GC-TRIGGER* is DECLAIMed as INDEX, we know that + ;; MOST-POSITIVE-FIXNUM is a hard limit on how much memory can be + ;; allocated. (Not necessarily *the* hard limit, which is fairly + ;; likely something like a Unix per-process limit that we don't know + ;; about, but a hard limit anyway.) And this gives us a reasonable + ;; conservative default for the soft limit... + (- most-positive-fixnum + *bytes-consed-between-gcs*)) + +;;;; The following specials are used to control when garbage +;;;; collection occurs. ;;; When the dynamic usage increases beyond this amount, the system ;;; notes that a garbage collection needs to occur by setting ;;; *NEED-TO-COLLECT-GARBAGE* to T. It starts out as NIL meaning ;;; nobody has figured out what it should be yet. -(defvar *gc-trigger* nil) - +;;; +;;; FIXME: *GC-TRIGGER* seems to be denominated in bytes, not words. +;;; And limiting it to INDEX is fairly reasonable in order to avoid +;;; bignum arithmetic on every allocation, and to minimize the need +;;; for thought about weird gotchas of the GC-control mechanism itself +;;; consing as it operates. But as of sbcl-0.7.5, 512Mbytes of memory +;;; costs $54.95 at Fry's in Dallas but cheap consumer 64-bit machines +;;; are still over the horizon, so gratuitously limiting our heap size +;;; to FIXNUM bytes seems fairly stupid. It'd be reasonable to +;;; (1) allow arbitrary UNSIGNED-BYTE values of *GC-TRIGGER*, or +;;; (2) redenominate this variable in words instead of bytes, postponing +;;; the problem to heaps which exceed 50% of the machine's address +;;; space, or even +;;; (3) redemoninate this variable in CONS-sized two-word units, +;;; allowing it to cover the entire memory space at the price of +;;; possible loss of clarity. +;;; (And whatever is done, it'd also be good to rename the variable so +;;; that it's clear what unit it's denominated in.) (declaim (type (or index null) *gc-trigger*)) - -;;;; The following specials are used to control when garbage collection -;;;; occurs. +(defvar *gc-trigger* nil) ;;; When non-NIL, inhibits garbage collection. (defvar *gc-inhibit*) ; initialized in cold init @@ -214,7 +244,7 @@ and submit it as a patch." (finish-output notify-stream)) (defparameter *gc-notify-before* #'default-gc-notify-before #!+sb-doc - "This function bound to this variable is invoked before GC'ing (unless + "The function bound to this variable is invoked before GC'ing (unless *GC-NOTIFY-STREAM* is NIL) with the value of *GC-NOTIFY-STREAM* and current amount of dynamic usage (in bytes). It should notify the user that the system is going to GC.") @@ -243,7 +273,7 @@ function should notify the user that the system has finished GC'ing.") ;;;; internal GC (sb!alien:define-alien-routine collect-garbage sb!alien:int - #!+gencgc (last-gen sb!alien:int)) + (#!+gencgc last-gen #!-gencgc ignore sb!alien:int)) (sb!alien:define-alien-routine set-auto-gc-trigger sb!alien:void (dynamic-usage sb!alien:unsigned-long)) @@ -319,17 +349,7 @@ function should notify the user that the system has finished GC'ing.") ;; triggered GC could've done a fair amount of ;; consing.) (pre-internal-gc-dynamic-usage (dynamic-usage)) - (ignore-me - #!-gencgc (funcall *internal-gc*) - ;; FIXME: This EQ test is pretty gross. Among its other - ;; nastinesses, it looks as though it could break if we - ;; recompile COLLECT-GARBAGE. We should probably just - ;; straighten out the interface so that all *INTERNAL-GC* - ;; functions accept a GEN argument (and then the - ;; non-generational ones just ignore it). - #!+gencgc (if (eq *internal-gc* #'collect-garbage) - (funcall *internal-gc* gen) - (funcall *internal-gc*))) + (ignore-me (funcall *internal-gc* gen)) (post-gc-dynamic-usage (dynamic-usage)) (n-bytes-freed (- pre-internal-gc-dynamic-usage post-gc-dynamic-usage))