uint
memsize(void){ // Simply insert the memory size of the current process into size and return size
uint size;
struct proc *p;
p = myproc();
size = p->sz;
return size;
}
// test_memsize.c
#define SIZE 2048
#include "types.h"
#include "user.h"
int main(void){
int msize = memsize();
printf("The process is using %dB\n", msize); // output: 12288B
char *tmp = (char *)malloc(SIZE * sizeof(char));
printf("Allocating more memory\n");
msize = memsize();
printf("The process is using %dB\n", msize); // output: 45045B
free(tmp);
printf("Freeing memory\n");
msize = memsize();
printf("The process is using %dB\n", msize); //output: 45045B
exit();
}
The memory usage of the current process is 12288B and It was allocated as dynamic as 2048 bytes. But the result is 45045B. Why does this happen? (I'm using xv6.)