[lc-checkins] CVS: linux/mm/comp_cache aux.c,1.12,1.13 free.c,1.16,1.17 main.c,1.18,1.19 swapin.c,1.
Status: Beta
Brought to you by:
nitin_sf
From: Rodrigo S. de C. <rc...@us...> - 2002-01-16 16:30:17
|
Update of /cvsroot/linuxcompressed/linux/mm/comp_cache In directory usw-pr-cvs1:/tmp/cvs-serv2268/mm/comp_cache Modified Files: aux.c free.c main.c swapin.c swapout.c vswap.c Log Message: Simple changes regarding hash tables and some cleanups. - no need to enter a power of 2 number for the maximum number of compressed pages any longer. It's not increasing the hash table size in a dynamic way, but that will be done soon. - hash table initialization was changed to allocate contiguous pages for it, what increases a lot related functions' performance. - swapin_vswap() has been deleted. Not needed. - comp_cache_free() was renamed to comp_cache_free_locked() and the page is passed as paremeter has to be locked. comp_cache_free() function was created to handle cases where the page is not yet locked. Index: aux.c =================================================================== RCS file: /cvsroot/linuxcompressed/linux/mm/comp_cache/aux.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -r1.12 -r1.13 *** aux.c 2002/01/14 12:05:08 1.12 --- aux.c 2002/01/16 16:30:12 1.13 *************** *** 2,6 **** * linux/mm/comp_cache/aux.c * ! * Time-stamp: <2002-01-13 16:16:07 rcastro> * * Linux Virtual Memory Compressed Cache --- 2,6 ---- * linux/mm/comp_cache/aux.c * ! * Time-stamp: <2002-01-16 13:10:07 rcastro> * * Linux Virtual Memory Compressed Cache *************** *** 13,21 **** #include <linux/pagemap.h> #include <linux/init.h> ! comp_cache_fragment_t * fragment_hash[FRAGMENT_HASH_SIZE]; ! comp_cache_t * free_space_hash[FREE_SPACE_HASH_SIZE]; /* computes (unsigned long long x) / (unsigned long long y) */ unsigned long long --- 13,26 ---- #include <linux/pagemap.h> #include <linux/init.h> + #include <linux/vmalloc.h> ! comp_cache_fragment_t ** fragment_hash; ! unsigned int fragment_hash_size; + comp_cache_t ** free_space_hash; + unsigned int free_space_hash_size; + unsigned int free_space_interval; + /* computes (unsigned long long x) / (unsigned long long y) */ unsigned long long *************** *** 119,123 **** idx = free_space_hashfn(free_space); ! if (idx == FREE_SPACE_HASH_SIZE) goto check_exact_size; --- 124,128 ---- idx = free_space_hashfn(free_space); ! if (idx == free_space_hash_size) goto check_exact_size; *************** *** 127,131 **** do { comp_page = free_space_hash[i++]; ! } while(i < FREE_SPACE_HASH_SIZE && !comp_page); /* couldn't find a page? let's check the pages whose free --- 132,136 ---- do { comp_page = free_space_hash[i++]; ! } while(i < free_space_hash_size && !comp_page); /* couldn't find a page? let's check the pages whose free *************** *** 179,193 **** { comp_cache_fragment_t * fragment; *fragment_out = NULL; ! for (fragment = fragment_hash[fragment_hashfn(entry)]; fragment != NULL; fragment = fragment->next_hash) { if (fragment->index == entry.val) { *fragment_out = fragment; ! return (fragment->comp_page); } } ! ! return NULL; } --- 184,211 ---- { comp_cache_fragment_t * fragment; + comp_cache_t * comp_page; + comp_page = NULL; *fragment_out = NULL; + + fragment = fragment_hash[fragment_hashfn(entry)]; ! goto inside; ! ! for (;;) { ! fragment = fragment->next_hash; ! inside: ! if (!fragment) ! goto not_found; ! if (fragment->index == entry.val) { *fragment_out = fragment; ! comp_page = fragment->comp_page; ! break; } } ! ! not_found: ! return comp_page; } *************** *** 323,335 **** comp_cache_hash_init(void) { ! int i; ! /* inits fragment hash table */ ! for (i = 0; i < FRAGMENT_HASH_SIZE; i++) ! fragment_hash[i] = NULL; /* inits comp cache free space hash table */ ! for (i = 0; i < FREE_SPACE_HASH_SIZE; i++) ! free_space_hash[i] = NULL; } --- 341,383 ---- comp_cache_hash_init(void) { ! unsigned long htable_bits, order; ! ! /* (code heavily based on page_cache_init():filemap.c */ ! ! /* fragment hash table */ ! fragment_hash_size = 3* CONFIG_COMP_CACHE_SIZE * sizeof(comp_cache_fragment_t *); ! for (order = 0; (PAGE_SIZE << order) < fragment_hash_size; order++); ! ! do { ! unsigned long tmp = (PAGE_SIZE << order)/sizeof(comp_cache_fragment_t *); ! ! htable_bits = 0; ! while((tmp >>= 1UL) != 0UL) ! htable_bits++; ! ! fragment_hash = (comp_cache_fragment_t **) __get_free_pages(GFP_ATOMIC, order); ! } while(fragment_hash == NULL && --order > 0); ! ! fragment_hash_size = 1 << htable_bits; ! ! printk("Compressed Cache: fragment hash table - %u = %luB\n", fragment_hash_size, (PAGE_SIZE << order)); ! ! if (!fragment_hash) ! panic("comp_cache_hash_init(): couldn't allocate fragment hash table\n"); ! memset((void *) fragment_hash, 0, fragment_hash_size * sizeof(comp_cache_fragment_t *)); /* inits comp cache free space hash table */ ! free_space_interval = 100 * ((float) PAGE_SIZE)/4096; ! free_space_hash_size = (int) (PAGE_SIZE/free_space_interval) + 2; ! ! free_space_hash = vmalloc(free_space_hash_size * sizeof(comp_cache_t *)); ! ! printk("Compressed Cache: free space hash table - %u = %uB\n", free_space_hash_size, free_space_hash_size * sizeof(comp_cache_t *)); ! ! if (!free_space_hash) ! panic("comp_cache_hash_init(): couldn't allocate free space hash table\n"); ! ! memset((void *) free_space_hash, 0, free_space_hash_size * sizeof(comp_cache_t *)); } Index: free.c =================================================================== RCS file: /cvsroot/linuxcompressed/linux/mm/comp_cache/free.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -r1.16 -r1.17 *** free.c 2002/01/14 12:05:08 1.16 --- free.c 2002/01/16 16:30:12 1.17 *************** *** 2,6 **** * linux/mm/comp_cache/free.c * ! * Time-stamp: <2002-01-13 19:00:05 rcastro> * * Linux Virtual Memory Compressed Cache --- 2,6 ---- * linux/mm/comp_cache/free.c * ! * Time-stamp: <2002-01-14 16:13:12 rcastro> * * Linux Virtual Memory Compressed Cache *************** *** 70,75 **** } ! void ! comp_cache_free(comp_cache_fragment_t * fragment) { comp_cache_t * comp_page; --- 70,75 ---- } ! int ! comp_cache_free_locked(comp_cache_fragment_t * fragment) { comp_cache_t * comp_page; *************** *** 88,94 **** BUG(); - if (TryLockPage(comp_page->page)) - BUG(); - /* remove from the free space hash table to update it */ remove_comp_page_from_hash_table(comp_page); --- 88,91 ---- *************** *** 158,167 **** /* steal the page if we need to shrink the comp cache */ if (shrink_comp_cache(comp_page)) ! return; - add_comp_page_to_hash_table(comp_page); ! UnlockPage(comp_page->page); } int --- 155,183 ---- /* steal the page if we need to shrink the comp cache */ if (shrink_comp_cache(comp_page)) ! return 0; add_comp_page_to_hash_table(comp_page); ! ! return 1; ! } ! ! inline int ! comp_cache_free(comp_cache_fragment_t * fragment) { ! int retval = 0; ! ! if (!fragment) ! BUG(); ! ! if (TryLockPage(fragment->comp_page->page)) ! BUG(); ! ! retval = comp_cache_free_locked(fragment); ! ! if (retval) ! UnlockPage(fragment->comp_page->page); ! ! return retval; } + int Index: main.c =================================================================== RCS file: /cvsroot/linuxcompressed/linux/mm/comp_cache/main.c,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -r1.18 -r1.19 *** main.c 2002/01/14 12:05:08 1.18 --- main.c 2002/01/16 16:30:12 1.19 *************** *** 2,6 **** * linux/mm/comp_cache/main.c * ! * Time-stamp: <2002-01-11 18:55:28 rcastro> * * Linux Virtual Memory Compressed Cache --- 2,6 ---- * linux/mm/comp_cache/main.c * ! * Time-stamp: <2002-01-14 16:46:46 rcastro> * * Linux Virtual Memory Compressed Cache *************** *** 181,185 **** min_num_comp_pages = 0; ! printk("Starting compressed cache v0.21pre6 (%lu pages = %luk)\n", max_num_comp_pages, (max_num_comp_pages * PAGE_SIZE)/1024); /* initialize our data for the `test' compressed_page */ --- 181,185 ---- min_num_comp_pages = 0; ! printk("Compressed Cache: starting %s - %lu pages = %luKiB\n", COMP_CACHE_VERSION, max_num_comp_pages, (max_num_comp_pages * PAGE_SIZE)/1024); /* initialize our data for the `test' compressed_page */ Index: swapin.c =================================================================== RCS file: /cvsroot/linuxcompressed/linux/mm/comp_cache/swapin.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -r1.14 -r1.15 *** swapin.c 2002/01/14 12:05:08 1.14 --- swapin.c 2002/01/16 16:30:12 1.15 *************** *** 2,6 **** * linux/mm/comp_cache/swapin.c * ! * Time-stamp: <2002-01-14 08:31:09 rcastro> * * Linux Virtual Memory Compressed Cache --- 2,6 ---- * linux/mm/comp_cache/swapin.c * ! * Time-stamp: <2002-01-14 16:59:13 rcastro> * * Linux Virtual Memory Compressed Cache *************** *** 27,30 **** --- 27,32 ---- if (!PageCompCache(comp_page->page)) BUG(); + if (!PageLocked(comp_page->page)) + BUG(); if (!PageLocked(uncompressed_page)) BUG(); *************** *** 41,46 **** } - extern void swapin_vswap(comp_cache_t *, comp_cache_fragment_t *); - /** * decompress_and_free_fragment - decompress a fragment, freeing its --- 43,46 ---- *************** *** 55,66 **** { comp_cache_t * comp_page = fragment->comp_page; if (!PageLocked(page)) BUG(); decompress_page(fragment, page); ! comp_cache_free(fragment); ! swapin_vswap(comp_page, fragment); comp_cache_update_faultin_stats(); } --- 55,73 ---- { comp_cache_t * comp_page = fragment->comp_page; + int retval; if (!PageLocked(page)) BUG(); + if (TryLockPage(comp_page->page)) + BUG(); decompress_page(fragment, page); ! retval = comp_cache_free_locked(fragment); comp_cache_update_faultin_stats(); + + if (!retval) + return; + + UnlockPage(comp_page->page); } Index: swapout.c =================================================================== RCS file: /cvsroot/linuxcompressed/linux/mm/comp_cache/swapout.c,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -r1.17 -r1.18 *** swapout.c 2002/01/14 12:05:08 1.17 --- swapout.c 2002/01/16 16:30:12 1.18 *************** *** 2,6 **** * /mm/comp_cache/swapout.c * ! * Time-stamp: <2002-01-13 18:21:19 rcastro> * * Linux Virtual Memory Compressed Cache --- 2,6 ---- * /mm/comp_cache/swapout.c * ! * Time-stamp: <2002-01-14 15:39:40 rcastro> * * Linux Virtual Memory Compressed Cache *************** *** 70,73 **** --- 70,75 ---- CompFragmentClearIO(swp_buffer->fragment); comp_cache_free(swp_buffer->fragment); + + swp_buffer->fragment = NULL; out: Index: vswap.c =================================================================== RCS file: /cvsroot/linuxcompressed/linux/mm/comp_cache/vswap.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -r1.16 -r1.17 *** vswap.c 2002/01/14 12:05:08 1.16 --- vswap.c 2002/01/16 16:30:12 1.17 *************** *** 2,6 **** * linux/mm/comp_cache/vswap.c * ! * Time-stamp: <2002-01-13 19:08:24 rcastro> * * Linux Virtual Memory Compressed Cache --- 2,6 ---- * linux/mm/comp_cache/vswap.c * ! * Time-stamp: <2002-01-14 16:58:59 rcastro> * * Linux Virtual Memory Compressed Cache *************** *** 215,224 **** if (!vswap_address(entry)) return; - - /* it's ok fragment == NULL since the vswap may have been - * freed in swp_free, but the fragment was only set to Freed */ - if (vswap_address[offset]->fragment == VSWAP_RESERVED) - BUG(); vswap_address[offset]->fragment = VSWAP_RESERVED; --- 215,222 ---- if (!vswap_address(entry)) return; + if (reserved(offset)) + BUG(); + vswap_address[offset]->fragment = VSWAP_RESERVED; *************** *** 229,232 **** --- 227,231 ---- estimated_free_space += fragment->compressed_size; + estimated_pages--; } *************** *** 257,277 **** estimated_free_space -= fragment->compressed_size; } - - inline void - swapin_vswap(comp_cache_t * comp_page, comp_cache_fragment_t * fragment) - { - swp_entry_t entry; - unsigned long offset; - - entry.val = fragment->index; - - if (!vswap_address(entry)) - return; - - offset = SWP_OFFSET(entry); - - vswap_address[offset]->fragment = VSWAP_RESERVED; - estimated_pages--; - } inline void --- 256,259 ---- |