"Fossies" - the Fresh Open Source Software Archive

Member "memcached-1.6.15/extstore.h" (24 Feb 2022, 4587 Bytes) of package /linux/www/memcached-1.6.15.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 "extstore.h" see the Fossies "Dox" file reference documentation.

    1 #ifndef EXTSTORE_H
    2 #define EXTSTORE_H
    3 
    4 /* A safe-to-read dataset for determining compaction.
    5  * id is the array index.
    6  */
    7 struct extstore_page_data {
    8     uint64_t version;
    9     uint64_t bytes_used;
   10     unsigned int bucket;
   11     unsigned int free_bucket;
   12 };
   13 
   14 /* Pages can have objects deleted from them at any time. This creates holes
   15  * that can't be reused until the page is either evicted or all objects are
   16  * deleted.
   17  * bytes_fragmented is the total bytes for all of these holes.
   18  * It is the size of all used pages minus each page's bytes_used value.
   19  */
   20 struct extstore_stats {
   21     uint64_t page_allocs;
   22     uint64_t page_count; /* total page count */
   23     uint64_t page_evictions;
   24     uint64_t page_reclaims;
   25     uint64_t page_size; /* size in bytes per page (supplied by caller) */
   26     uint64_t pages_free; /* currently unallocated/unused pages */
   27     uint64_t pages_used;
   28     uint64_t objects_evicted;
   29     uint64_t objects_read;
   30     uint64_t objects_written;
   31     uint64_t objects_used; /* total number of objects stored */
   32     uint64_t bytes_evicted;
   33     uint64_t bytes_written;
   34     uint64_t bytes_read; /* wbuf - read -> bytes read from storage */
   35     uint64_t bytes_used; /* total number of bytes stored */
   36     uint64_t bytes_fragmented; /* see above comment */
   37     uint64_t io_queue;
   38     struct extstore_page_data *page_data;
   39 };
   40 
   41 // TODO: Temporary configuration structure. A "real" library should have an
   42 // extstore_set(enum, void *ptr) which hides the implementation.
   43 // this is plenty for quick development.
   44 struct extstore_conf {
   45     unsigned int page_size; // ideally 64-256M in size
   46     unsigned int page_count;
   47     unsigned int page_buckets; // number of different writeable pages
   48     unsigned int free_page_buckets; // buckets of dedicated pages (see code)
   49     unsigned int wbuf_size; // must divide cleanly into page_size
   50     unsigned int wbuf_count; // this might get locked to "2 per active page"
   51     unsigned int io_threadcount;
   52     unsigned int io_depth; // with normal I/O, hits locks less. req'd for AIO
   53 };
   54 
   55 struct extstore_conf_file {
   56     unsigned int page_count;
   57     char *file;
   58     int fd; // internal usage
   59     uint64_t offset; // internal usage
   60     unsigned int bucket; // free page bucket
   61     unsigned int free_bucket; // specialized free bucket
   62     struct extstore_conf_file *next;
   63 };
   64 
   65 enum obj_io_mode {
   66     OBJ_IO_READ = 0,
   67     OBJ_IO_WRITE,
   68 };
   69 
   70 typedef struct _obj_io obj_io;
   71 typedef void (*obj_io_cb)(void *e, obj_io *io, int ret);
   72 
   73 /* An object for both reads and writes to the storage engine.
   74  * Once an IO is submitted, ->next may be changed by the IO thread. It is not
   75  * safe to further modify the IO stack until the entire request is completed.
   76  */
   77 struct _obj_io {
   78     void *data; /* user supplied data pointer */
   79     struct _obj_io *next;
   80     char *buf;  /* buffer of data to read or write to */
   81     struct iovec *iov; /* alternatively, use this iovec */
   82     unsigned int iovcnt; /* number of IOV's */
   83     unsigned int page_version;     /* page version for read mode */
   84     unsigned int len;     /* for both modes */
   85     unsigned int offset;  /* for read mode */
   86     unsigned short page_id; /* for read mode */
   87     enum obj_io_mode mode;
   88     /* callback pointers? */
   89     obj_io_cb cb;
   90 };
   91 
   92 enum extstore_res {
   93     EXTSTORE_INIT_BAD_WBUF_SIZE = 1,
   94     EXTSTORE_INIT_NEED_MORE_WBUF,
   95     EXTSTORE_INIT_NEED_MORE_BUCKETS,
   96     EXTSTORE_INIT_PAGE_WBUF_ALIGNMENT,
   97     EXTSTORE_INIT_TOO_MANY_PAGES,
   98     EXTSTORE_INIT_OOM,
   99     EXTSTORE_INIT_OPEN_FAIL,
  100     EXTSTORE_INIT_THREAD_FAIL
  101 };
  102 
  103 const char *extstore_err(enum extstore_res res);
  104 void *extstore_init(struct extstore_conf_file *fh, struct extstore_conf *cf, enum extstore_res *res);
  105 int extstore_write_request(void *ptr, unsigned int bucket, unsigned int free_bucket, obj_io *io);
  106 void extstore_write(void *ptr, obj_io *io);
  107 int extstore_submit(void *ptr, obj_io *io);
  108 /* count are the number of objects being removed, bytes are the original
  109  * length of those objects. Bytes is optional but you can't track
  110  * fragmentation without it.
  111  */
  112 int extstore_check(void *ptr, unsigned int page_id, uint64_t page_version);
  113 int extstore_delete(void *ptr, unsigned int page_id, uint64_t page_version, unsigned int count, unsigned int bytes);
  114 void extstore_get_stats(void *ptr, struct extstore_stats *st);
  115 /* add page data array to a stats structure.
  116  * caller must allocate its stats.page_data memory first.
  117  */
  118 void extstore_get_page_data(void *ptr, struct extstore_stats *st);
  119 void extstore_run_maint(void *ptr);
  120 void extstore_close_page(void *ptr, unsigned int page_id, uint64_t page_version);
  121 
  122 #endif