add flushpart; avoid O_DIRECT on linux

This commit is contained in:
rsc 2007-04-27 18:14:45 +00:00
parent 7e4524011b
commit e46cacb0ea
10 changed files with 39 additions and 21 deletions

View file

@ -613,7 +613,8 @@ wbarenahead(Arena *arena)
* during initialization. * during initialization.
*/ */
bad = packarenahead(&head, b->data)<0 || bad = packarenahead(&head, b->data)<0 ||
writepart(arena->part, arena->base - arena->blocksize, b->data, arena->blocksize)<0; writepart(arena->part, arena->base - arena->blocksize, b->data, arena->blocksize)<0 ||
flushpart(arena->part)<0;
freezblock(b); freezblock(b);
if(bad) if(bad)
return -1; return -1;

View file

@ -222,7 +222,8 @@ wbarenapart(ArenaPart *ap)
freezblock(b); freezblock(b);
return -1; return -1;
} }
if(writepart(ap->part, PartBlank, b->data, HeadSize) < 0){ if(writepart(ap->part, PartBlank, b->data, HeadSize) < 0 ||
flushpart(ap->part) < 0){
seterr(EAdmin, "can't write arena partition header: %r"); seterr(EAdmin, "can't write arena partition header: %r");
freezblock(b); freezblock(b);
return -1; return -1;
@ -325,7 +326,7 @@ wbarenamap(AMap *am, int n, Part *part, u64int base, u64int size)
freezblock(b); freezblock(b);
return -1; return -1;
} }
if(writepart(part, base, b->data, size) < 0){ if(writepart(part, base, b->data, size) < 0 || flushpart(part) < 0){
seterr(EAdmin, "can't write arena set: %r"); seterr(EAdmin, "can't write arena set: %r");
freezblock(b); freezblock(b);
return -1; return -1;

View file

@ -121,7 +121,11 @@ int
writebloom(Bloom *b) writebloom(Bloom *b)
{ {
wbbloomhead(b); wbbloomhead(b);
return writepart(b->part, 0, b->data, b->size); if(writepart(b->part, 0, b->data, b->size) < 0)
return -1;
if(flushpart(b->part) < 0)
return -1;
return 0;
} }
/* /*

View file

@ -734,7 +734,7 @@ parallelwrites(DBlock **b, DBlock **eb, int dirty)
for(p=b; p<q; p++){ for(p=b; p<q; p++){
if(part != (*p)->part){ if(part != (*p)->part){
part = (*p)->part; part = (*p)->part;
flushpart(part); flushpart(part); /* what if it fails? */
} }
} }

View file

@ -38,6 +38,7 @@ Arena *findarena(char *name);
int flushciblocks(Arena *arena); int flushciblocks(Arena *arena);
void flushdcache(void); void flushdcache(void);
void flushicache(void); void flushicache(void);
int flushpart(Part*);
void flushqueue(void); void flushqueue(void);
void fmtzbinit(Fmt *f, ZBlock *b); void fmtzbinit(Fmt *f, ZBlock *b);
void freearena(Arena *arena); void freearena(Arena *arena);

View file

@ -175,13 +175,12 @@ icachewritesect(Index *ix, ISect *is, u8int *buf)
diskaccess(1); diskaccess(1);
trace(TraceProc, "icachewritesect writepart", addr, nbuf); trace(TraceProc, "icachewritesect writepart", addr, nbuf);
if(writepart(is->part, addr, buf, nbuf) < 0){ if(writepart(is->part, addr, buf, nbuf) < 0 || flushpart(is->part) < 0){
/* XXX more details here */ /* XXX more details here */
fprint(2, "icachewriteproc writepart: %r\n"); fprint(2, "icachewriteproc writepart: %r\n");
err = -1; err = -1;
continue; continue;
} }
flushpart(is->part);
addstat(StatIsectWriteBytes, nbuf); addstat(StatIsectWriteBytes, nbuf);
addstat(StatIsectWrite, 1); addstat(StatIsectWrite, 1);
icacheclean(chunk); icacheclean(chunk);

View file

@ -144,7 +144,8 @@ wbindex(Index *ix)
return -1; return -1;
} }
for(i = 0; i < ix->nsects; i++){ for(i = 0; i < ix->nsects; i++){
if(writepart(ix->sects[i]->part, ix->sects[i]->tabbase, b->data, ix->tabsize) < 0){ if(writepart(ix->sects[i]->part, ix->sects[i]->tabbase, b->data, ix->tabsize) < 0
|| flushpart(ix->sects[i]->part) < 0){
seterr(EOk, "can't write index: %r"); seterr(EOk, "can't write index: %r");
freezblock(b); freezblock(b);
return -1; return -1;
@ -498,7 +499,7 @@ wbisect(ISect *is)
freezblock(b); freezblock(b);
return -1; return -1;
} }
if(writepart(is->part, PartBlank, b->data, HeadSize) < 0){ if(writepart(is->part, PartBlank, b->data, HeadSize) < 0 || flushpart(is->part) < 0){
seterr(EAdmin, "can't write index section header: %r"); seterr(EAdmin, "can't write index section header: %r");
freezblock(b); freezblock(b);
return -1; return -1;

View file

@ -80,7 +80,7 @@ ereadpart(Part *p, u64int offset, u8int *buf, u32int count)
int int
ewritepart(Part *p, u64int offset, u8int *buf, u32int count) ewritepart(Part *p, u64int offset, u8int *buf, u32int count)
{ {
if(writepart(p, offset, buf, count) != count){ if(writepart(p, offset, buf, count) != count || flushpart(p) < 0){
chat("%T writepart %s at %#llux+%ud: %r\n", p->name, offset, count); chat("%T writepart %s at %#llux+%ud: %r\n", p->name, offset, count);
return -1; return -1;
} }

View file

@ -16,16 +16,6 @@
#include "dat.h" #include "dat.h"
#include "fns.h" #include "fns.h"
/* TODO for linux:
don't use O_DIRECT.
use
posix_fadvise(fd, 0, 0, POSIX_FADV_NOREUSE);
after block is read and also use
posix_fadvise(fd, 0, 0, POSIX_FADV_RANDOM);
to disable readahead on the index partition.
bump block size of bloom filter higher.
*/
u32int maxblocksize; u32int maxblocksize;
int readonly; int readonly;
@ -116,6 +106,9 @@ initpart(char *name, int mode)
mode &= (OREAD|OWRITE|ORDWR); mode &= (OREAD|OWRITE|ORDWR);
mode |= OREAD; mode |= OREAD;
} }
#ifdef __linux__ /* sorry, but linus made O_DIRECT unusable! */
mode &= ~ODIRECT;
#endif
part->fd = open(file, mode); part->fd = open(file, mode);
if(part->fd < 0){ if(part->fd < 0){
if((mode&(OREAD|OWRITE|ORDWR)) == ORDWR) if((mode&(OREAD|OWRITE|ORDWR)) == ORDWR)
@ -130,6 +123,9 @@ initpart(char *name, int mode)
} }
fprint(2, "warning: %s opened for reading only\n", name); fprint(2, "warning: %s opened for reading only\n", name);
} }
#ifdef __linux__ /* sorry again! still linus's fault! */
posix_fadvise(part->fd, 0, 0, POSIX_FADV_RANDOM); /* disable readahead */
#endif
part->offset = lo; part->offset = lo;
dir = dirfstat(part->fd); dir = dirfstat(part->fd);
if(dir == nil){ if(dir == nil){
@ -166,9 +162,18 @@ initpart(char *name, int mode)
return part; return part;
} }
void int
flushpart(Part *part) flushpart(Part *part)
{ {
USED(part);
#ifdef __linux__ /* grrr! */
if(fsync(part->fd) < 0){
logerr(EAdmin, "flushpart %s: %r", part->name);
return -1;
}
posix_fadvise(part->fd, 0, 0, POSIX_FADV_DONTNEED);
#endif
return 0;
} }
void void
@ -420,6 +425,9 @@ rwpart(Part *part, int isread, u64int offset, u8int *buf, u32int count)
#endif #endif
break; break;
} }
#ifdef __linux__ /* sigh */
posix_fadvise(part->fd, part->offset+offset, n, POSIX_FADV_DONTNEED);
#endif
return n; return n;
} }
int int

View file

@ -23,5 +23,8 @@ zeropart(Part *part, int blocksize)
if(writepart(part, addr, b->data, blocksize) < 0) if(writepart(part, addr, b->data, blocksize) < 0)
sysfatal("can't initialize %s: %r", part->name); sysfatal("can't initialize %s: %r", part->name);
if(flushpart(part) < 0)
sysfatal("can't flush writes to %s: %r", part->name);
freezblock(b); freezblock(b);
} }