| 1 | OrangeFS User Cache Documentation |
|---|
| 2 | ------------------------------------------------------------------------------- |
|---|
| 3 | |
|---|
| 4 | 1. Overview |
|---|
| 5 | 1.1 The user cache (ucache) for OrangeFS is an optional layer of |
|---|
| 6 | functionality that can be used to improve I/O latency and |
|---|
| 7 | throughput of OrangeFS/PVFS files. Users can use the familiar |
|---|
| 8 | stdio library functions and POSIX system calls by statically |
|---|
| 9 | linking with our static library or LD_PRELOAD the shared |
|---|
| 10 | library. |
|---|
| 11 | |
|---|
| 12 | 2. Installation |
|---|
| 13 | 2.0 Shared Memory Adjustments |
|---|
| 14 | Since the ucache relies on SYSV shared memory, the SYSV |
|---|
| 15 | shared memory limits on your system probably need to be |
|---|
| 16 | increased. |
|---|
| 17 | |
|---|
| 18 | For your convenience, a Linux compatible script has been |
|---|
| 19 | included to adjust these values for you. Though, in order |
|---|
| 20 | to make these changes permanent, appropriate steps must be taken: |
|---|
| 21 | |
|---|
| 22 | Linux users should run and follow the instructions as the script |
|---|
| 23 | executes: |
|---|
| 24 | |
|---|
| 25 | By default, the script is located in /src/apps/user. |
|---|
| 26 | The script depends upon the file ucache.conf to supply the script |
|---|
| 27 | with the necessary info to compute the total shared memory size |
|---|
| 28 | required by the ucache. Run as root: |
|---|
| 29 | |
|---|
| 30 | ./checkset_shmall_shmmax.linux |
|---|
| 31 | |
|---|
| 32 | At the end of the script there's a note about what to do to make |
|---|
| 33 | the shared memory limit changes persistent. |
|---|
| 34 | |
|---|
| 35 | 2.1 Configure ucache enabled |
|---|
| 36 | ./configure --enable-ucache <other config options> |
|---|
| 37 | |
|---|
| 38 | 2.2 Configure ucache disabled |
|---|
| 39 | ./configure --disable-ucache <other config options> |
|---|
| 40 | |
|---|
| 41 | Note: By default, currently, the ucache is not compiled automatically, |
|---|
| 42 | so if you wish to use it, make sure to perform the configure step in |
|---|
| 43 | in section 2.1. |
|---|
| 44 | |
|---|
| 45 | 2.3 Finish |
|---|
| 46 | make |
|---|
| 47 | make install |
|---|
| 48 | |
|---|
| 49 | 3. ucached Daemon capabilities |
|---|
| 50 | 3.0 The ucache daemon (ucached) is a daemon that polls FIFO descriptors |
|---|
| 51 | to perform commands sent to it by the ucached daemon |
|---|
| 52 | client (ucached_cmd). When the daemon recieves a new command, |
|---|
| 53 | it attempts to execute the command and returns a response |
|---|
| 54 | through another FIFO back to ucached_cmd. The ucached must be |
|---|
| 55 | properly started before the ucache can be used. |
|---|
| 56 | |
|---|
| 57 | Following installation, by default, ucached and ucached_cmd are both |
|---|
| 58 | located in /usr/local/sbin. |
|---|
| 59 | |
|---|
| 60 | 3.1 Starting the ucache: |
|---|
| 61 | ucached_cmd s |
|---|
| 62 | |
|---|
| 63 | Note: this command effectively calls "ucached_cmd c" as a part of |
|---|
| 64 | starting the ucache, so the only time the user should call |
|---|
| 65 | "ucached_cmd c" themselves is only after they've destroyed the |
|---|
| 66 | shared memory segments with "ucached_cmd d" and would like them |
|---|
| 67 | recreated. |
|---|
| 68 | |
|---|
| 69 | 3.2 Exiting the ucache: |
|---|
| 70 | ucached_cmd x |
|---|
| 71 | |
|---|
| 72 | Note: this command effectivley calls "ucached_cmd d" as a part of exiting the |
|---|
| 73 | ucache, so the only time the user should call "ucached_cmd d" |
|---|
| 74 | themselves is if they want to destroy the shared memory segments |
|---|
| 75 | used by the ucache. |
|---|
| 76 | |
|---|
| 77 | 3.3 Remove the ucache related SYSV shared memory segments: |
|---|
| 78 | ucached_cmd d |
|---|
| 79 | |
|---|
| 80 | 3.4 Create and Initialize the SYSV shared memory segments: |
|---|
| 81 | ucached_cmd c |
|---|
| 82 | |
|---|
| 83 | 3.5 Dump info pertaining to the ucache to stdout: |
|---|
| 84 | ucached_cmd i |
|---|
| 85 | |
|---|
| 86 | *Note: info options can be specified that control the verbosity |
|---|
| 87 | of this output. The ordering of these options doesn't matter. |
|---|
| 88 | Multiple options can be used by simply appending additional |
|---|
| 89 | options to the previous ones. |
|---|
| 90 | |
|---|
| 91 | ex: ucached_cmd i spcf (note 'spcf' is equivalent to 'a') |
|---|
| 92 | |
|---|
| 93 | Options: |
|---|
| 94 | --------------------------------------------------------------- |
|---|
| 95 | Default - no info options (same as 'c') |
|---|
| 96 | |
|---|
| 97 | a Show All Info |
|---|
| 98 | |
|---|
| 99 | c Show ucache contents (append 'f' to see the free ucache elements, |
|---|
| 100 | see below) |
|---|
| 101 | |
|---|
| 102 | s Show Statistics Summary |
|---|
| 103 | |
|---|
| 104 | p Show ucache parameters |
|---|
| 105 | |
|---|
| 106 | f Show free ucache elements (must be used in conjunction with with |
|---|
| 107 | 'c' to affect output) |
|---|
| 108 | |
|---|
| 109 | Combo examples: |
|---|
| 110 | --------------------------------------------------------------- |
|---|
| 111 | i sc Show stats and ucache contents |
|---|
| 112 | |
|---|
| 113 | i cf Show ucache contents (including free ucache elements) |
|---|
| 114 | |
|---|
| 115 | i spc Show stats, parameters, and contents (but not free ucache |
|---|
| 116 | elements) |
|---|
| 117 | |
|---|
| 118 | ...etc |
|---|
| 119 | |
|---|
| 120 | 4. Examples |
|---|
| 121 | 4.1 Simple Test Program |
|---|
| 122 | =============================================================================== |
|---|
| 123 | Compiled with: |
|---|
| 124 | gcc -g -Wall -O0 -o 14 14.c \ |
|---|
| 125 | -L/usr/local/lib -lofs -lpvfs2 -rdynamic -lssl -lcrypto -lpthread -ldl |
|---|
| 126 | =============================================================================== |
|---|
| 127 | #include <stdio.h> |
|---|
| 128 | #include <stdlib.h> |
|---|
| 129 | #include <assert.h> |
|---|
| 130 | #include <errno.h> |
|---|
| 131 | #include <string.h> |
|---|
| 132 | #include <unistd.h> |
|---|
| 133 | #include <sys/types.h> |
|---|
| 134 | #include <sys/stat.h> |
|---|
| 135 | #include <fcntl.h> |
|---|
| 136 | |
|---|
| 137 | #define B_SIZE (1024 * 256) |
|---|
| 138 | #define N_BLKS 679 |
|---|
| 139 | |
|---|
| 140 | int main(int argc, char **argv) |
|---|
| 141 | { |
|---|
| 142 | /* Write buffer */ |
|---|
| 143 | size_t write_buff_size = N_BLKS * B_SIZE; |
|---|
| 144 | char *write_buff = (char *) malloc(write_buff_size); |
|---|
| 145 | assert(write_buff); |
|---|
| 146 | memset(write_buff, '0', write_buff_size); |
|---|
| 147 | |
|---|
| 148 | /* Open file */ |
|---|
| 149 | char fullpath[]= "/mnt/pvfs2/myfile"; |
|---|
| 150 | int file = open(fullpath, O_RDWR | O_CREAT, |
|---|
| 151 | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); |
|---|
| 152 | if(file < 0) |
|---|
| 153 | { |
|---|
| 154 | perror("open"); |
|---|
| 155 | return -1; |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | /* Perform the write */ |
|---|
| 159 | int howmany = write(file, write_buff, write_buff_size); |
|---|
| 160 | if(howmany < write_buff_size) |
|---|
| 161 | { |
|---|
| 162 | perror("write"); |
|---|
| 163 | close(file); |
|---|
| 164 | return -1; |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | /* Seek back to beginning of file */ |
|---|
| 168 | off_t lseek_rc = lseek(file, 0, SEEK_SET); |
|---|
| 169 | if(lseek_rc == -1) |
|---|
| 170 | { |
|---|
| 171 | perror("lseek"); |
|---|
| 172 | close(file); |
|---|
| 173 | return -1; |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | /* Read Buffer */ |
|---|
| 177 | int read_count = B_SIZE; |
|---|
| 178 | char read_buff[N_BLKS]; |
|---|
| 179 | |
|---|
| 180 | /* Perform many reads on small segments to demonstrate caching benefit */ |
|---|
| 181 | int i; |
|---|
| 182 | for(i = 0; i < read_count; i++) |
|---|
| 183 | { |
|---|
| 184 | howmany = read(file, read_buff, N_BLKS); |
|---|
| 185 | if(howmany != N_BLKS) |
|---|
| 186 | { |
|---|
| 187 | perror("read"); |
|---|
| 188 | close(file); |
|---|
| 189 | return -1; |
|---|
| 190 | } |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | /* Close File */ |
|---|
| 194 | if(close(file) != 0) |
|---|
| 195 | { |
|---|
| 196 | perror("file close"); |
|---|
| 197 | return -1; |
|---|
| 198 | } |
|---|
| 199 | return 1; |
|---|
| 200 | } |
|---|
| 201 | =============================================================================== |
|---|
| 202 | |
|---|
| 203 | 4.2 Timed Test w/o Cache |
|---|
| 204 | time sudo ./14 |
|---|
| 205 | |
|---|
| 206 | real 1m35.229s |
|---|
| 207 | user 0m31.900s |
|---|
| 208 | sys 0m11.110s |
|---|
| 209 | |
|---|
| 210 | 4.3 Timed Test w/ Cache |
|---|
| 211 | time sudo ./14 |
|---|
| 212 | |
|---|
| 213 | real 0m2.365s |
|---|
| 214 | user 0m0.860s |
|---|
| 215 | sys 0m0.690s |
|---|
| 216 | |
|---|
| 217 | 4.4 Test w/ Cache Stats Summary |
|---|
| 218 | SUCCESS |
|---|
| 219 | user cache statistics: |
|---|
| 220 | hits= 262822 |
|---|
| 221 | misses= 679 |
|---|
| 222 | hit percentage= 99.742317 |
|---|
| 223 | pseudo_misses= 0 |
|---|
| 224 | block_count= 0 |
|---|
| 225 | file_count= 0 |
|---|
| 226 | |
|---|
| 227 | 5. Limits |
|---|
| 228 | 5.1 Block Limit |
|---|
| 229 | The ucache is composed of blocks which store both hash table data to |
|---|
| 230 | facilitate ucache functionality and the actual data itself. Currently |
|---|
| 231 | the ucache is limited to 1024 blocks. |
|---|
| 232 | |
|---|
| 233 | 5.2 File Entry Limit |
|---|
| 234 | The ucache can keep up to 682 files in memory at once. Any files beyond |
|---|
| 235 | that will not use the ucache. Also, files are flushed from the ucache |
|---|
| 236 | when they are closed. |
|---|
| 237 | |
|---|
| 238 | 5.3 Memory Entry Limit |
|---|
| 239 | Memory entries represent the data block cached and some associated |
|---|
| 240 | cache meta-data. The ucache can keep up to 682 memory entries per |
|---|
| 241 | file at once. Any memory entries inserted beyond that limit will cause |
|---|
| 242 | eviction of the least recently used (LRU) memory entry of that file. |
|---|
| 243 | For the file being read/written, if no LRU memory entry is available |
|---|
| 244 | to be evicted, the LRU memory entry of the file in ucache with the most |
|---|
| 245 | memory entries is evicted. |
|---|
| 246 | |
|---|
| 247 | 6. Issues |
|---|
| 248 | 6.1 Gossip |
|---|
| 249 | |
|---|
| 250 | 6.2 Multithreading |
|---|
| 251 | |
|---|
| 252 | 6.3 Multiprocessing |
|---|