16 |
|
#define CACHESIZE 16 /* default cache size (Mbytes, 0==inf) */ |
17 |
|
#endif |
18 |
|
#ifndef FREEBEAMS |
19 |
< |
#define FREEBEAMS 512 /* maximum beams to free at a time */ |
19 |
> |
#define FREEBEAMS 1500 /* maximum beams to free at a time */ |
20 |
|
#endif |
21 |
|
#ifndef PCTFREE |
22 |
< |
#define PCTFREE 20 /* maximum fraction to free (%) */ |
22 |
> |
#define PCTFREE 15 /* maximum fraction to free (%) */ |
23 |
|
#endif |
24 |
|
#ifndef MAXFRAG |
25 |
|
#define MAXFRAG 32767 /* maximum fragments/file to track (0==inf) */ |
105 |
|
int fd; /* corresponding file descriptor */ |
106 |
|
HDGRID *hproto; /* holodeck section grid */ |
107 |
|
{ |
108 |
+ |
long rtrunc; |
109 |
|
long fpos; |
110 |
|
register HOLO *hp; |
111 |
|
register int n; |
145 |
|
hdattach(fd); |
146 |
|
/* check rays on disk */ |
147 |
|
fpos = hdfilen(fd); |
148 |
< |
biglob(hp)->nrd = 0; |
148 |
> |
biglob(hp)->nrd = rtrunc = 0; |
149 |
|
for (n = hproto == NULL ? nbeams(hp) : 0; n > 0; n--) |
150 |
|
if (hp->bi[n].nrd) |
151 |
< |
if (hp->bi[n].fo + hp->bi[n].nrd > fpos) |
152 |
< |
hp->bi[n].nrd = 0; /* off end */ |
153 |
< |
else |
151 |
> |
if (hp->bi[n].fo + hp->bi[n].nrd > fpos) { |
152 |
> |
rtrunc += hp->bi[n].nrd; |
153 |
> |
hp->bi[n].nrd = 0; |
154 |
> |
} else |
155 |
|
biglob(hp)->nrd += hp->bi[n].nrd; |
156 |
+ |
if (rtrunc) { |
157 |
+ |
sprintf(errmsg, "truncated section, %ld rays lost (%.1f%%)", |
158 |
+ |
rtrunc, 100.*rtrunc/(rtrunc+biglob(hp)->nrd)); |
159 |
+ |
error(WARNING, errmsg); |
160 |
+ |
} |
161 |
|
/* add to holodeck list */ |
162 |
|
for (n = 0; n < HDMAX; n++) |
163 |
|
if (hdlist[n] == NULL) { |
316 |
|
p = hdbray(hp->bl[i]) + hp->bl[i]->nrm; |
317 |
|
hp->bl[i]->nrm += nr; /* update in-core structure */ |
318 |
|
bzero((char *)p, nr*sizeof(RAYVAL)); |
319 |
< |
hp->bl[i]->tick = hdclock; /* update LRU clock */ |
313 |
< |
blglob(hp)->tick = hdclock++; |
319 |
> |
blglob(hp)->tick = hp->bl[i]->tick = hdclock++; /* update LRU clock */ |
320 |
|
return(p); /* point to new rays */ |
321 |
|
memerr: |
322 |
|
error(SYSTEM, "out of memory in hdnewrays"); |
347 |
|
if (read(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) |
348 |
|
error(SYSTEM, "error reading beam from holodeck file"); |
349 |
|
} |
350 |
< |
hp->bl[i]->tick = hdclock; /* update LRU clock */ |
345 |
< |
blglob(hp)->tick = hdclock++; |
350 |
> |
blglob(hp)->tick = hp->bl[i]->tick = hdclock++; /* update LRU clock */ |
351 |
|
return(hp->bl[i]); |
352 |
|
} |
353 |
|
|
377 |
|
int (*bf)(); /* callback function (optional) */ |
378 |
|
{ |
379 |
|
unsigned origcachesize, memuse; |
375 |
– |
register BEAM *bp; |
380 |
|
int bytesloaded, needbytes, bytes2free; |
381 |
+ |
register BEAM *bp; |
382 |
|
register int i; |
383 |
|
/* precheck consistency */ |
384 |
+ |
if (n <= 0) return; |
385 |
|
for (i = n; i--; ) |
386 |
|
if (hb[i].h == NULL || hb[i].b < 1 | hb[i].b > nbeams(hb[i].h)) |
387 |
|
error(CONSISTENCY, "bad beam in hdloadbeams"); |
389 |
|
qsort((char *)hb, n, sizeof(HDBEAMI), hdfilord); |
390 |
|
bytesloaded = 0; /* run through loaded beams */ |
391 |
|
for ( ; n && (bp = hb->h->bl[hb->b]) != NULL; n--, hb++) { |
392 |
< |
bp->tick = hdclock; /* preempt swap */ |
392 |
> |
bp->tick = hdclock; /* preempt swap */ |
393 |
|
bytesloaded += bp->nrm; |
394 |
|
if (bf != NULL) |
395 |
< |
(*bf)(bp, hb->h, hb->b); |
395 |
> |
(*bf)(bp, hb); |
396 |
|
} |
397 |
|
bytesloaded *= sizeof(RAYVAL); |
398 |
|
if ((origcachesize = hdcachesize) > 0) { |
411 |
|
} |
412 |
|
for (i = 0; i < n; i++) |
413 |
|
if ((bp = hdgetbeam(hb[i].h, hb[i].b)) != NULL && bf != NULL) |
414 |
< |
(*bf)(bp, hb[i].h, hb[i].b); |
414 |
> |
(*bf)(bp, hb+i); |
415 |
|
hdcachesize = origcachesize; /* resume dynamic swapping */ |
416 |
|
} |
417 |
|
|
647 |
|
{ |
648 |
|
register int i, j; |
649 |
|
/* insert each beam from hp */ |
650 |
< |
for (i = nbeams(hp); i > 0; i--) { |
650 |
> |
for (i = 1; i <= nbeams(hp); i++) { |
651 |
|
if (hp->bl[i] == NULL) /* check if loaded */ |
652 |
|
continue; |
653 |
|
#if 0 |
679 |
|
int freetarget; |
680 |
|
int n; |
681 |
|
register int i; |
682 |
+ |
#ifdef DEBUG |
683 |
+ |
unsigned membefore; |
684 |
+ |
|
685 |
+ |
membefore = hdmemuse(0); |
686 |
+ |
#endif |
687 |
|
/* compute free target */ |
688 |
|
freetarget = (honly != NULL) ? blglob(honly)->nrm : |
689 |
|
hdmemuse(0)/sizeof(RAYVAL) ; |
704 |
|
break; |
705 |
|
} |
706 |
|
hdsync(honly, 0); /* synchronize directories as necessary */ |
707 |
+ |
#ifdef DEBUG |
708 |
+ |
sprintf(errmsg, |
709 |
+ |
"%dK before, %dK after hdfreecache (%dK total), %d rays short\n", |
710 |
+ |
membefore>>10, hdmemuse(0)>>10, hdmemuse(1)>>10, freetarget); |
711 |
+ |
wputs(errmsg); |
712 |
+ |
#endif |
713 |
|
return(-freetarget); /* return how far past goal we went */ |
714 |
|
} |
715 |
|
|
722 |
|
if (hp == NULL) { /* NULL means clean up everything */ |
723 |
|
while (hdlist[0] != NULL) |
724 |
|
hddone(hdlist[0]); |
725 |
+ |
free((char *)hdfragl); |
726 |
+ |
hdfragl = NULL; nhdfragls = 0; |
727 |
|
return; |
728 |
|
} |
729 |
|
/* flush all data and free memory */ |