ºìÁªLinuxÃÅ»§
Linux°ïÖú

linuxѧϰ¶þÄÚ´æ¹ÜÀíÖØÒªµÄÊý¾Ý½á¹¹

·¢²¼Ê±¼ä:2008-05-15 15:45:20À´Ô´:ºìÁª×÷Õß:Dopsdck
ÕâÀïÖ»Áоټ¸¸ö±È½ÏÂé·³µÄÊý¾Ý½á¹¹

struct list_head {
struct list_head *next, *prev;
} //linuxͨÓõÄË«ÏòÁ´¶ÓÁУ¬ÏÂÃæ¶à´¦Óõ½£¬ÕâÀïÁгöÔ´´úÂë

linux¶ÔÄÚ´æÔÙÓÃҳʽ¹ÜÀí£¬¶ÔÓÚÒ³£¬¾ÍÓиöÊý¾Ý½á¹¹page¼ÓÒÔÃèÊö¡£ÔÚÄÚºËÖÐÓиöÈ«¾ÖÁ¿mem-mapÖ¸ÏòµÄÊÇÒ»¸öpageµÄÊý×飬Õû¸öÊý×éÃèÊöÁËÕû¸öÎïÀíÄڴ棬´ó¼Ò×¢Òâ32λµØÖ·Ïߣ¬ÄÚ´æ´óСÊÇ2µÄ32´Î·½¡£ÓÉÓÚÒ³´óСÊÇ4kÒ²¾ÍÊÇ2µÄ12´Î·½¡£Ã¿4KµÄÒ³¾ÍÓÐÒ»¸öpage¡£ÄÇô2µÄ32´Î·½¹²ÓÐ2µÄ20´Î·½¸öÒ³£¬Ôòmem-mapÖ¸ÏòµÄÊý×é´óС¾ÍÊÇ2µÄ20´Î·½¡£ÆäÖÐÃ÷ÏÔ¶ÔÓÚÒ³µÄÎïÀíµØÖ·£¬Ò»¶¨ÊÇ4KµÄ±¶Êý£¬ÒòΪËü´óСÊÇ4K£¬ÄÇôÕâ¸öÊý×é¾ÍÓиö¶ÔÓ¦£¬Êý×éϱêºóÃæ12¸ö0£¨2½øÖÆ£©¶ÔÓ¦ÁËÒ³ÃæµÄÎïÀíµØÖ·£¬ËûÃÇÔÚÊýÖµÉÏÊÇÏàµÈµÄ¡£ÄÇôÎÒÃÇÔÚpageÊý¾Ý½á¹¹ÖоÍûÓбØÒª´æÖüËüµÄÎïÀíµØÖ·¡£pageÊý¾Ý½á¹¹¶¨ÒåλÖÃinclude/linux/mm.h

struct page{

struct list_head list; //ͨ¹ýʹÓÃËü½øÈëÏÂÃæµÄÊý¾Ý½á¹¹free_area_struct½á¹¹ÖеÄË«ÏòÁ´¶ÓÁÐ

struct address_space * mapping;

unsigned long index;

struct page *next_hash; //×ÔÉíµÄÖ¸Õ룬ÕâÑù¾Í¿ÉÒÔÁ´½Ó³ÉÒ»¸öÁ´±í

atomic t count;

unsigned long flags;

struct list_head lru;

unsigned long age;

wait_queue_head_t wait;

struct page ** pprev_hash;

struct buffer_head * buffers;

void * virtual

struct zone_struct * zone;

}

(¶ÔÓÚÿ¸öÏîµÄ˵Ã÷£¬ÎÒ»áÂýÂý²¹ÉÏ£©

¶ÔÄڴ棬½ö½öÓÃpageÊý¾Ý½á¹¹À´ÃèÊö¿Ï¶¨Ô¶Ô¶²»¹»£¬¶ÔÓÚÕû¸öÄڴ棬ÎÒÃÇÔÚ´ËÖ®ÉÏ·ÖÁ˹ÜÀíÇøµÄ¸ÅÄÿ¸ö¹ÜÀíÇø¹ÜÀíÊý¸öÒ³Ãæ¡£ÎÒÃÇÏȲ»¹ØÐÄÕâ¸öÓÐʲôÓã¬ÎÒÃÇÏÈÖªµÀÕâ¸öÊÇÔõô»ØÊ¡£Õâ¸öÊý¾Ý½á¹¹ÊÇ zone_struct¶¨ÒåλÖÃÊÇÔÚinclude/linux/mmzone.h

typedef struct free_area_struct {
struct list_head free_list; //linux ÖÐͨÓõÄË«ÏòÁ´¶ÓÁÐ
unsigned int * map;
} free_area_t;

typedef struct zone_struct{

spinlock_t lock;

unsigned long offset; //±íʾ¸Ã¹ÜÀíÇøÔÚmem-mapÊý×éÖУ¬ÆðʼµÄÒ³ºÅ

unsigned long free pages;
unsigned long inactive_clean_pages;
unsigned long inactive_dirty_pages;
unsigned pages_min, pages_low, pages_high;

struct list_head inactive_clean_list;
free_area_t free_area[MAX_ORDER]; //Ò»×é¡°¿ÕÏÐÇø¼ä¡±¶ÓÁУ¬free_area_t¶¨ÒåÔÚÉÏÃæ

char * name;
unsigned long size;

struct pglist_data * zone_pgdat; //ÓÃÓÚÖ¸ÏòËüËùÊôµÄ´æÖü½Úµã£¬¼°ÏÂÃæµÄÊý¾Ý½á¹¹
unsigned long zone_start_paddr;
unsigned long zone_start_mapnr;
struct page * zone_mem_map;

} zone_t;

ÎÒÃÇÖªµÀÄÚ´æµÄµØλ²¢²»ÊÇ¡°Æ½µÈµÄ¡±£¬ÀýÈçÖ÷ÄÚ´æºÍͼÐο¨Éϵľ²Ì¬ÄÚ´æram¾Í²»ÊÇ¡°Æ½µÈµØλ¡±£¬Òò´ËÎÒÃÇÒ³Ãæ¹ÜÀí»úÖÆ×öÁËÐÞÕý£¬¹ÜÀíÇø²»ÊÇÄÚ´æ¹ÜÀíÖÐ×î¸ß²ãµÄ¸ÅÄǰÊöµÄpageÊý×émem-mapÒ²²»ÊÇÈ«¾Ö£¬¶øÊÇ´ÓÊôÓÚ¾ßÌåµÄ½Úµã£¬ÔÚzone_struct ÉÏÃæÓÐÁËÒ»²ã´ú±í´æÖü½ÚµãµÄÊý¾Ý½á¹¹pglist_data£¬¶¨ÒåÓÚinclude/linux/mmzone.h ÖÐ

typedef struct pglist_data {
zone_t node_zones[MAX_NR_ZONES]; //¸Ã½Úµã×î¶àµÄ3¸öÒ³Ãæ¹ÜÀíÇø£¬MAX_NR_ZONEÖµÊÇ3£¬ÔÚlinuxÖзÖΪ3¸ö¹ÜÀíÇø£¬Ò²¿ÉÄÜÊÇ2¸öZONE_DMA,ZONE_NORMAL,ZONE_HIGHMEM
zonelist_t node_zonelist[NR_GFPINDEX]; //¾ßÌå˵Ã÷¼ûÏÂÃæµÄÊý¾Ý½á¹¹
struct page * node_mem_map; //ÓÃÓÚÖ¸ÏòÊôÓڸô洢½ÚµãµÄpageÊý×é
unsigned long * valid_addr_bitmap;
struct bootmem_data * bdata;
unsigned long node_start_paddr;
unsigned long node_start_mapnr;
unsigned long node_size;
int node_id;
struct pglistdata * node_next; //ÓÃÓÚÐγÉÒ»¸öµ¥Á´¶ÓÁÐ
} pg_data_t;

typedef struct zonelist_struct {
zone_t * zones [MAX_NR_ZONES+1]; //Ö¸ÕëÊý×飬ָÏòÿ¸ö¾ßÌåµÄÒ³Ãæ¹ÜÀíÇø
int gfp_mask;
} zonelist_t;

ÕâЩ¶¼ÊÇÓÃÓÚÎïÀí¿Õ¼ä¹ÜÀíµÄ£¬ÐéÄâ¿Õ¼ä¹ÜÀíÓÉÏÂÃæµÄÊý¾Ý½á¹¹ÃèÊö£¨ÎÒ¸Õ¿ªÊ¼°ÑÐéÄâ¿Õ¼äŪ³ÉÁËÐéÄâÄڴ棬Խ¿´Ô½ºýÍ¿£¬ÐéÄâ¿Õ¼äÖ¸µÄÊÇ£¬ÔÚlinuxÖУ¬4GÄÚ´æ±»·ÖΪ2¿é£¬¸ãµØÖ·1GÄÚ´æ½Ðϵͳ¿Õ¼ä£¬ËùÓнø³Ì¹²Ïí£¬ÏÂÃæµÄ3G±ãÊÇÐéÄâ¿Õ¼ä£¬Ã¿¸ö½ø³Ì¶¼Õ¼ÓÐÐéÄâ¿Õ¼ä3G£¬ÔÚ½ø³Ì×Ô¼º¿´À´ÊÇÕâÑùµÄ£¬µ«Êµ¼ÊÉÏ£¬ËûԶԶûÕâô¶àÄÚ´æÓã©£¬vm_area_structÊý¾Ý½á¹¹£¬¶¨ÒåÓÚ include/linux/mm.h

struct vm_area_struct {
struct mm_struct * vm_mm; //ÏÂÃæ˵Ã÷
unsigned long vm_start;
unsigned long vm_end; //startºÍend¾ö¶¨ÁËÐé´æ¿Õ¼ä£¬¸öÈËÀí½âÓ¦¸ÃÊÇmem-map±íµÄϱ꣬ÆäÖÐ start°üº¬£¬end²»°üº¬£¬Í¬Ê±Çø¼ä»®·Ö²»µ¥µ¥ÊǵØÖ·Á¬Ðø£¬»¹Òª±£Ö¤È¨ÏÞµÄͳһ

struct vm_area_struct * vm_next; //½«ÊôÓÚͬһ½ø³ÌµÄÐé´æÇø¼ä°´ÕÕÐé´æµØÖ·¸ßµÍÁ´½ÓÆðÀ´

pgrot t_vm_page_prot;
unsigned long vm_flags; //´æÖü¸ÃÇø¼äµÄȨÏÞ

short vm_avl_height;
struct vm_area_struct * vm_avl_left;
struct vm_area_struct * vm_avl_rigth; //ÓÃÓÚÉú³É avlÊ÷£¬Ìá¸ßËÑË÷ЧÂÊ

struct vm_area_struct * vm_next_share;
struct vm_area_struct ** vm_pprev_share;

struct vm_operations_struct * vm_ops; //ÏÂÃæ˵Ã÷
unsigned long vm_pgoff;

struct file * vm_file;
unsigned long vm_raend;
void * vm_private_data; //ÕâЩÊôÐÔ¶¼ÊÇÓÃÓڼǼҳÃæÓëÎļþ¹Øϵ£¬¾ßÌåÇé¿ö¾ßÌå·ÖÎö
}

¶¨ÒåÓÚinclude/linux/mm.h

struct vm_operations_struct {
void (*open) (struct vm_area_struct * area);
void (*close) (struct vm_area_struct * area);
struct page * (*nopage)(struct vm_area_struct *area, unsigned long address, int write_access);
} //open, close,nopageÓÃÓÚÐé´æ¿Õ¼ä´ò¿ª£¬¹Ø±ÕºÍ½¨Á¢Ó¡Éä



¶¨ÒåÓÚinclude/linux/sched.h

struct mm_struct{
struct vm_area_struct * mmap; //½¨Á¢Ðé´æ¿Õ¼äµÄµ¥Á´¶ÓÁÐ
struct vm_area_struct * mmap_avl; //½¨Á¢Ðé´æ¿Õ¼äµÄAVLÊ÷
struct vm_area_struct * mmap_cache; //×î½üÒ»´ÎʹÓõÄÐé´æ¿Õ¼ä£¬ÓÉÓÚÄÚ´æ·ÃÎÊ×ÜÊÇ´øÓоֲ¿ÐÔ£¬ÃüÖÐÂÊÓÐ35%
pgd_t * pgd; //Ö¸Ïò½ø³ÌÒ³ÃæĿ¼
atomic_t mm_users;
atomic_t mm_count;

int map_count;
struct semaphore mmap_sem; //ÓÃÓÚ½ø³ÌµÄ¼äµÄ»¥³â·ÃÎÊ
spinlock_t page_table_lock;

struct list_head mmlist;

unsigned long start_code, end_code, start_data, end_data
unsigned long start_brk, brk, start_stack;
unsigned long arg_start, arg_end, env_start, env_end;
unsigned long rss, total_vm, locked_vm;
unsigned long def_flags;
unsigned long cpu_vm_mask;
unsigned long swap_cnt;
unsigned long swap_address;
mm_context_t context;
}

ÔÚ²Ù×÷ϵͳÖУ¬Óиö½ø³Ì¿ØÖƿ飨PCB£©µÄ¸ÅÄ¾ßÌåµ½linuxÀïÃæ¶ÔÓ¦µÄÊý¾Ý½á¹¹ÊÇtask_struct£¬ËüÄÚ²¿¾ÍÓиömm_structÖ¸Õ룬mm_structÊÇÕû¸öÓû§¿Õ¼äµÄ³éÏó¡£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 1 ÌõÆÀÂÛ

  1. lijiang ÓÚ 2012-01-09 22:33:28·¢±í:

    ÉîÈëÒ»²½µÄÀí½â£¬»¹Êǵþ²Ñ§Êý¾Ý½á¹¹Ô­Àí