StorageAccountingImpl.Mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Paul Rovner, January 17, 1984 12:02:04 pm PST
Russ Atkinson (RRA) February 1, 1985 1:36:22 pm PST
DIRECTORY
AllocatorOps USING[permanentPageZone],
Collector USING[InternalReclaim],
PrincOps USING[PsbIndex],
Process USING[GetCurrent],
StorageAccounting USING[defaultCollectionInterval, PSBIMap],
SafeStorage USING[];
StorageAccountingImpl: MONITOR -- Protects the storage account books
IMPORTS AllocatorOps, Collector, Process
EXPORTS StorageAccounting, SafeStorage
= BEGIN OPEN StorageAccounting;
VARIABLES
nWordsRequested: PUBLIC INT ← 0;
nWordsAllocated: PUBLIC INT ← 0; -- >= CollectionInterval implies collect
SUMnWordsAllocated: PUBLIC INT ← 0;
nWordsReclaimed: PUBLIC INT ← 0;
nObjectsCreated: PUBLIC INT ← 0;
nObjectsReclaimed: PUBLIC INT ← 0;
MapPsbiToWordsAllocated: PUBLIC LONG POINTER TO StorageAccounting.PSBIMap;
CollectionInterval: PUBLIC INT ← StorageAccounting.defaultCollectionInterval;
SuspensionThreshold: PUBLIC INT ← ComputeSuspensionThreshold[];
PROCS
ComputeSuspensionThreshold: PROC RETURNS[LONG INTEGER] = {
RETURN[CollectionInterval+CollectionInterval]};
NWordsAllocated: PUBLIC --to SS-- ENTRY SAFE PROC RETURNS[INT] = TRUSTED {
ENABLE UNWIND => NULL;
RETURN[SUMnWordsAllocated + nWordsAllocated];
};
NWordsReclaimed: PUBLIC --to SS-- SAFE PROC RETURNS[INT] = TRUSTED {
RETURN[nWordsReclaimed];
};
ConsiderCollection: PUBLIC PROC[requestedWords, suppliedWords: LONG CARDINAL] = {
psbi: PrincOps.PsbIndex = LOOPHOLE[Process.GetCurrent[]];
nw: LONG INTEGER ← MapPsbiToWordsAllocated.elements[psbi].current + suppliedWords;
MapPsbiToWordsAllocated.elements[psbi].current ← nw;
nWordsAllocated ← nWordsAllocated + suppliedWords;
total count for all processes since the last colection
nWordsRequested ← nWordsRequested + requestedWords; -- total count for all processes
IF LOOPHOLE[nWordsAllocated, INT] >= CollectionInterval OR nw > SuspensionThreshold
THEN Collector.InternalReclaim[allocationInterval, nw > SuspensionThreshold];
};
SetCollectionInterval: PUBLIC --to SS-- ENTRY SAFE PROC[newInterval: LONG CARDINAL] RETURNS[oldInterval: LONG CARDINAL] = TRUSTED {
ENABLE UNWIND => NULL;
oldInterval ← CollectionInterval;
CollectionInterval ← newInterval;
SuspensionThreshold ← ComputeSuspensionThreshold[];
};
ResetNWordsAllocated: PUBLIC ENTRY PROC = {
ENABLE UNWIND => NULL;
SUMnWordsAllocated ← SUMnWordsAllocated + nWordsAllocated;
nWordsAllocated ← 0;
FOR i: PrincOps.PsbIndex IN PrincOps.PsbIndex
DO
MapPsbiToWordsAllocated.elements[i].total
← MapPsbiToWordsAllocated.elements[i].total
+ MapPsbiToWordsAllocated.elements[i].current;
MapPsbiToWordsAllocated.elements[i].current ← 0;
ENDLOOP;
};
ResetTotalNWordsAllocatedOnly: PUBLIC ENTRY PROC = {
SUMnWordsAllocated ← SUMnWordsAllocated + nWordsAllocated;
nWordsAllocated ← 0;
};
START HERE
MapPsbiToWordsAllocated ←
AllocatorOps.permanentPageZone.NEW[
StorageAccounting.PSBIMap[LAST[PrincOps.PsbIndex]+1]];
FOR i: PrincOps.PsbIndex IN PrincOps.PsbIndex DO
MapPsbiToWordsAllocated.elements[i] ← [total: 0, current: 0];
ENDLOOP;
END.