diff options
author | Iliyan Malchev <malchev@google.com> | 2015-05-12 23:41:37 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-05-12 23:41:37 +0000 |
commit | 8b4486294053ea96ac50d8c07d4fc23729ef7c52 (patch) | |
tree | 8407debc2d18a23ec4afee0aa315cc772a64fbe1 | |
parent | b67b92f279e2f991b8899b55d2722bd651aba076 (diff) | |
parent | 16092b7a48e8426515f67206be2f0aee92fd6006 (diff) | |
download | system_core-8b4486294053ea96ac50d8c07d4fc23729ef7c52.zip system_core-8b4486294053ea96ac50d8c07d4fc23729ef7c52.tar.gz system_core-8b4486294053ea96ac50d8c07d4fc23729ef7c52.tar.bz2 |
am 16092b7a: Merge "fs_mgr: allow for zramsize to be specified as percentage of total memory" into lmp-mr1-dev
* commit '16092b7a48e8426515f67206be2f0aee92fd6006':
fs_mgr: allow for zramsize to be specified as percentage of total memory
-rw-r--r-- | fs_mgr/fs_mgr_fstab.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/fs_mgr/fs_mgr_fstab.c b/fs_mgr/fs_mgr_fstab.c index edd9591..c2da28a 100644 --- a/fs_mgr/fs_mgr_fstab.c +++ b/fs_mgr/fs_mgr_fstab.c @@ -15,10 +15,12 @@ */ #include <ctype.h> +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/mount.h> +#include <unistd.h> #include "fs_mgr_priv.h" @@ -73,6 +75,19 @@ static struct flag_list fs_mgr_flags[] = { { 0, 0 }, }; +static uint64_t calculate_zram_size(unsigned int percentage) +{ + uint64_t total; + + total = sysconf(_SC_PHYS_PAGES); + total *= percentage; + total /= 100; + + total *= sysconf(_SC_PAGESIZE); + + return total; +} + static int parse_flags(char *flags, struct flag_list *fl, struct fs_mgr_flag_values *flag_vals, char *fs_options, int fs_options_len) @@ -146,7 +161,12 @@ static int parse_flags(char *flags, struct flag_list *fl, } else if ((fl[i].flag == MF_SWAPPRIO) && flag_vals) { flag_vals->swap_prio = strtoll(strchr(p, '=') + 1, NULL, 0); } else if ((fl[i].flag == MF_ZRAMSIZE) && flag_vals) { - flag_vals->zram_size = strtoll(strchr(p, '=') + 1, NULL, 0); + int is_percent = !!strrchr(p, '%'); + unsigned int val = strtoll(strchr(p, '=') + 1, NULL, 0); + if (is_percent) + flag_vals->zram_size = calculate_zram_size(val); + else + flag_vals->zram_size = val; } break; } |