Memory Status

Name

Memory Status -- Status of the memory.

Synopsis


struct      frame_info_t;
enum        mem_frame_flags_t;
#define     FRAME_LOCKED                    (frame)
#define     FRAME_REFERENCED                (frame)
#define     FRAME_MODIFIED                  (frame)
struct      proc_pages_info_t;
#define     PAGE_VALID                      (proc_pages, page)
#define     NO_FRAME
#define     NO_PAGE
#define     NO_PROC
#define     NO_BLOCK
void        init_page_info                  (void);
frame_info_t* get_free_frame                (void);
void        put_free_frame                  (gint frame);
gboolean    have_free_frame                 (void);
frame_info_t* get_frame_info                (gint frame);
frame_info_t* get_frames_list               (void);
frame_info_t* mem_frames_next               (frame_info_t *frame);
proc_pages_info_t* get_proc_pages           (gint pid,
                                             gboolean creat);
proc_pages_info_t* get_proc_pages_list      (void);
proc_pages_info_t* proc_pages_next          (proc_pages_info_t *pages);
gint        virt_to_phys                    (gint pid,
                                             gint page);
void        mem_page_invalid                (gint pid,
                                             gint page);
gint        mem_assign_frame                (gint pid,
                                             gint page,
                                             gint frame);
void        mem_page_valid                  (gint pid,
                                             gint page);

Description

Here is descrived show to find out the status of memory, the frames available, what process they belong to, valid and invalid pages...

Details

struct frame_info_t

typedef struct {		/* what there is to know about a frame */
	gint frame;		/* frame number */
	gint proc;		/* process it belongs to or NO_PROC */
	gint page;		/* page it belongs to of NO_PAGE */
	guint32 flags;		/* See mem_frame_flags_t */
	guint32 private_flags;	/* algorithm dependet flags */
}frame_info_t;


enum mem_frame_flags_t

typedef enum {			/* bit indexes for frame flags */
	MEM_FRAME_LOCKED=0,	/* frame is locked and should not be
				   stolen of assigned */
	MEM_FRAME_REFERENCED,	/* frame has been referenced recently */
	MEM_FRAME_MODIFIED	/* frame is modified and should be writen to
				   swap if stolen */
} mem_frame_flags_t;


FRAME_LOCKED()

#define FRAME_LOCKED(frame) (test_bit(MEM_FRAME_LOCKED, &frame->flags))

Test whether frame is locked.

frame : frame involved.


FRAME_REFERENCED()

#define FRAME_REFERENCED(frame) (test_bit(MEM_FRAME_REFERENCED, &frame->flags))

Test whether frame has been referenced.

frame : frame involved.


FRAME_MODIFIED()

#define FRAME_MODIFIED(frame) (test_bit(MEM_FRAME_MODIFIED, &frame->flags))

Test whether frame has been modified.

frame : frame involved.


struct proc_pages_info_t

typedef struct {			/* memory related information for a
					   process */
	gint pid;			/* process id of the process */
	gint n_pages;			/* number of pages its using */
	guint32 bitmap;			/* bitmap of valid pages */
	frame_info_t *frame[MAX_PAGES];	/* frames where the pages are stored*/
	gint block[MAX_PAGES];		/* swap blocks assigned to pages */
	GSList *node;			/* GSList link this struct is hanging
					   from */
} proc_pages_info_t;


PAGE_VALID()

#define PAGE_VALID(proc_pages, page) (proc_pages->bitmap & (1<<page))

Test whether page is valid in proc_pages.

proc_pages : process memory information.
page : page involved.


NO_FRAME

#define NO_FRAME -1	/* frame number when there is no frame */


NO_PAGE

#define NO_PAGE -1	/* page number when there is no page */


NO_PROC

#define NO_PROC -1	/* process number when there is no process */


NO_BLOCK

#define NO_BLOCK -1	/* block number when there is no block */


init_page_info ()

void        init_page_info                  (void);

Initialize the code which keeps track of pages and frames.


get_free_frame ()

frame_info_t* get_free_frame                (void);

Returns : a free frame if any, NULL otherwise.


put_free_frame ()

void        put_free_frame                  (gint frame);

Give back a frame to be returned by get_free_frame later.

frame : frame to return.


have_free_frame ()

gboolean    have_free_frame                 (void);

Returns : TRUE if we have free memory frames available.


get_frame_info ()

frame_info_t* get_frame_info                (gint frame);

frame : frame involved.
Returns : frame's information data.


get_frames_list ()

frame_info_t* get_frames_list               (void);

Returns : the first element on the list of frame information structures.


mem_frames_next ()

frame_info_t* mem_frames_next               (frame_info_t *frame);

frame : a frame information structure.
Returns : the next frame information structure or NULL if frame is the last element.


get_proc_pages ()

proc_pages_info_t* get_proc_pages           (gint pid,
                                             gboolean creat);

Retrives the memory related information for pid.

If there is no memory information for pid and creat is TRUE the information will be created.

pid : process involved.
creat : it TRUE a process information structure will be created.
Returns : memory information for pid if applyable of NULL otherwise.


get_proc_pages_list ()

proc_pages_info_t* get_proc_pages_list      (void);

Returns : the first element of the memory infomation structures.


proc_pages_next ()

proc_pages_info_t* proc_pages_next          (proc_pages_info_t *pages);

pages : a process' memory information structure.
Returns : then next memory information structure or NULL if pages is the last element.


virt_to_phys ()

gint        virt_to_phys                    (gint pid,
                                             gint page);

pid : process involved.
page : a page in pid's virtual memory.
Returns : the frame number coresponding to page in pid's address space or NO_FRAME if there is non assigned.


mem_page_invalid ()

void        mem_page_invalid                (gint pid,
                                             gint page);

Makes page of pid's address space invalid so pid will incure a page fault if it tryes to use it.

pid : process involved.
page : invalid page.


mem_assign_frame ()

gint        mem_assign_frame                (gint pid,
                                             gint page,
                                             gint frame);

Assings frame to page in pid's address space.

pid : process involved.
page : a page in pid's address space.
frame : a free frame.
Returns : 0 if all went well -1 otherwise.


mem_page_valid ()

void        mem_page_valid                  (gint pid,
                                             gint page);

Makes page of pid's address space valid for pid to use.

pid : process involved.
page : valid page.