--- ray/src/hd/holofile.c 1998/01/04 12:32:53 3.19 +++ ray/src/hd/holofile.c 1998/09/18 13:51:01 3.25 @@ -1,4 +1,4 @@ -/* Copyright (c) 1997 Silicon Graphics, Inc. */ +/* Copyright (c) 1998 Silicon Graphics, Inc. */ #ifndef lint static char SCCSid[] = "$SunId$ SGI"; @@ -16,10 +16,10 @@ static char SCCSid[] = "$SunId$ SGI"; #define CACHESIZE 16 /* default cache size (Mbytes, 0==inf) */ #endif #ifndef FREEBEAMS -#define FREEBEAMS 512 /* maximum beams to free at a time */ +#define FREEBEAMS 1500 /* maximum beams to free at a time */ #endif #ifndef PCTFREE -#define PCTFREE 20 /* maximum fraction to free (%) */ +#define PCTFREE 15 /* maximum fraction to free (%) */ #endif #ifndef MAXFRAG #define MAXFRAG 32767 /* maximum fragments/file to track (0==inf) */ @@ -105,6 +105,7 @@ hdinit(fd, hproto) /* initialize a holodeck section in int fd; /* corresponding file descriptor */ HDGRID *hproto; /* holodeck section grid */ { + long rtrunc; long fpos; register HOLO *hp; register int n; @@ -126,7 +127,7 @@ HDGRID *hproto; /* holodeck section grid */ error(SYSTEM, "failure loading holodeck directory"); /* check that it's clean */ if (hp->bi[nbeams(hp)].fo < 0) - error(USER, "dirty holodeck section"); + error(WARNING, "dirty holodeck section"); } else { /* assume we're creating it */ if ((hp = hdalloc(hproto)) == NULL) goto memerr; @@ -144,13 +145,19 @@ HDGRID *hproto; /* holodeck section grid */ hdattach(fd); /* check rays on disk */ fpos = hdfilen(fd); - biglob(hp)->nrd = 0; + biglob(hp)->nrd = rtrunc = 0; for (n = hproto == NULL ? nbeams(hp) : 0; n > 0; n--) if (hp->bi[n].nrd) - if (hp->bi[n].fo + hp->bi[n].nrd > fpos) - hp->bi[n].nrd = 0; /* off end */ - else + if (hp->bi[n].fo + hp->bi[n].nrd > fpos) { + rtrunc += hp->bi[n].nrd; + hp->bi[n].nrd = 0; + } else biglob(hp)->nrd += hp->bi[n].nrd; + if (rtrunc) { + sprintf(errmsg, "truncated section, %ld rays lost (%.1f%%)", + rtrunc, 100.*rtrunc/(rtrunc+biglob(hp)->nrd)); + error(WARNING, errmsg); + } /* add to holodeck list */ for (n = 0; n < HDMAX; n++) if (hdlist[n] == NULL) { @@ -309,8 +316,7 @@ int nr; /* number of new rays desired */ p = hdbray(hp->bl[i]) + hp->bl[i]->nrm; hp->bl[i]->nrm += nr; /* update in-core structure */ bzero((char *)p, nr*sizeof(RAYVAL)); - hp->bl[i]->tick = hdclock; /* update LRU clock */ - blglob(hp)->tick = hdclock++; + blglob(hp)->tick = hp->bl[i]->tick = hdclock++; /* update LRU clock */ return(p); /* point to new rays */ memerr: error(SYSTEM, "out of memory in hdnewrays"); @@ -341,8 +347,7 @@ register int i; if (read(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) error(SYSTEM, "error reading beam from holodeck file"); } - hp->bl[i]->tick = hdclock; /* update LRU clock */ - blglob(hp)->tick = hdclock++; + blglob(hp)->tick = hp->bl[i]->tick = hdclock++; /* update LRU clock */ return(hp->bl[i]); } @@ -372,10 +377,11 @@ int n; /* list length */ int (*bf)(); /* callback function (optional) */ { unsigned origcachesize, memuse; - register BEAM *bp; int bytesloaded, needbytes, bytes2free; + register BEAM *bp; register int i; /* precheck consistency */ + if (n <= 0) return; for (i = n; i--; ) if (hb[i].h == NULL || hb[i].b < 1 | hb[i].b > nbeams(hb[i].h)) error(CONSISTENCY, "bad beam in hdloadbeams"); @@ -383,10 +389,10 @@ int (*bf)(); /* callback function (optional) */ qsort((char *)hb, n, sizeof(HDBEAMI), hdfilord); bytesloaded = 0; /* run through loaded beams */ for ( ; n && (bp = hb->h->bl[hb->b]) != NULL; n--, hb++) { - bp->tick = hdclock; /* preempt swap */ + bp->tick = hdclock; /* preempt swap */ bytesloaded += bp->nrm; if (bf != NULL) - (*bf)(bp, hb->h, hb->b); + (*bf)(bp, hb); } bytesloaded *= sizeof(RAYVAL); if ((origcachesize = hdcachesize) > 0) { @@ -405,7 +411,7 @@ int (*bf)(); /* callback function (optional) */ } for (i = 0; i < n; i++) if ((bp = hdgetbeam(hb[i].h, hb[i].b)) != NULL && bf != NULL) - (*bf)(bp, hb[i].h, hb[i].b); + (*bf)(bp, hb+i); hdcachesize = origcachesize; /* resume dynamic swapping */ } @@ -641,7 +647,7 @@ register HOLO *hp; /* section we're adding from */ { register int i, j; /* insert each beam from hp */ - for (i = nbeams(hp); i > 0; i--) { + for (i = 1; i <= nbeams(hp); i++) { if (hp->bl[i] == NULL) /* check if loaded */ continue; #if 0 @@ -673,6 +679,11 @@ register HOLO *honly; /* NULL means check all */ int freetarget; int n; register int i; +#ifdef DEBUG + unsigned membefore; + + membefore = hdmemuse(0); +#endif /* compute free target */ freetarget = (honly != NULL) ? blglob(honly)->nrm : hdmemuse(0)/sizeof(RAYVAL) ; @@ -693,6 +704,12 @@ register HOLO *honly; /* NULL means check all */ break; } hdsync(honly, 0); /* synchronize directories as necessary */ +#ifdef DEBUG + sprintf(errmsg, + "%dK before, %dK after hdfreecache (%dK total), %d rays short\n", + membefore>>10, hdmemuse(0)>>10, hdmemuse(1)>>10, freetarget); + wputs(errmsg); +#endif return(-freetarget); /* return how far past goal we went */ } @@ -705,6 +722,8 @@ register HOLO *hp; /* NULL means clean up all */ if (hp == NULL) { /* NULL means clean up everything */ while (hdlist[0] != NULL) hddone(hdlist[0]); + free((char *)hdfragl); + hdfragl = NULL; nhdfragls = 0; return; } /* flush all data and free memory */