"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/xlators/performance/io-cache/src/io-cache.h" (16 Sep 2020, 9718 Bytes) of package /linux/misc/glusterfs-8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "io-cache.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2   Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com>
    3   This file is part of GlusterFS.
    4 
    5   This file is licensed to you under your choice of the GNU Lesser
    6   General Public License, version 3 or any later version (LGPLv3 or
    7   later), or the GNU General Public License, version 2 (GPLv2), in all
    8   cases as published by the Free Software Foundation.
    9 */
   10 
   11 #ifndef __IO_CACHE_H
   12 #define __IO_CACHE_H
   13 
   14 #include <sys/types.h>
   15 #include <glusterfs/compat-errno.h>
   16 
   17 #include <glusterfs/glusterfs.h>
   18 #include <glusterfs/dict.h>
   19 #include <glusterfs/call-stub.h>
   20 #include <glusterfs/rbthash.h>
   21 #include <sys/time.h>
   22 #include <fnmatch.h>
   23 #include "io-cache-messages.h"
   24 
   25 #define IOC_PAGE_SIZE (1024 * 128) /* 128KB */
   26 #define IOC_CACHE_SIZE (32 * 1024 * 1024)
   27 #define IOC_PAGE_TABLE_BUCKET_COUNT 1
   28 
   29 struct ioc_table;
   30 struct ioc_local;
   31 struct ioc_page;
   32 struct ioc_inode;
   33 
   34 struct ioc_priority {
   35     struct list_head list;
   36     char *pattern;
   37     uint32_t priority;
   38 };
   39 
   40 /*
   41  * ioc_waitq - this structure is used to represents the waiting
   42  *             frames on a page
   43  *
   44  * @next: pointer to next object in waitq
   45  * @data: pointer to the frame which is waiting
   46  */
   47 struct ioc_waitq {
   48     struct ioc_waitq *next;
   49     void *data;
   50     off_t pending_offset;
   51     size_t pending_size;
   52 };
   53 
   54 /*
   55  * ioc_fill -
   56  *
   57  */
   58 struct ioc_fill {
   59     struct list_head list; /* list of ioc_fill structures of a frame */
   60     off_t offset;
   61     size_t size;
   62     struct iovec *vector;
   63     int32_t count;
   64     struct iobref *iobref;
   65 };
   66 
   67 struct ioc_local {
   68     mode_t mode;
   69     int32_t flags;
   70     loc_t file_loc;
   71     off_t offset;
   72     size_t size;
   73     int32_t op_ret;
   74     int32_t op_errno;
   75     struct list_head fill_list; /* list of ioc_fill structures */
   76     off_t pending_offset;       /*
   77                                  * offset from this frame should
   78                                  * continue
   79                                  */
   80     size_t pending_size;        /*
   81                                  * size of data this frame is waiting
   82                                  * on
   83                                  */
   84     struct ioc_inode *inode;
   85     int32_t wait_count;
   86     pthread_mutex_t local_lock;
   87     struct ioc_waitq *waitq;
   88     void *stub;
   89     fd_t *fd;
   90     struct iovec *vector;
   91     struct iobref *iobref;
   92     int32_t need_xattr;
   93     dict_t *xattr_req;
   94 };
   95 
   96 /*
   97  * ioc_page - structure to store page of data from file
   98  *
   99  */
  100 struct ioc_page {
  101     struct list_head page_lru;
  102     struct ioc_inode *inode; /* inode this page belongs to */
  103     struct ioc_priority *priority;
  104     char dirty;
  105     char ready;
  106     struct iovec *vector;
  107     int32_t count;
  108     off_t offset;
  109     size_t size;
  110     struct ioc_waitq *waitq;
  111     struct iobref *iobref;
  112     pthread_mutex_t page_lock;
  113     int32_t op_errno;
  114     char stale;
  115 };
  116 
  117 struct ioc_cache {
  118     rbthash_table_t *page_table;
  119     struct list_head page_lru;
  120     time_t mtime;      /*
  121                         * seconds component of file mtime
  122                         */
  123     time_t mtime_nsec; /*
  124                         * nanosecond component of file mtime
  125                         */
  126     struct timeval tv; /*
  127                         * time-stamp at last re-validate
  128                         */
  129 };
  130 
  131 struct ioc_inode {
  132     struct ioc_table *table;
  133     off_t ia_size;
  134     struct ioc_cache cache;
  135     struct list_head inode_list; /*
  136                                   * list of inodes, maintained by
  137                                   * io-cache translator
  138                                   */
  139     struct list_head inode_lru;
  140     struct ioc_waitq *waitq;
  141     pthread_mutex_t inode_lock;
  142     uint32_t weight; /*
  143                       * weight of the inode, increases
  144                       * on each read
  145                       */
  146     inode_t *inode;
  147 };
  148 
  149 struct ioc_table {
  150     uint64_t page_size;
  151     uint64_t cache_size;
  152     uint64_t cache_used;
  153     uint64_t min_file_size;
  154     uint64_t max_file_size;
  155     struct list_head inodes; /* list of inodes cached */
  156     struct list_head active;
  157     struct list_head *inode_lru;
  158     struct list_head priority_list;
  159     int32_t readv_count;
  160     pthread_mutex_t table_lock;
  161     xlator_t *xl;
  162     uint32_t inode_count;
  163     int32_t cache_timeout;
  164     int32_t max_pri;
  165     struct mem_pool *mem_pool;
  166 };
  167 
  168 typedef struct ioc_table ioc_table_t;
  169 typedef struct ioc_local ioc_local_t;
  170 typedef struct ioc_page ioc_page_t;
  171 typedef struct ioc_inode ioc_inode_t;
  172 typedef struct ioc_waitq ioc_waitq_t;
  173 typedef struct ioc_fill ioc_fill_t;
  174 
  175 void *
  176 str_to_ptr(char *string);
  177 
  178 char *
  179 ptr_to_str(void *ptr);
  180 
  181 int32_t
  182 ioc_readv_disabled_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
  183                        int32_t op_ret, int32_t op_errno, struct iovec *vector,
  184                        int32_t count, struct iatt *stbuf, struct iobref *iobref,
  185                        dict_t *xdata);
  186 
  187 ioc_page_t *
  188 __ioc_page_get(ioc_inode_t *ioc_inode, off_t offset);
  189 
  190 ioc_page_t *
  191 __ioc_page_create(ioc_inode_t *ioc_inode, off_t offset);
  192 
  193 void
  194 ioc_page_fault(ioc_inode_t *ioc_inode, call_frame_t *frame, fd_t *fd,
  195                off_t offset);
  196 void
  197 __ioc_wait_on_page(ioc_page_t *page, call_frame_t *frame, off_t offset,
  198                    size_t size);
  199 
  200 ioc_waitq_t *
  201 __ioc_page_wakeup(ioc_page_t *page, int32_t op_errno);
  202 
  203 void
  204 ioc_page_flush(ioc_page_t *page);
  205 
  206 ioc_waitq_t *
  207 __ioc_page_error(ioc_page_t *page, int32_t op_ret, int32_t op_errno);
  208 
  209 void
  210 ioc_frame_return(call_frame_t *frame);
  211 
  212 void
  213 ioc_waitq_return(ioc_waitq_t *waitq);
  214 
  215 int32_t
  216 ioc_frame_fill(ioc_page_t *page, call_frame_t *frame, off_t offset, size_t size,
  217                int32_t op_errno);
  218 
  219 #define ioc_inode_lock(ioc_inode)                                              \
  220     do {                                                                       \
  221         gf_msg_trace(ioc_inode->table->xl->name, 0, "locked inode(%p)",        \
  222                      ioc_inode);                                               \
  223         pthread_mutex_lock(&ioc_inode->inode_lock);                            \
  224     } while (0)
  225 
  226 #define ioc_inode_unlock(ioc_inode)                                            \
  227     do {                                                                       \
  228         gf_msg_trace(ioc_inode->table->xl->name, 0, "unlocked inode(%p)",      \
  229                      ioc_inode);                                               \
  230         pthread_mutex_unlock(&ioc_inode->inode_lock);                          \
  231     } while (0)
  232 
  233 #define ioc_table_lock(table)                                                  \
  234     do {                                                                       \
  235         gf_msg_trace(table->xl->name, 0, "locked table(%p)", table);           \
  236         pthread_mutex_lock(&table->table_lock);                                \
  237     } while (0)
  238 
  239 #define ioc_table_unlock(table)                                                \
  240     do {                                                                       \
  241         gf_msg_trace(table->xl->name, 0, "unlocked table(%p)", table);         \
  242         pthread_mutex_unlock(&table->table_lock);                              \
  243     } while (0)
  244 
  245 #define ioc_local_lock(local)                                                  \
  246     do {                                                                       \
  247         gf_msg_trace(local->inode->table->xl->name, 0, "locked local(%p)",     \
  248                      local);                                                   \
  249         pthread_mutex_lock(&local->local_lock);                                \
  250     } while (0)
  251 
  252 #define ioc_local_unlock(local)                                                \
  253     do {                                                                       \
  254         gf_msg_trace(local->inode->table->xl->name, 0, "unlocked local(%p)",   \
  255                      local);                                                   \
  256         pthread_mutex_unlock(&local->local_lock);                              \
  257     } while (0)
  258 
  259 #define ioc_page_lock(page)                                                    \
  260     do {                                                                       \
  261         gf_msg_trace(page->inode->table->xl->name, 0, "locked page(%p)",       \
  262                      page);                                                    \
  263         pthread_mutex_lock(&page->page_lock);                                  \
  264     } while (0)
  265 
  266 #define ioc_page_unlock(page)                                                  \
  267     do {                                                                       \
  268         gf_msg_trace(page->inode->table->xl->name, 0, "unlocked page(%p)",     \
  269                      page);                                                    \
  270         pthread_mutex_unlock(&page->page_lock);                                \
  271     } while (0)
  272 
  273 static inline uint64_t
  274 time_elapsed(struct timeval *now, struct timeval *then)
  275 {
  276     uint64_t sec = now->tv_sec - then->tv_sec;
  277 
  278     if (sec)
  279         return sec;
  280 
  281     return 0;
  282 }
  283 
  284 ioc_inode_t *
  285 ioc_inode_search(ioc_table_t *table, inode_t *inode);
  286 
  287 void
  288 ioc_inode_destroy(ioc_inode_t *ioc_inode);
  289 
  290 int32_t
  291 ioc_inode_update(xlator_t *this, inode_t *inode, char *path,
  292                  struct iatt *iabuf);
  293 
  294 ioc_inode_t *
  295 ioc_inode_create(ioc_table_t *table, inode_t *inode, uint32_t weight);
  296 
  297 int64_t
  298 __ioc_page_destroy(ioc_page_t *page);
  299 
  300 int64_t
  301 __ioc_inode_flush(ioc_inode_t *ioc_inode);
  302 
  303 void
  304 ioc_inode_flush(ioc_inode_t *ioc_inode);
  305 
  306 void
  307 ioc_inode_wakeup(call_frame_t *frame, ioc_inode_t *ioc_inode,
  308                  struct iatt *stbuf);
  309 
  310 int8_t
  311 ioc_cache_still_valid(ioc_inode_t *ioc_inode, struct iatt *stbuf);
  312 
  313 int32_t
  314 ioc_prune(ioc_table_t *table);
  315 
  316 int32_t
  317 ioc_need_prune(ioc_table_t *table);
  318 
  319 #endif /* __IO_CACHE_H */