df3370907ce9c6adc98f385debf96bed4ee1a12c
[bluesky.git] / bluesky / init.c
1 /* Blue Sky: File Systems in the Cloud
2  *
3  * Copyright (C) 2009  The Regents of the University of California
4  * Written by Michael Vrable <mvrable@cs.ucsd.edu>
5  *
6  * TODO: Licensing
7  */
8
9 #include <stdint.h>
10 #include <stdlib.h>
11 #include <glib.h>
12 #include <string.h>
13
14 #include "bluesky-private.h"
15
16 int bluesky_verbose = 0;
17
18 BlueSkyOptions bluesky_options = {
19     .cache_size = 1024*1024,         // Default cache size is 1 GiB
20 };
21
22 /* Maximum number of threads to use in any particular thread pool, or -1 for no
23  * limit */
24 int bluesky_max_threads = 16;
25
26 /* Watermark levels for cache tuning: these control when dirty data is flushed
27  * from cache, when clean data is dropped from the cache, etc.  These values
28  * are measured in blocks, not bytes.
29  *
30  * There are a few relevant levels:
31  *   low: Below this point, data is not forced out due to memory pressure
32  *   medium: At this point start flushing data to get back below medium
33  *   high: Flush data very aggressively (launch extra tasks if needed)
34  */
35 int bluesky_watermark_low_dirty    = (64 << 20) / BLUESKY_BLOCK_SIZE;
36 int bluesky_watermark_medium_dirty = (96 << 20) / BLUESKY_BLOCK_SIZE;
37 int bluesky_watermark_high_dirty   = (192 << 20) / BLUESKY_BLOCK_SIZE;
38
39 int bluesky_watermark_low_total    = (64 << 20) / BLUESKY_BLOCK_SIZE;
40 int bluesky_watermark_medium_total = (128 << 20) / BLUESKY_BLOCK_SIZE;
41 int bluesky_watermark_high_total   = (256 << 20) / BLUESKY_BLOCK_SIZE;
42
43 /* Environment variables that can be used to initialize settings. */
44 static struct {
45     const char *env;
46     int *option;
47 } option_table[] = {
48     {"BLUESKY_OPT_SYNC_STORES", &bluesky_options.synchronous_stores},
49     {"BLUESKY_OPT_WRITETHROUGH", &bluesky_options.writethrough_cache},
50     {"BLUESKY_OPT_SYNC_INODE_FETCH", &bluesky_options.sync_inode_fetches},
51     {"BLUESKY_OPT_SYNC_FRONTENDS", &bluesky_options.sync_frontends},
52     {"BLUESKY_CACHE_SIZE", &bluesky_options.cache_size},
53     {NULL, NULL}
54 };
55
56 /* BlueSky library initialization. */
57
58 void bluesky_store_init_s3(void);
59 void bluesky_store_init_kv(void);
60 void bluesky_store_init_multi(void);
61 void bluesky_store_init_bdb(void);
62 void bluesky_store_init_simple(void);
63
64 /* Initialize the BlueSky library and dependent libraries. */
65 void bluesky_init(void)
66 {
67     g_thread_init(NULL);
68     bluesky_crypt_init();
69
70     for (int i = 0; option_table[i].env != NULL; i++) {
71         const char *val = getenv(option_table[i].env);
72         if (val != NULL) {
73             int v = atoi(val);
74             g_print("Option %s set to %d\n", option_table[i].env, v);
75             *option_table[i].option = atoi(val);
76         }
77     }
78
79     bluesky_store_init();
80     bluesky_store_init_kv();
81     bluesky_store_init_s3();
82     bluesky_store_init_multi();
83     bluesky_store_init_bdb();
84     bluesky_store_init_simple();
85 }