Add unit(in variable) & fix bugs
[platform/core/system/resourced.git] / src / resource-optimizer / memory / swap / zswap.c
index 213d1e6..f87a1f0 100644 (file)
@@ -42,8 +42,8 @@ struct swap_zswap_control {
        char crypt_type[MAX_TYPE_LENGTH];
        char swapfile[64];
        float zpool_ratio;
-       long zswap_file_size;
-       unsigned long zswap_reclaim_bytes;
+       unsigned long long zswap_file_bytes;
+       unsigned long long zswap_reclaim_bytes;
        char zpool_type[MAX_TYPE_LENGTH];
 };
 
@@ -51,7 +51,7 @@ static struct swap_zswap_control zswap_control = {
        .crypt_type = "aes",
        .swapfile = SWAP_FILE_NAME,
        .zpool_ratio = DEFAULT_ZSWAP_POOL_RATIO,
-       .zswap_file_size = DEFAULT_ZSWAP_FILE_SIZE,
+       .zswap_file_bytes = DEFAULT_ZSWAP_FILE_SIZE,
        .zswap_reclaim_bytes = 0,
        .zpool_type = "zbud",
 };
@@ -62,7 +62,7 @@ static int swap_zswap_activate(void *data)
        int r;
 
        zswap_control.zswap_reclaim_bytes =
-                       zswap_control.zswap_file_size * ZSWAP_FULLNESS_RATIO;
+                       zswap_control.zswap_file_bytes * ZSWAP_FULLNESS_RATIO;
 
        r = swap_set_file(zswap_control.swapfile, swap, zswap_control.crypt_type);
        if (r < 0)
@@ -88,16 +88,17 @@ static int swap_zswap_activate(void *data)
 static int swap_zswap_reclaim(void *data)
 {
        int r;
-       unsigned int swap_size;
+       unsigned int swap_size_pages;
+       unsigned long long swap_size_bytes;
 
-       r = fread_uint(ZSWAP_WRITTEN_SIZE, &swap_size);
+       r = fread_uint(ZSWAP_WRITTEN_SIZE, &swap_size_pages);
        if (r < 0) {
                _E("fail to read written swap size");
                return r;
        }
 
-       swap_size <<= PAGE_SHIFT;
-       if (swap_size <= zswap_control.zswap_reclaim_bytes)
+       swap_size_bytes = swap_size_pages <<= PAGE_SHIFT;
+       if (swap_size_bytes <= zswap_control.zswap_reclaim_bytes)
                return 0;
 
        /*
@@ -107,7 +108,7 @@ static int swap_zswap_reclaim(void *data)
         * So, it requires to trigger proactive oom killer.
         */
 
-       lowmem_trigger_swap_reclaim(CGROUP_ROOT, swap_size);
+       lowmem_trigger_swap_reclaim(CGROUP_ROOT, swap_size_bytes);
        return -ENOSPC;
 }
 
@@ -118,7 +119,7 @@ static int swap_zswap_init(void *data)
        if (access(ZSWAP_POOL_PERCENT, R_OK) != 0)
                return -ENOENT;
 
-       swap->k_size = BYTE_TO_KBYTE(zswap_control.zswap_file_size);
+       swap->k_size = BYTE_TO_KBYTE(zswap_control.zswap_file_bytes);
        return 0;
 }
 
@@ -139,7 +140,7 @@ static int swap_zswap_conf(void *data)
                memset(zswap_control.zpool_type, 0, MAX_TYPE_LENGTH);
 
        _I("[SWAP] zswap type = %s", zswap_control.crypt_type);
-       _I("[SWAP] zswap filesize = %ld", zswap_control.zswap_file_size);
+       _I("[SWAP] zswap filesize = %llu bytes", zswap_control.zswap_file_bytes);
        _I("[SWAP] zswap pool ratio = %f", zswap_control.zpool_ratio);
        _I("[SWAP] zswap pool type = %s", zswap_control.zpool_type);