Rework cache flushing logic--this version should work much better.
[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 BlueSkyOptions bluesky_options;
17
18 /* Maximum number of threads to use in any particular thread pool, or -1 for no
19  * limit */
20 int bluesky_max_threads = 16;
21
22 /* Watermark levels for cache tuning: these control when dirty data is flushed
23  * from cache, when clean data is dropped from the cache, etc.  These values
24  * are measured in blocks, not bytes.
25  *
26  * There are a few relevant levels:
27  *   low: Below this point, data is not forced out due to memory pressure
28  *   medium: At this point start flushing data to get back below medium
29  *   high: Flush data very aggressively (launch extra tasks if needed)
30  */
31 int bluesky_watermark_low_dirty    = (64 << 20) / BLUESKY_BLOCK_SIZE;
32 int bluesky_watermark_medium_dirty = (96 << 20) / BLUESKY_BLOCK_SIZE;
33 int bluesky_watermark_high_dirty   = (192 << 20) / BLUESKY_BLOCK_SIZE;
34
35 int bluesky_watermark_low_total    = (64 << 20) / BLUESKY_BLOCK_SIZE;
36 int bluesky_watermark_medium_total = (128 << 20) / BLUESKY_BLOCK_SIZE;
37 int bluesky_watermark_high_total   = (256 << 20) / BLUESKY_BLOCK_SIZE;
38
39 /* Environment variables that can be used to initialize settings. */
40 static struct {
41     const char *env;
42     int *option;
43 } option_table[] = {
44     {"BLUESKY_OPT_SYNC_STORES", &bluesky_options.synchronous_stores},
45     {"BLUESKY_OPT_WRITETHROUGH", &bluesky_options.writethrough_cache},
46     {"BLUESKY_OPT_SYNC_INODE_FETCH", &bluesky_options.sync_inode_fetches},
47     {"BLUESKY_OPT_SYNC_FRONTENDS", &bluesky_options.sync_frontends},
48     {NULL, NULL}
49 };
50
51 /* BlueSky library initialization. */
52
53 void bluesky_store_init_s3(void);
54 void bluesky_store_init_kv(void);
55
56 /* Initialize the BlueSky library and dependent libraries. */
57 void bluesky_init(void)
58 {
59     g_thread_init(NULL);
60     bluesky_crypt_init();
61
62     for (int i = 0; option_table[i].env != NULL; i++) {
63         const char *val = getenv(option_table[i].env);
64         if (val != NULL) {
65             int v = atoi(val);
66             g_print("Option %s set to %d\n", option_table[i].env, v);
67             *option_table[i].option = atoi(val);
68         }
69     }
70
71     bluesky_store_init();
72     bluesky_store_init_kv();
73     bluesky_store_init_s3();
74 }