Memory mapping ordinary files in Unix file system anonymous files ...

feastcanadianΛογισμικό & κατασκευή λογ/κού

14 Δεκ 2013 (πριν από 3 χρόνια και 5 μήνες)

62 εμφανίσεις

Memory mapping

1.

ordinary files in Unix file system

2.

anonymous

files

How to share objects?

An object can be mapped to an area in the virtual memory as a sharing object or a private
one(
copy
-
on
-
write).

Function fork()

Function execve(a.out.NULL,NULL)

M
map function

#include<unistd.h>

#include<sys/mman.h>

Void*

mmap(void *start,size_t length, int prot, int flags, int fd, off_t offset)

It requires the kernel to create a new virtual memory an
d maps a series chunks which is pointed
by fd to this area.

Dynamical memory allocation

E
xplicit allocator

I
mplicit allocator

M
alloc() and free()

#include

csapp.h


I
nt main()

{

I
nt *array ,
I

, n;

S
canf(

%d

,&n)

A
rray = (int*)malloc(n*sizeof(int))

F
or
(i=0;i<n;i++)

S
canf(

%d

,array[i]);

E
xit(0);

}


Uk=maxPi/Hk


Fragmentation

I
mplicit free linked list

Placement policy:first fit,next fit,best fit.

C
ut and merge the free blocks.


A simple allocator

E
xtern int mm_init(void);

E
xtern void *mm_malloc(size_t

size);

E
xtern void mm_free(void *ptr);


E
xplicit linked list(LIFO)