mit-pdos / xv6-riscv

Xv6 for RISC-V
Other
6.58k stars 2.38k forks source link

user/sysinfotest.c : is there a bug? #190

Open qin-you opened 1 year ago

qin-you commented 1 year ago

int countfree() { uint64 sz0 = (uint64)sbrk(0); struct sysinfo info; int n = 0;

while(1){ if((uint64)sbrk(PGSIZE) == 0xffffffffffffffff){ / loop forever if there is no more mem originally?/ break; } n += PGSIZE; / undercount one if there is only one page left originally ?/ } }

ljluestc commented 8 months ago

include

include <sys/sysinfo.h>

int countfree() { uint64_t sz0 = (uint64_t)sbrk(0); struct sysinfo info; int n = 0;

while (1) {
    if ((uint64_t)sbrk(PGSIZE) == (uint64_t)-1) { /* Check if sbrk returns -1 when there's no more memory */
        break;
    }
    n += PGSIZE;
}

return n;

}