4 * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 * @desc swap common process
25 #ifndef __SWAP_COMMON_H__
26 #define __SWAP_COMMON_H__
29 #include "resourced.h"
30 #include "memory-cgroup.h"
34 #endif /* __cplusplus */
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)
51 SWAP_TYPE_ZSWAP = 0x4,
55 struct swap_status_msg {
56 char path[MAX_PATH_LENGTH];
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,
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.
75 SWAP_PRI_DISABLE = -255,
81 struct swap_module_ops {
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);
95 char algorithm[MAX_TYPE_LENGTH - 1];
100 char type[MAX_TYPE_LENGTH - 1];
103 char pool_type[MAX_TYPE_LENGTH -1];
106 struct fileswap_conf {
107 char type[MAX_TYPE_LENGTH - 1];
113 bool boot_reclaim_enable;
115 int swappiness[CGROUP_END];
116 struct zram_conf zram;
117 struct zswap_conf zswap;
118 struct fileswap_conf fileswap;
121 struct swap_conf *get_swap_conf(void);
122 void free_swap_conf(void);
124 enum swap_state swap_get_state(void);
125 void swap_set_state(enum swap_state state);
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);
131 bool swap_is_on(const char *name);
133 void swap_add(const struct swap_module_ops *swap);
134 void swap_remove(const struct swap_module_ops *swap);
136 #define SWAP_MODULE_REGISTER(swap) \
137 static void __attribute__ ((constructor)) swap_module_register(void) \
141 static void __attribute__ ((destructor)) swap_module_unregister(void) \
148 #endif /* __cplusplus */
150 #endif /* __SWAP_COMMON_H__ */