Remove useless source code
[platform/core/system/resourced.git] / src / common / swap-common.h
1 /*
2  * resourced
3  *
4  * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 /**
21  * @file swap-common.h
22  * @desc swap common process
23  **/
24
25 #ifndef __SWAP_COMMON_H__
26 #define __SWAP_COMMON_H__
27
28 #include <stdio.h>
29 #include "resourced.h"
30 #include "memory-cgroup.h"
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif /* __cplusplus */
35
36 #define SWAP_ZRAM_SYSFILE       "/sys/block/zram0/"
37 #define SWAP_FILE_NAME          "/opt/usr/.swapfile"
38 #define SWAP_CONF_FILE          RD_CONFIG_FILE(optimizer)
39
40 enum swap_state {
41         SWAP_ARG_START = -1,
42         SWAP_OFF,
43         SWAP_ON,
44         SWAP_ARG_END,
45 };
46
47 enum swap_type {
48         SWAP_TYPE_NONE = 0x0,
49         SWAP_TYPE_ZRAM = 0x1,
50         SWAP_TYPE_FILE = 0x2,
51         SWAP_TYPE_ZSWAP = 0x4,
52         SWAP_TYPE_MAX,
53 };
54
55 struct swap_status_msg {
56         char path[MAX_PATH_LENGTH];
57 };
58
59 enum swap_compact_reason {
60         SWAP_COMPACT_MEM_LEVEL_CRITICAL,
61         SWAP_COMPACT_MEM_LEVEL_OOM,
62         SWAP_COMPACT_SWAP_FULL,
63         SWAP_COMPACT_RESASON_MAX,
64 };
65
66 /*
67  * Each swap modoule can have priority.
68  * The swap list of kernel has low-to-high order
69  * while swap ordering is high-to-low.
70  * So, if a swap module has lower priority, it should be intialized eariler.
71  * On the top of that, SWAP_PRI_DISABLE will be used
72  * not to support multiple swap devices.
73  */
74 enum swap_priority {
75         SWAP_PRI_DISABLE = -255,
76         SWAP_PRI_LOW = -1,
77         SWAP_PRI_DEFAULT = 0,
78         SWAP_PRI_HIGH = 1,
79 };
80
81 struct swap_module_ops {
82         char *name;
83         enum swap_type type;
84         char *path;
85         int priority;
86         unsigned int k_size;
87         int (*init)(void *data);
88         int (*exit) (void *data);
89         int (*activate)(void *data);
90         int (*reclaim)(void *data);
91         int (*conf)(void *data);
92 };
93
94 struct zram_conf {
95         char algorithm[MAX_TYPE_LENGTH - 1];
96         float ratio;
97 };
98
99 struct zswap_conf {
100         char type[MAX_TYPE_LENGTH - 1];
101         long filesize;
102         float pool_ratio;
103         char pool_type[MAX_TYPE_LENGTH -1];
104 };
105
106 struct fileswap_conf {
107         char type[MAX_TYPE_LENGTH - 1];
108         long filesize;
109 };
110
111 struct swap_conf {
112         bool enable;
113         bool boot_reclaim_enable;
114         char type[30];
115         int swappiness[CGROUP_END];
116         struct zram_conf zram;
117         struct zswap_conf zswap;
118         struct fileswap_conf fileswap;
119 };
120
121 struct swap_conf *get_swap_conf(void);
122 void free_swap_conf(void);
123
124 enum swap_state swap_get_state(void);
125 void swap_set_state(enum swap_state state);
126
127 int swap_set_file(char *file, struct swap_module_ops *swap, char *crypt_type);
128 int do_mkswap(const char *device);
129 int do_dd(char *input, char *output, unsigned int size, unsigned int count);
130
131 bool swap_is_on(const char *name);
132
133 void swap_add(const struct swap_module_ops *swap);
134 void swap_remove(const struct swap_module_ops *swap);
135
136 #define SWAP_MODULE_REGISTER(swap)                                      \
137 static void __attribute__ ((constructor)) swap_module_register(void)            \
138 {                                                       \
139         swap_add(swap);                                 \
140 }                                                       \
141 static void __attribute__ ((destructor)) swap_module_unregister(void)   \
142 {                                                       \
143         swap_remove(swap);                              \
144 }
145
146 #ifdef __cplusplus
147 }
148 #endif /* __cplusplus */
149
150 #endif /* __SWAP_COMMON_H__ */