diff options
author | Iliyan Malchev <malchev@google.com> | 2015-05-01 14:05:04 -0700 |
---|---|---|
committer | Iliyan Malchev <malchev@google.com> | 2015-05-01 23:04:04 -0700 |
commit | 3ea902f25291e7c91a3a8f73d0f64bfd3de548b6 (patch) | |
tree | af4c1c41e11b8983a0d0a54fe66ba05668263093 | |
parent | 4fca59181c838b91572d1b57cb74b26d0a70528f (diff) | |
download | system_core-3ea902f25291e7c91a3a8f73d0f64bfd3de548b6.zip system_core-3ea902f25291e7c91a3a8f73d0f64bfd3de548b6.tar.gz system_core-3ea902f25291e7c91a3a8f73d0f64bfd3de548b6.tar.bz2 |
fs_mgr: allow for zramsize to be specified as percentage of total memory
If the zramsize entry has a % size at the end, as in the following example:
/dev/block/zram0 none swap defaults zramsize=25%
then we will set the value as that percentage of total RAM, as read by scanning
/proc/meminfo.
b/20760266 Seed common build allocated too much for zRAM-backed swap
Change-Id: I17c91d311ba99ae7adae112bfe1b38542ea69b80
Signed-off-by: Iliyan Malchev <malchev@google.com>
-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 ab8f128..c200b05 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" @@ -72,6 +74,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) @@ -145,7 +160,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; } |