ape: get rid of fixed MUXADDR for buffered i/o

instead of trying to resize the segment (which will not work when
the kernel picks the address as it will allocate right before
the base of the topmost segment), we create the mux segment with the
maximum size needed (arround 1.4MB) for OPEN_MAX filedescriptors.

buf slots will be reused and slots get demand paged once used.
This commit is contained in:
cinap_lenrek 2013-05-03 19:34:48 +02:00
parent e8efd0a242
commit 9de8d61fe6

View file

@ -20,10 +20,9 @@ typedef struct Muxseg {
int waittime; /* time for timer process to wait */
fd_set rwant; /* fd's that select wants to read */
fd_set ewant; /* fd's that select wants to know eof info on */
Muxbuf bufs[INITBUFS]; /* can grow, via segbrk() */
Muxbuf bufs[OPEN_MAX];
} Muxseg;
#define MUXADDR ((void*)0x6000000)
static Muxseg *mux = 0; /* shared memory segment */
/* _muxsid and _killmuxsid are known in libbsd's listen.c */
@ -50,14 +49,13 @@ static int copynotehandler(void *, char *);
int
_startbuf(int fd)
{
long i, slot;
int pid, sid;
int i, pid, sid;
Fdinfo *f;
Muxbuf *b;
if(mux == 0){
_RFORK(RFREND);
mux = (Muxseg*)_SEGATTACH(0, "shared", MUXADDR, sizeof(Muxseg));
mux = (Muxseg*)_SEGATTACH(0, "shared", 0, sizeof(Muxseg));
if((long)mux == -1){
_syserrno();
return -1;
@ -66,7 +64,7 @@ _startbuf(int fd)
atexit(_killmuxsid);
}
if(fd == -1)
if(fd < 0)
return 0;
lock(&mux->lock);
@ -85,17 +83,16 @@ _startbuf(int fd)
errno = EIO;
return -1;
}
slot = mux->curfds++;
if(mux->curfds > INITBUFS) {
if(_SEGBRK(mux, mux->bufs+mux->curfds) < 0){
_syserrno();
unlock(&mux->lock);
return -1;
}
for(b = mux->bufs; b < &mux->bufs[mux->curfds]; b++)
if(b->fd == -1)
goto Found;
if(mux->curfds >= OPEN_MAX){
unlock(&mux->lock);
errno = ENFILE;
return -1;
}
b = &mux->bufs[slot];
mux->curfds++;
Found:
b->n = 0;
b->putnext = b->data;
b->getnext = b->data;