Skip to content
Snippets Groups Projects
Commit 0696d2e7 authored by Markus Alexander Kuppe's avatar Markus Alexander Kuppe
Browse files

Fall back to conservative memory allocation if LiveWorker runs into

OutOfMemoryError.  If conservative allocation succeeds, liveness
checking will be slow.

[Feature][Bug]
parent d1668ba1
Branches
Tags
No related merge requests found
......@@ -477,6 +477,7 @@ public class LiveWorker implements Callable<Boolean> {
// memory. Also take the total number of simultaneously running
// workers into account that have to share the available memory
// among each other.
try {
final double freeMemoryInBytes = (Runtime.getRuntime().freeMemory() / (numWorkers * 1d));
final long graphSizeInBytes = this.dg.getSizeOnDisk();
final double ratio = graphSizeInBytes / freeMemoryInBytes;
......@@ -495,6 +496,18 @@ public class LiveWorker implements Callable<Boolean> {
// If the disk graph as a whole fits into memory, do not use a
// disk-backed SynchronousDiskIntStack.
return new MemIntStack(metaDir, name);
} catch (final OutOfMemoryError oom) {
System.gc();
// If the allocation above failed, be more conservative. If it fails to
// allocate even 16mb, TLC will subsequently terminate with a message about insufficient
// memory.
final SynchronousDiskIntStack sdis = new SynchronousDiskIntStack(metaDir, name,
SynchronousDiskIntStack.BufSize / 2);
MP.printWarning(EC.GENERAL,
"Liveness checking will be extremely slow because TLC is running low on memory.\n"
+ "Try allocating more memory to the Java pool (heap) in future TLC runs.");
return sdis;
}
}
/**
......
......@@ -55,7 +55,7 @@ public class SynchronousDiskIntStack implements IntStack {
public SynchronousDiskIntStack(String diskdir, String name, int capacity) {
// Hard-limit capacity to 1gb per page file
capacity = Math.min(BufSizeMax, Math.max(capacity, BufSize));
capacity = Math.min(BufSizeMax, capacity);
this.filePrefix = diskdir + FileUtil.separator + name;
this.bufSize = capacity;
this.buf = new int[capacity];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment