swap: do NOT set ZRAM size if it is already set by kernel 06/243206/1 accepted/tizen/unified/20200908.060819 submit/tizen/20200907.113616 submit/tizen/20200908.010406
authorElmurod Talipov <e.talipov@samsung.com>
Fri, 4 Sep 2020 02:26:40 +0000 (11:26 +0900)
committerElmurod Talipov <e.talipov@samsung.com>
Fri, 4 Sep 2020 02:27:58 +0000 (11:27 +0900)
 ZRAM disksize can be set with configuration in Kernel or by other
 means, in that case setting and verify ZRAM size fails.

Change-Id: Id296cf8106ecbea368959f92e06ad7d7a6a57f4c
Signed-off-by: Elmurod Talipov <e.talipov@samsung.com>
src/swap/zramswap.c

index b40f147..e179713 100644 (file)
@@ -127,23 +127,32 @@ static int swap_zram_activate(void *data)
                }
        }
 
-       r = fwrite_uint(SWAP_ZRAM_DISK_SIZE, swap_size_bytes);
-       if (r < 0) {
-               _E("fail to write disk_size");
-               return r;
-       }
-
        r = fread_uint(SWAP_ZRAM_DISK_SIZE, &read_size_bytes);
        if (r < 0) {
                _E("fail to read zram disk_size");
                return r;
        }
 
-       /* Check if zram was sucessfully initialized (zcomp rollback case) */
-       if (read_size_bytes < swap_size_bytes) {
-               _E("swap size (%d) less than expected swap size (%d)",
-                               read_size_bytes, swap_size_bytes);
-               return RESOURCED_ERROR_OUT_OF_MEMORY;
+       /* disksize can be pre-fixed by other means, do not set size in that case */
+       if (read_size_bytes == 0) {
+               r = fwrite_uint(SWAP_ZRAM_DISK_SIZE, swap_size_bytes);
+               if (r < 0) {
+                       _E("fail to write disk_size");
+                       return r;
+               }
+
+               r = fread_uint(SWAP_ZRAM_DISK_SIZE, &read_size_bytes);
+               if (r < 0) {
+                       _E("fail to read zram disk_size");
+                       return r;
+               }
+
+               /* Check if zram was sucessfully initialized (zcomp rollback case) */
+               if (read_size_bytes < swap_size_bytes) {
+                       _E("swap size (%d) less than expected swap size (%d)",
+                                       read_size_bytes, swap_size_bytes);
+                       return RESOURCED_ERROR_OUT_OF_MEMORY;
+               }
        }
 
        r = do_mkswap(swap->path);