aboutsummaryrefslogtreecommitdiff
path: root/lgc.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-12-13 11:55:14 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-12-13 11:55:14 -0300
commit40565b4a089f44fdcb16f4ed0080b0ca3755e4aa (patch)
treed3d692070a250e5756fad95388606736253da8c4 /lgc.h
parentff106c028ca944ee5e95b005628e2669b87bcaf2 (diff)
downloadlua-40565b4a089f44fdcb16f4ed0080b0ca3755e4aa.tar.gz
lua-40565b4a089f44fdcb16f4ed0080b0ca3755e4aa.tar.bz2
lua-40565b4a089f44fdcb16f4ed0080b0ca3755e4aa.zip
Revamp of GC parameters
More uniformity when handling GC parameters + avoid divisions by 100 when applying them.
Diffstat (limited to 'lgc.h')
-rw-r--r--lgc.h44
1 files changed, 34 insertions, 10 deletions
diff --git a/lgc.h b/lgc.h
index 3c871969..6d82690d 100644
--- a/lgc.h
+++ b/lgc.h
@@ -8,6 +8,9 @@
8#define lgc_h 8#define lgc_h
9 9
10 10
11#include <stddef.h>
12
13
11#include "lobject.h" 14#include "lobject.h"
12#include "lstate.h" 15#include "lstate.h"
13 16
@@ -122,20 +125,18 @@
122 125
123 126
124/* Default Values for GC parameters */ 127/* Default Values for GC parameters */
125#define LUAI_GENMAJORMUL 100 128
126#define LUAI_GENMINORMUL 20 129/* generational */
130
131#define LUAI_GENMAJORMUL 100 /* major multiplier */
132#define LUAI_GENMINORMUL 20 /* minor multiplier */
133
134/* incremental */
127 135
128/* wait memory to double before starting new cycle */ 136/* wait memory to double before starting new cycle */
129#define LUAI_GCPAUSE 200 137#define LUAI_GCPAUSE 200
130 138
131/* 139#define LUAI_GCMUL 300 /* step multiplier */
132** some gc parameters are stored divided by 4 to allow a maximum value
133** up to 1023 in a 'lu_byte'.
134*/
135#define getgcparam(p) ((p) * 4)
136#define setgcparam(p,v) ((p) = (v) / 4)
137
138#define LUAI_GCMUL 300
139 140
140/* how many objects to allocate before next GC step (log2) */ 141/* how many objects to allocate before next GC step (log2) */
141#define LUAI_GCSTEPSIZE 8 /* 256 objects */ 142#define LUAI_GCSTEPSIZE 8 /* 256 objects */
@@ -149,6 +150,29 @@
149#define GCSTPCLS 4 /* bit true when closing Lua state */ 150#define GCSTPCLS 4 /* bit true when closing Lua state */
150#define gcrunning(g) ((g)->gcstp == 0) 151#define gcrunning(g) ((g)->gcstp == 0)
151 152
153/*
154** Macros to set and apply GC parameters. GC parameters are given in
155** percentage points, but are stored as lu_byte. To reduce their
156** values and avoid repeated divisions by 100, these macros store
157** the original parameter multiplied by 2^n and divided by 100.
158** To apply them, the value is divided by 2^n (a shift) and then
159** multiplied by the stored parameter, yielding
160** value / 2^n * (original parameter * 2^n / 100), or approximately
161** (value * original parameter / 100).
162**
163** For most parameters, which are typically larger than 100%, 2^n is
164** 16 (2^4), allowing maximum values up to 1599. For the minor
165** multiplier, which is typically smaller, 2^n is 64 (2^6) to allow more
166** precision.
167*/
168#define gcparamshift(p) \
169 (offsetof(global_State, p) == offsetof(global_State, genminormul) ? 6 : 4)
170
171#define setgcparam(g,p,v) \
172 (g->p = (cast_uint(v) << gcparamshift(p)) / 100u)
173#define applygcparam(g,p,v) (((v) >> gcparamshift(p)) * g->p)
174
175
152 176
153/* 177/*
154** Does one step of collection when debt becomes positive. 'pre'/'pos' 178** Does one step of collection when debt becomes positive. 'pre'/'pos'