9 ulong pgsize, userpgs, userused;
15 pgsize = userpgs = userused = 0;
16 if(bp = Bopen("/dev/swap", OREAD)) {
17 while(s = Brdline(bp, '\n')) {
18 if((n = Blinelen(bp)) < 1)
21 if(tokenize(s, f, nelem(f)) != 2)
23 if(strcmp(f[1], "pagesize") == 0)
24 pgsize = strtoul(f[0], 0, 0);
25 else if(strcmp(f[1], "user") == 0) {
26 userused = strtoul(f[0], &s, 0);
28 userpgs = strtoul(s+1, 0, 0);
33 if(pgsize && userused < userpgs){
35 if(s = getenv("fsmempercent")){
41 userpgs = (userpgs*mpcnt)/100;
42 return (uvlong)userpgs*pgsize;
52 * Called to allocate permanent data structures
53 * Alignment is in number of bytes. It pertains both to the start and
54 * end of the allocated memory.
57 ialloc(uintptr n, int align)
63 align = sizeof(uintptr);
65 mainmem->lock(mainmem);
70 if(m = (uintptr)p % align)
73 panic("ialloc: out of memory");
75 mainmem->unlock(mainmem);
80 enum { HWIDTH = 8 }; /* buffers per hash */
83 * allocate rest of mem
94 wlock(&mainlock); /* init */
97 niob = memsize() / (sizeof(Iobuf) + RBUFSIZE + sizeof(Hiob)/HWIDTH);
98 nhiob = niob / HWIDTH;
102 print("\t%ud buffers; %ud hashes\n", niob, nhiob);
103 hiob = ialloc((uintptr)nhiob * sizeof(Hiob), 0);
105 for(i=0; i<nhiob; i++) {
110 p = ialloc((uintptr)niob * sizeof(Iobuf), 0);
111 xiop = ialloc((uintptr)niob * RBUFSIZE, 0);
113 for(i=0; i < niob; i++) {
133 p->iobuf = (char*)-1;
142 return p->iobuf = p->xiobuf;
148 p->iobuf = (char*)-1;