以下代码在xv6(risc—v)中执行.我有点糊涂了.为什么在malloc()之后需要madvise()? 是否用于页面表条目交换/交换?
PS. vmprint()打印页面表.
#include "kernel/types.h"
#include "kernel/stat.h"
#include "user/user.h"
#include "kernel/vm.h"
#define PG_SIZE 4096
#define NR_PG 16
int main(int argc, char *argv[]) {
vmprint();
char *ptr = malloc(NR_PG * PG_SIZE);
vmprint();
madvise((uint64) ptr + 10*PG_SIZE, 2*PG_SIZE , MADV_NORMAL);
vmprint();
madvise((uint64) ptr + 10*PG_SIZE, 2*PG_SIZE , MADV_DONTNEED);
vmprint();
madvise((uint64) ptr + 10*PG_SIZE, 2*PG_SIZE , MADV_WILLNEED);
vmprint();
exit(0);
}