8 ulong userpgs = 0, userused = 0;
13 bp = Bopen("#c/swap", OREAD);
15 while ((ln = Brdline(bp, '\n')) != nil) {
16 ln[Blinelen(bp)-1] = '\0';
17 nf = tokenize(ln, fields, nelem(fields));
20 if (strcmp(fields[1], "pagesize") == 0)
21 pgsize = atoi(fields[0]);
22 else if (strcmp(fields[1], "user") == 0) {
23 sl = strchr(fields[0], '/');
27 userused = atol(fields[0]);
31 if (pgsize > 0 && userused < userpgs)
32 return (userpgs - userused)*pgsize;
43 * Called to allocate permanent data structures
44 * Alignment is in number of bytes. It pertains both to the start and
45 * end of the allocated memory.
48 ialloc(ulong n, int align)
50 void *p = mallocalign(n, align, 0, 0);
53 panic("ialloc: out of memory");
54 setmalloctag(p, getcallerpc(&n));
59 enum { HWIDTH = 8 }; /* buffers per hash */
62 * allocate rest of mem
74 wlock(&mainlock); /* init */
78 niob = m / (sizeof(Iobuf) + RBUFSIZE + sizeof(Hiob)/HWIDTH);
79 nhiob = niob / HWIDTH;
83 print("\t%ld buffers; %ld hashes\n", niob, nhiob);
84 hiob = ialloc(nhiob * sizeof(Hiob), 0);
86 for(i=0; i<nhiob; i++) {
91 p = ialloc(niob * sizeof(Iobuf), 0);
92 xiop = ialloc(niob * RBUFSIZE, 0);
94 for(i=0; i < niob; i++) {
114 p->iobuf = (char*)-1;
123 return p->iobuf = p->xiobuf;
129 p->iobuf = (char*)-1;