[Pkg-gnupg-commit] [gnupg2] 83/132: gpgscm: Avoid fruitless garbage collection cycles.
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Wed May 17 03:07:44 UTC 2017
This is an automated email from the git hooks/post-receive script.
dkg pushed a commit to branch experimental
in repository gnupg2.
commit 245860ecaf8b9e82ca577385abd453ac92ffcd26
Author: Justus Winter <justus at g10code.com>
Date: Thu Apr 20 15:04:52 2017 +0200
gpgscm: Avoid fruitless garbage collection cycles.
* tests/gpgscm/scheme-private.h (CELL_MINRECOVER): New macro.
* tests/gpgscm/scheme.c (_get_cell): Move the heuristic to get more
cells...
(gc): ... here where every caller benefits from the optimization.
Signed-off-by: Justus Winter <justus at g10code.com>
---
tests/gpgscm/scheme-private.h | 7 +++++++
tests/gpgscm/scheme.c | 16 ++++++++--------
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/tests/gpgscm/scheme-private.h b/tests/gpgscm/scheme-private.h
index 075dc70..bc0269a 100644
--- a/tests/gpgscm/scheme-private.h
+++ b/tests/gpgscm/scheme-private.h
@@ -108,6 +108,13 @@ int tracing;
#ifndef CELL_SEGSIZE
#define CELL_SEGSIZE 5000 /* # of cells in one segment */
#endif
+
+/* If less than # of cells are recovered in a garbage collector run,
+ * allocate a new cell segment to avoid fruitless collection cycles in
+ * the near future. */
+#ifndef CELL_MINRECOVER
+#define CELL_MINRECOVER (CELL_SEGSIZE >> 2)
+#endif
struct cell_segment *cell_segments;
/* We use 4 registers. */
diff --git a/tests/gpgscm/scheme.c b/tests/gpgscm/scheme.c
index 933dc45..11f6fcb 100644
--- a/tests/gpgscm/scheme.c
+++ b/tests/gpgscm/scheme.c
@@ -949,15 +949,10 @@ static pointer _get_cell(scheme *sc, pointer a, pointer b) {
assert (gc_enabled (sc));
if (sc->free_cell == sc->NIL) {
- const int min_to_be_recovered = CELL_SEGSIZE / 4;
gc(sc,a, b);
- if (sc->fcells < min_to_be_recovered
- || sc->free_cell == sc->NIL) {
- /* if only a few recovered, get more to avoid fruitless gc's */
- if (!alloc_cellseg(sc,1) && sc->free_cell == sc->NIL) {
- sc->no_memory=1;
- return sc->sink;
- }
+ if (sc->free_cell == sc->NIL) {
+ sc->no_memory=1;
+ return sc->sink;
}
}
x = sc->free_cell;
@@ -1746,6 +1741,11 @@ static void gc(scheme *sc, pointer a, pointer b) {
snprintf(msg,80,"done: %ld cells were recovered.\n", sc->fcells);
putstr(sc,msg);
}
+
+ /* if only a few recovered, get more to avoid fruitless gc's */
+ if (sc->fcells < CELL_MINRECOVER
+ && alloc_cellseg(sc, 1) == 0)
+ sc->no_memory = 1;
}
static void finalize_cell(scheme *sc, pointer a) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git
More information about the Pkg-gnupg-commit
mailing list