basic sparepage optimisation
some simplification of linear/virtual address translation (less hardcoding and more use of arch_*2* functions)
This commit is contained in:
		
							parent
							
								
									f9e81cb57b
								
							
						
					
					
						commit
						581e68433a
					
				| @ -47,6 +47,7 @@ struct vmproc *vmp = &vmproc[VM_PROC_NR]; | |||||||
|  * page table. |  * page table. | ||||||
|  */ |  */ | ||||||
| #define SPAREPAGES 5 | #define SPAREPAGES 5 | ||||||
|  | int missing_spares = SPAREPAGES; | ||||||
| static struct { | static struct { | ||||||
| 	void *page; | 	void *page; | ||||||
| 	u32_t phys; | 	u32_t phys; | ||||||
| @ -204,8 +205,7 @@ PRIVATE void vm_freepages(vir_bytes vir, vir_bytes phys, int pages, int reason) | |||||||
| 		vm_assert(!(vir % I386_PAGE_SIZE));  | 		vm_assert(!(vir % I386_PAGE_SIZE));  | ||||||
| 		vm_assert(!(phys % I386_PAGE_SIZE));  | 		vm_assert(!(phys % I386_PAGE_SIZE));  | ||||||
| 		FREE_MEM(ABS2CLICK(phys), pages); | 		FREE_MEM(ABS2CLICK(phys), pages); | ||||||
| 		if(pt_writemap(&vmp->vm_pt, | 		if(pt_writemap(&vmp->vm_pt, arch_vir2map(vmp, vir), | ||||||
| 			vir + CLICK2ABS(vmp->vm_arch.vm_seg[D].mem_phys), |  | ||||||
| 			MAP_NONE, pages*I386_PAGE_SIZE, 0, WMF_OVERWRITE) != OK) | 			MAP_NONE, pages*I386_PAGE_SIZE, 0, WMF_OVERWRITE) != OK) | ||||||
| 				vm_panic("vm_freepages: pt_writemap failed", | 				vm_panic("vm_freepages: pt_writemap failed", | ||||||
| 					NO_NUM); | 					NO_NUM); | ||||||
| @ -221,12 +221,15 @@ PRIVATE void vm_freepages(vir_bytes vir, vir_bytes phys, int pages, int reason) | |||||||
| PRIVATE void *vm_getsparepage(u32_t *phys) | PRIVATE void *vm_getsparepage(u32_t *phys) | ||||||
| { | { | ||||||
| 	int s; | 	int s; | ||||||
|  | 	vm_assert(missing_spares >= 0 && missing_spares <= SPAREPAGES); | ||||||
| 	for(s = 0; s < SPAREPAGES; s++) { | 	for(s = 0; s < SPAREPAGES; s++) { | ||||||
| 		if(sparepages[s].page) { | 		if(sparepages[s].page) { | ||||||
| 			void *sp; | 			void *sp; | ||||||
| 			sp = sparepages[s].page; | 			sp = sparepages[s].page; | ||||||
| 			*phys = sparepages[s].phys; | 			*phys = sparepages[s].phys; | ||||||
| 			sparepages[s].page = NULL; | 			sparepages[s].page = NULL; | ||||||
|  | 			missing_spares++; | ||||||
|  | 			vm_assert(missing_spares >= 0 && missing_spares <= SPAREPAGES); | ||||||
| 			return sp; | 			return sp; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| @ -241,11 +244,14 @@ PRIVATE void *vm_checkspares(void) | |||||||
| { | { | ||||||
| 	int s, n = 0; | 	int s, n = 0; | ||||||
| 	static int total = 0, worst = 0; | 	static int total = 0, worst = 0; | ||||||
| 	for(s = 0; s < SPAREPAGES; s++) | 	vm_assert(missing_spares >= 0 && missing_spares <= SPAREPAGES); | ||||||
|  | 	for(s = 0; s < SPAREPAGES && missing_spares > 0; s++) | ||||||
| 	    if(!sparepages[s].page) { | 	    if(!sparepages[s].page) { | ||||||
| 		n++; | 		n++; | ||||||
| 		sparepages[s].page = vm_allocpages(&sparepages[s].phys, 1, | 		sparepages[s].page = vm_allocpages(&sparepages[s].phys, 1, | ||||||
| 			VMP_SPARE); | 			VMP_SPARE); | ||||||
|  | 		missing_spares--; | ||||||
|  | 		vm_assert(missing_spares >= 0 && missing_spares <= SPAREPAGES); | ||||||
| 	} | 	} | ||||||
| 	if(worst < n) worst = n; | 	if(worst < n) worst = n; | ||||||
| 	total += n; | 	total += n; | ||||||
| @ -293,7 +299,7 @@ PUBLIC void *vm_allocpages(phys_bytes *phys, int pages, int reason) | |||||||
| 	 * Where in our virtual address space can we put it? | 	 * Where in our virtual address space can we put it? | ||||||
| 	 */ | 	 */ | ||||||
| 	loc = findhole(pt, I386_PAGE_SIZE * pages, | 	loc = findhole(pt, I386_PAGE_SIZE * pages, | ||||||
| 		CLICK2ABS(vmp->vm_arch.vm_seg[D].mem_phys) + vmp->vm_stacktop, | 		arch_vir2map(vmp, vmp->vm_stacktop), | ||||||
| 		vmp->vm_arch.vm_data_top); | 		vmp->vm_arch.vm_data_top); | ||||||
| 	if(loc == NO_MEM) { | 	if(loc == NO_MEM) { | ||||||
| 		level--; | 		level--; | ||||||
| @ -320,7 +326,7 @@ PUBLIC void *vm_allocpages(phys_bytes *phys, int pages, int reason) | |||||||
| 	level--; | 	level--; | ||||||
| 
 | 
 | ||||||
| 	/* Return user-space-ready pointer to it. */ | 	/* Return user-space-ready pointer to it. */ | ||||||
| 	return (void *) (loc - CLICK2ABS(vmp->vm_arch.vm_seg[D].mem_phys)); | 	return (void *) arch_map2vir(vmp, loc); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /*===========================================================================*
 | /*===========================================================================*
 | ||||||
| @ -479,8 +485,7 @@ PUBLIC int pt_new(pt_t *pt) | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	/* Where to start looking for free virtual address space? */ | 	/* Where to start looking for free virtual address space? */ | ||||||
| 	pt->pt_virtop = VM_STACKTOP + | 	pt->pt_virtop = 0; | ||||||
| 		CLICK2ABS(vmproc[VMP_SYSTEM].vm_arch.vm_seg[D].mem_phys); |  | ||||||
| 
 | 
 | ||||||
| 	return OK; | 	return OK; | ||||||
| } | } | ||||||
| @ -514,6 +519,8 @@ PUBLIC void pt_init(void) | |||||||
|                         I386_PAGE_SIZE, &sparepages[s].phys)) != OK) |                         I386_PAGE_SIZE, &sparepages[s].phys)) != OK) | ||||||
|                         vm_panic("pt_init: sys_umap failed", r); |                         vm_panic("pt_init: sys_umap failed", r); | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  | 	missing_spares = 0; | ||||||
|          |          | ||||||
|         /* Make new page table for ourselves, partly copied
 |         /* Make new page table for ourselves, partly copied
 | ||||||
|          * from the current one. |          * from the current one. | ||||||
| @ -594,8 +601,7 @@ PUBLIC void pt_init(void) | |||||||
|         /* Where our free virtual address space starts.
 |         /* Where our free virtual address space starts.
 | ||||||
|          * This is only a hint to the VM system. |          * This is only a hint to the VM system. | ||||||
|          */ |          */ | ||||||
|         newpt->pt_virtop = (vmp->vm_arch.vm_seg[S].mem_vir + |         newpt->pt_virtop = 0; | ||||||
|                 vmp->vm_arch.vm_seg[S].mem_len) << CLICK_SHIFT; |  | ||||||
| 
 | 
 | ||||||
|         /* Let other functions know VM now has a private page table. */ |         /* Let other functions know VM now has a private page table. */ | ||||||
|         vmp->vm_flags |= VMF_HASPT; |         vmp->vm_flags |= VMF_HASPT; | ||||||
| @ -604,13 +610,12 @@ PUBLIC void pt_init(void) | |||||||
|          * can use to map in arbitrary physical pages. |          * can use to map in arbitrary physical pages. | ||||||
|          */ |          */ | ||||||
|         varmap_loc = findhole(newpt, I386_PAGE_SIZE, |         varmap_loc = findhole(newpt, I386_PAGE_SIZE, | ||||||
|                 CLICK2ABS(vmp->vm_arch.vm_seg[D].mem_phys) + vmp->vm_stacktop, |                 arch_vir2map(vmp, vmp->vm_stacktop), | ||||||
|                 vmp->vm_arch.vm_data_top); |                 vmp->vm_arch.vm_data_top); | ||||||
|         if(varmap_loc == NO_MEM) { |         if(varmap_loc == NO_MEM) { | ||||||
|                 vm_panic("no virt addr for vm mappings", NO_NUM); |                 vm_panic("no virt addr for vm mappings", NO_NUM); | ||||||
|         } |         } | ||||||
|         varmap = (unsigned char *) (varmap_loc - |         varmap = (unsigned char *) arch_map2vir(vmp, varmap_loc); | ||||||
|                 CLICK2ABS(vmp->vm_arch.vm_seg[D].mem_phys)); |  | ||||||
| 
 | 
 | ||||||
|         /* All OK. */ |         /* All OK. */ | ||||||
|         return; |         return; | ||||||
|  | |||||||
| @ -31,6 +31,8 @@ | |||||||
| #include "vm.h" | #include "vm.h" | ||||||
| #include "sanitycheck.h" | #include "sanitycheck.h" | ||||||
| 
 | 
 | ||||||
|  | extern int missing_spares; | ||||||
|  | 
 | ||||||
| #include <archtypes.h> | #include <archtypes.h> | ||||||
| #include "../../kernel/const.h" | #include "../../kernel/const.h" | ||||||
| #include "../../kernel/config.h"  | #include "../../kernel/config.h"  | ||||||
| @ -95,7 +97,9 @@ PUBLIC int main(void) | |||||||
| 	int r, c; | 	int r, c; | ||||||
| 
 | 
 | ||||||
| 	SANITYCHECK(SCL_TOP); | 	SANITYCHECK(SCL_TOP); | ||||||
| 	pt_cycle();	/* pagetable code wants to be called */ | 	if(missing_spares > 0) { | ||||||
|  | 		pt_cycle();	/* pagetable code wants to be called */ | ||||||
|  | 	} | ||||||
| #if SANITYCHECKS | #if SANITYCHECKS | ||||||
| 	slabstats(); | 	slabstats(); | ||||||
| #endif | #endif | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Ben Gras
						Ben Gras