#define SWAP_RECLIAM_PAGES_MIN 128
#define SWAP_MEMCG_SWAPPINESS 60
#define SWAP_MIN_SWAPPINESS 0
+#define SWAP_EARLYRECALIM_TIME 60
enum swap_thread_op {
SWAP_OP_ACTIVATE,
static int current_swappiness = SWAP_MEMCG_SWAPPINESS;
static GSList *swap_module; /* module list */
+static GSource *swap_activating_timer = NULL;
static int swap_sort_func(const struct swap_module_ops *a,
const struct swap_module_ops *b)
int r;
GSList *iter;
struct swap_module_ops *swaps;
+ static bool early_reclaim;
r = cgroup_read_node_int32(LOWMEM_ROOT_CGROUP,
MEMCG_SWAPNESS_PATH, ¤t_swappiness);
continue;
}
_I("swap device(%s) was turned on: %s", swaps->name, swaps->path);
+
+ /*
+ * Most system daemons use much memory for intializing own process.
+ * but there is little change to reuse it while running.
+ * So early reclaiming moves unused system memory to swap device.
+ * It is enough to trigger reclaiming about root memcg only once.
+ * If multiple swap devices are available,
+ * first swap with the lowest priority will start reclaiming.
+ */
+ if (!early_reclaim) {
+ swap_start_reclaim(LOWMEM_ROOT_CGROUP);
+ early_reclaim = true;
+ }
+
swap_set_state(SWAP_ON);
}
}
return swap_internal_bundle_sender(SWAP_OP_ACTIVATE);
}
+static gboolean swap_activate_timer_cb(gpointer data)
+{
+ swap_activating_timer = NULL;
+ swap_internal_bundle_sender(SWAP_OP_ACTIVATE);
+ return false;
+}
+
+static int swap_booting_done(void *data)
+{
+ swap_activating_timer = g_timeout_source_new_seconds(SWAP_EARLYRECALIM_TIME);
+ g_source_set_callback(swap_activating_timer, swap_activate_timer_cb, NULL, NULL);
+ g_source_attach(swap_activating_timer, NULL);
+
+ return RESOURCED_ERROR_NONE;
+}
+
static int swap_compact_handler(void *data)
{
_I("compaction request. Reason: %s",
{
unregister_notifier(RESOURCED_NOTIFIER_SWAP_START, swap_start_handler);
unregister_notifier(RESOURCED_NOTIFIER_SWAP_ACTIVATE, swap_activate_handler);
- unregister_notifier(RESOURCED_NOTIFIER_BOOTING_DONE, swap_activate_handler);
+ unregister_notifier(RESOURCED_NOTIFIER_BOOTING_DONE, swap_booting_done);
unregister_notifier(RESOURCED_NOTIFIER_SWAP_COMPACT, swap_compact_handler);
unregister_notifier(RESOURCED_NOTIFIER_SWAP_UNSET_LIMIT, swap_cgroup_reset_limit);