aux/disksim: use even less memory
[rsc] --rw-rw-r-- M 1812954 rsc sys 11178 Feb 26 09:40 sys/src/cmd/aux/disksim.c
/n/sourcesdump/2006/0226/plan9/sys/src/cmd/aux/disksim.c:23,28 -
/n/sourcesdump/2006/0227/plan9/sys/src/cmd/aux/disksim.c:23,29
LOGNPTR = LOGBLKSZ-2, /* assume sizeof(void*) == 4 */
NPTR = 1<<LOGNPTR,
};
+ static uchar zero[BLKSZ];
struct Trip
{
/n/sourcesdump/2006/0226/plan9/sys/src/cmd/aux/disksim.c:239,245 -
/n/sourcesdump/2006/0227/plan9/sys/src/cmd/aux/disksim.c:240,245
uchar*
getblock(vlong addr, int alloc)
{
- static uchar zero[BLKSZ];
Dbl *p2;
Ind *p1;
uchar *p0;
/n/sourcesdump/2006/0226/plan9/sys/src/cmd/aux/disksim.c:356,364 -
/n/sourcesdump/2006/0227/plan9/sys/src/cmd/aux/disksim.c:356,377
}
int
+ isnonzero(void *v, ulong n)
+ {
+ uchar *a, *ea;
+
+ a = v;
+ ea = a+n;
+ for(; a<ea; a++)
+ if(*a)
+ return 1;
+ return 0;
+ }
+
+ int
rdwrpart(Req *r)
{
- int q;
+ int q, nonzero;
Part *p;
vlong offset;
long count, tot, n, o;
/n/sourcesdump/2006/0226/plan9/sys/src/cmd/aux/disksim.c:396,429 -
/n/sourcesdump/2006/0227/plan9/sys/src/cmd/aux/disksim.c:409,444
move = evommem;
tot = 0;
+ nonzero = 1;
if(r->ifcall.type == Tread)
dat = (uchar*)r->ofcall.data;
- else
+ else{
dat = (uchar*)r->ifcall.data;
+ nonzero = isnonzero(dat, r->ifcall.count);
+ }
o = offset & (BLKSZ-1);
/* left fringe block */
- if(o && count){
- blk = getblock(offset, r->ifcall.type==Twrite);
- if(blk == nil)
- abort();
+ if(o && count){
+ blk = getblock(offset, r->ifcall.type==Twrite && nonzero);
n = BLKSZ - o;
if(n > count)
n = count;
- (*move)(dat, blk+o, n);
+ if(r->ifcall.type != Twrite || blk != zero)
+ (*move)(dat, blk+o, n);
if(r->ifcall.type == Twrite)
dirty(offset, blk);
tot += n;
}
+ next:
/* full and right fringe blocks */
while(tot < count){
- blk = getblock(offset+tot, r->ifcall.type==Twrite);
- if(blk == nil)
- abort();
+ blk = getblock(offset+tot, r->ifcall.type==Twrite && nonzero);
n = BLKSZ;
if(n > count-tot)
n = count-tot;
- (*move)(dat+tot, blk, n);
+ if(r->ifcall.type != Twrite || blk != zero)
+ (*move)(dat+tot, blk, n);
if(r->ifcall.type == Twrite)
dirty(offset+tot, blk);
tot += n;
[rsc] --rw-rw-r-- M 1812954 rsc sys 1452 Feb 26 22:08 sys/man/8/disksim
|