Changeset 9165
- Timestamp:
- 12/15/11 15:46:06 (18 months ago)
- Location:
- trunk/src/client/usrint
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/client/usrint/ucache.c
r9151 r9165 5 5 */ 6 6 7 /* Experimental cache for user data 8 * Currently under development... 9 */ 10 #include <usrint.h> /* to get PVFS_UCACHE_ENABLE */ 7 /** 8 * \file 9 * \ingroup usrint 10 * 11 * Experimental cache for user data. 12 * 13 */ 11 14 #include "usrint.h" 12 15 #include "posix-ops.h" 13 16 #include "openfile-util.h" 17 #include "iocommon.h" 14 18 #if PVFS_UCACHE_ENABLE 15 #include <ucache.h> 16 #include <iocommon.h> 17 #define FILE_SYSTEM_ENABLED 19 #include "ucache.h" 18 20 19 21 /* Global Variables */ … … 115 117 */ 116 118 117 /** Initializes the cache. 119 /** 120 * Initializes the cache. 118 121 * Mainly, it aquires a previously created shared memory segment used to 119 122 * cache data. The shared mem. creation and ftbl initialization should already … … 176 179 } 177 180 178 /** Returns a pointer to the mtbl corresponding to the blk & ent. 181 /** 182 * Returns a pointer to the mtbl corresponding to the blk & ent. 179 183 * Input must be reliable otherwise invalid mtbl could be returned. 180 184 */ … … 192 196 } 193 197 194 /** Initializes the ucache file table if it hasn't previously been initialized. 198 /** 199 * Initializes the ucache file table if it hasn't previously been initialized. 195 200 * Although this function is visible, DO NOT CALL THIS FUNCTION. 196 201 * It is meant to be called in the ucache daemon or during testing. … … 260 265 } 261 266 267 /** 268 * Opens a file in ucache. 269 */ 262 270 int ucache_open_file(PVFS_fs_id *fs_id, 263 271 PVFS_handle *handle, … … 322 330 } 323 331 324 /** Returns ptr to block in ucache based on file and offset */ 332 /** 333 * Returns ptr to block in ucache based on file and offset 334 */ 325 335 inline void *ucache_lookup(struct file_ent_s *fent, uint64_t offset, 326 336 uint16_t *block_ndx) … … 341 351 } 342 352 343 /** Prepares the data structures for block storage. 353 /** 354 * Prepares the data structures for block storage. 344 355 * On success, returns a pointer to where the block of data should be written. 345 356 * On failure, returns NIL. … … 357 368 358 369 #if 0 359 /** Removes a cached block of data from mtbl 370 /** 371 * Removes a cached block of data from mtbl 360 372 * Returns 1 on success, 0 on failure. 361 373 */ … … 370 382 #endif 371 383 372 /** Flushes the entire ucache's dirty blocks (every file's dirty blocks) */ 373 /* Returns 0 on success, -1 on failure*/ 384 /** 385 * Flushes the entire ucache's dirty blocks (every file's dirty blocks) 386 * Returns 0 on success, -1 on failure 387 */ 374 388 int ucache_flush_cache(void) 375 389 { … … 403 417 } 404 418 405 /** Externally visible wrapper of the internal flush file function. 419 /** 420 * Externally visible wrapper of the internal flush file function. 406 421 * This is intended to allow and external flush file call which locks the 407 422 * global lock, flushes the file, then releases the global lock. … … 419 434 } 420 435 421 /** Internal only function - Flushes dirty blocks to the I/O Nodes 436 /** 437 * Internal only function - Flushes dirty blocks to the I/O Nodes 422 438 * Returns 0 on success and -1 on failure. 423 439 */ … … 445 461 mtbl->mem[i].dirty_next = NIL16; 446 462 447 #ifdef FILE_SYSTEM_ENABLED463 /*#ifdef FILE_SYSTEM_ENABLED*/ 448 464 PVFS_object_ref ref = {fent->tag_handle, fent->tag_id, 0}; 449 465 struct iovec vector = {&(ucache->b[ment->item].mblk[0]), CACHE_BLOCK_SIZE_K * 1024}; 450 466 rc = iocommon_vreadorwrite(2, &ref, ment->tag, 1, &vector); 467 /* 451 468 #endif 452 469 #ifndef FILE_SYSTEM_ENABLED 453 470 rc = 0; 454 471 #endif 472 */ 455 473 456 474 lock_unlock(blk_lock); … … 468 486 } 469 487 470 /* This function is meant to be called only inside remove_mem. */ 471 /* Returns 0 on success, -1 on failure */ 488 /** 489 * This function is meant to be called only inside remove_mem. 490 * Returns 0 on success, -1 on failure 491 */ 472 492 int flush_block(struct file_ent_s *fent, struct mem_ent_s *ment) 473 493 { 474 494 int rc = 0; 475 #ifdef FILE_SYSTEM_ENABLED495 /*#ifdef FILE_SYSTEM_ENABLED*/ 476 496 PVFS_object_ref ref = {fent->tag_handle, fent->tag_id, 0}; 477 497 struct iovec vector = {&(ucache->b[ment->item].mblk[0]), CACHE_BLOCK_SIZE_K * 1024}; 478 498 rc = iocommon_vreadorwrite(2, &ref, ment->tag, 1, &vector); 499 /* 479 500 #endif 480 501 #ifndef FILE_SYSTEM_ENABLED 481 502 rc = 0; 482 503 #endif 504 */ 483 505 return rc; 484 506 } 485 507 486 508 487 /* For testing purposes only */ 509 /** 510 * For testing purposes only! 511 */ 488 512 int wipe_ucache(void) 489 513 { … … 517 541 } 518 542 519 /** Removes all memory entries in the mtbl corresponding to the file info 543 /** 544 * Removes all memory entries in the mtbl corresponding to the file info 520 545 * provided as parameters. It also removes the mtbl and the file entry from 521 546 * the cache. … … 530 555 } 531 556 532 /** Dumps all cache related information. */ 557 /** 558 * Dumps all cache related information. 559 */ 533 560 int ucache_info(FILE *out, char *flags) 534 561 { … … 745 772 } 746 773 747 /** Returns a pointer to the lock corresponding to the block_index. 748 If the index is out of range, then 0 is returned. 774 /** 775 * Returns a pointer to the lock corresponding to the block_index. 776 * If the index is out of range, then 0 is returned. 749 777 */ 750 778 inline ucache_lock_t *get_lock(uint16_t block_index) … … 760 788 /* Beginning of internal only (static) functions */ 761 789 762 /** Initializes the proper lock based on the LOCK_TYPE 790 /** 791 * Initializes the proper lock based on the LOCK_TYPE 763 792 * Returns 0 on success, -1 on error 764 793 */ … … 789 818 } 790 819 791 /** Returns 0 when lock is locked; otherwise, return -1 and sets errno */ 820 /** 821 * Returns 0 when lock is locked; otherwise, return -1 and sets errno. 822 */ 792 823 inline int lock_lock(ucache_lock_t * lock) 793 824 { … … 817 848 } 818 849 819 /** If successful, return zero; otherwise, return -1 and sets errno */ 850 /** 851 * If successful, return zero; otherwise, return -1 and sets errno. 852 */ 820 853 inline int lock_unlock(ucache_lock_t * lock) 821 854 { … … 832 865 } 833 866 834 /** Upon successful completion, returns zero 867 /** 868 * Upon successful completion, returns zero 835 869 * Otherwise, returns -1 and sets errno. 836 870 */ … … 842 876 #endif 843 877 844 /** Upon successful completion, returns zero. 878 /** 879 * Upon successful completion, returns zero. 845 880 * Otherwise, returns -1. 846 881 * The functions have the same return policy. … … 861 896 #endif 862 897 863 /* Tries the lock to see if it's available: 898 /** 899 * Tries the lock to see if it's available: 864 900 * Returns 0 if lock has not been aquired ie: success 865 901 * Otherwise, returns -1 … … 901 937 902 938 /* Dirty List Iterator */ 903 /** Returns true if current index is NIL, otherwise, returns 0 */ 939 /** 940 * Returns true if current index is NIL, otherwise, returns 0. 941 */ 904 942 static inline unsigned char dirty_done(uint16_t index) 905 943 { … … 907 945 } 908 946 909 /** Returns the next index in the dirty list for the provided mtbl and index */ 947 /** 948 * Returns the next index in the dirty list for the provided mtbl and index 949 */ 910 950 static inline uint16_t dirty_next(struct mem_table_s *mtbl, uint16_t index) 911 951 { … … 914 954 915 955 /* Memory Entry Chain Iterator */ 916 /** Returns true if current index is NIL, otherwise, returns 0 */ 956 /** 957 * Returns true if current index is NIL, otherwise, returns 0. 958 */ 917 959 static inline unsigned char ment_done(uint16_t index) 918 960 { … … 920 962 } 921 963 922 /** Returns the next index in the memory entry chain for the provided mtbl 964 /** 965 * Returns the next index in the memory entry chain for the provided mtbl 923 966 * and index. 924 967 */ … … 929 972 930 973 /* File Entry Chain Iterator */ 931 /** Returns true if current index is NIL, otherwise, returns 0 */ 974 /** 975 * Returns true if current index is NIL, otherwise, returns 0 976 */ 932 977 static unsigned char file_done(uint16_t index) 933 978 { … … 935 980 } 936 981 937 /** Returns the next index in the file entry chain for the provided mtbl 982 /** 983 * Returns the next index in the file entry chain for the provided mtbl 938 984 * and index. 939 985 */ … … 943 989 } 944 990 945 /**This function should only be called when the ftbl has no free mtbls. 991 /** 992 * This function should only be called when the ftbl has no free mtbls. 946 993 * It initizializes MTBL_PER_BLOCK additional mtbls in the block provided, 947 994 * meaning this block will no longer be used for storing file data but … … 973 1020 ftbl->free_mtbl_ent = start_mtbl; 974 1021 } 975 1022 /** 1023 * Initializes a memory entry. 1024 */ 976 1025 static inline int init_memory_entry(struct mem_table_s *mtbl, int16_t index) 977 1026 { … … 989 1038 } 990 1039 991 /** Initializes a mtbl which is a hash table of memory entries. 1040 /** 1041 * Initializes a mtbl which is a hash table of memory entries. 992 1042 * The mtbl will be located at the provided entry index within 993 1043 * the provided block. … … 1021 1071 1022 1072 1023 /** This function asks the file table if a free block is avaialable. 1073 /** 1074 * This function asks the file table if a free block is avaialable. 1024 1075 * If so, returns the block's index; otherwise, returns NIL. 1025 1076 */ … … 1039 1090 } 1040 1091 1041 /** Accepts an index corresponding to a block that is put back on the file 1092 /** 1093 * Accepts an index corresponding to a block that is put back on the file 1042 1094 * table free list. 1043 1095 */ … … 1051 1103 } 1052 1104 1053 /** Consults the file table to retrieve an index corresponding to a file entry 1105 /** 1106 * Consults the file table to retrieve an index corresponding to a file entry 1054 1107 * If available, returns the file entry index, otherwise returns NIL. 1055 1108 */ … … 1070 1123 } 1071 1124 1072 /** Places the file entry located at the provided index back on the file table's 1125 /** 1126 * Places the file entry located at the provided index back on the file table's 1073 1127 * free file entry list. If the index is < FILE_TABLE_HASH_MAX, then set next 1074 1128 * to NIL since this index must remain the head of the linked list. Otherwise, … … 1094 1148 } 1095 1149 1096 /** Consults the provided mtbl's memory entry free list to get the index of the 1150 /** 1151 * Consults the provided mtbl's memory entry free list to get the index of the 1097 1152 * next free memory entry. Returns the index if one is available, otherwise 1098 1153 * returns NIL. … … 1109 1164 } 1110 1165 1111 /** Puts the memory entry corresponding to the provided mtbl and entry index 1166 /** 1167 * Puts the memory entry corresponding to the provided mtbl and entry index 1112 1168 * back on the mtbl's memory entry free list. 1113 1169 * … … 1134 1190 } 1135 1191 1136 /** Perform a file lookup on the ucache using the provided fs_id and handle. 1192 /** 1193 * Perform a file lookup on the ucache using the provided fs_id and handle. 1137 1194 * 1138 1195 * Additional parameters (references) may used that will be set to values … … 1198 1255 } 1199 1256 1200 /** Function that locates the next free mtbl. 1257 /** 1258 * Function that locates the next free mtbl. 1201 1259 * On success, Returns 1 and sets reference parameters to proper indexes. 1202 1260 * On failure, returns NIL; … … 1230 1288 } 1231 1289 1232 /** Places memory entries' corresponding blocks 1290 /** 1291 * Places memory entries' corresponding blocks 1233 1292 * back on the ftbl block free list. Reinitializes mtbl. 1234 1293 * Assumes mtbl->ref_cnt is 0. … … 1257 1316 } 1258 1317 1259 /** Places the provided mtbl back on the ftbl's mtbl free list provided it 1318 /** 1319 * Places the provided mtbl back on the ftbl's mtbl free list provided it 1260 1320 * isn't currently referenced. 1261 1321 */ … … 1283 1343 } 1284 1344 1285 /** Insert information about file into ucache (no file data inserted) 1345 /** 1346 * Insert information about file into ucache (no file data inserted) 1286 1347 * Returns pointer to mtbl on success. 1287 1348 * … … 1382 1443 } 1383 1444 1384 /** Remove file entry and memory table of file identified by parameters 1445 /** 1446 * Remove file entry and memory table of file identified by parameters 1385 1447 * Returns 1 following removal 1386 1448 * Returns NIL if file is referenced or if the file could not be located. … … 1436 1498 } 1437 1499 1438 /** Lookup the memory location of a block of data in cache that is identified 1500 /** 1501 * Lookup the memory location of a block of data in cache that is identified 1439 1502 * by the mtbl and offset parameters. 1440 1503 * … … 1495 1558 } 1496 1559 1497 /** Update the provided mtbl's LRU doubly-linked list by placing the memory 1560 /** 1561 * Update the provided mtbl's LRU doubly-linked list by placing the memory 1498 1562 * entry, identified by the provided index, at the head of the list (lru_first). 1499 *1500 1563 */ 1501 1564 static inline void update_LRU(struct mem_table_s *mtbl, uint16_t index) … … 1576 1639 } 1577 1640 1578 /** Searches the ftbl for the mtbl with the most entries. 1641 /** 1642 * Searches the ftbl for the mtbl with the most entries. 1579 1643 * Returns the number of memory entries the max mtbl has. The double ptr 1580 1644 * parameter is used to store a reference to the mtbl pointer with the most … … 1619 1683 } 1620 1684 1621 /** Evicts the LRU memory entry from the tail (lru_last) of the provided 1685 /** 1686 * Evicts the LRU memory entry from the tail (lru_last) of the provided 1622 1687 * mtbl's LRU list. 1623 1688 * … … 1647 1712 1648 1713 1649 /** Used to obtain a block for storage of data identified by the offset 1714 /** 1715 * Used to obtain a block for storage of data identified by the offset 1650 1716 * parameter and maintained in the mtbl at the memory entry identified by the 1651 1717 * index parameter. … … 1707 1773 } 1708 1774 1709 /** Requests a location in memory to place the data identified by the mtbl and 1775 /** 1776 * Requests a location in memory to place the data identified by the mtbl and 1710 1777 * offset parameters. Also inserts the necessary info into the mtbl. 1711 1778 * … … 1781 1848 } 1782 1849 1783 /** Removes all table info regarding the block identified by the mtbl and 1850 /** 1851 * Removes all table info regarding the block identified by the mtbl and 1784 1852 * offset provided the block isn't locked. 1785 1853 * … … 1866 1934 1867 1935 /* The following two functions are provided for error checking purposes. */ 1936 /** 1937 * Prints the Least Recently Used (LRU) list. 1938 */ 1868 1939 void print_LRU(struct mem_table_s *mtbl) 1869 1940 { … … 1887 1958 } 1888 1959 1960 /** 1961 * Prints the list of dirty (modified) blocks that should eventually be 1962 * flushed to disk. 1963 */ 1889 1964 void print_dirty(struct mem_table_s *mtbl) 1890 1965 { -
trunk/src/client/usrint/ucache.h
r9151 r9165 5 5 */ 6 6 7 /** 8 * \file 9 * \ingroup usrint 10 * ucache routines 11 */ 7 12 #ifndef UCACHE_H 8 13 #define UCACHE_H 1 9 14 10 #include <stdio.h>11 15 #include <stdint.h> 12 #include <string.h>13 16 #include <pthread.h> 14 17 #include <sys/shm.h>
