Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2557cd21 authored by Iliyan Malchev's avatar Iliyan Malchev Committed by Android Git Automerger
Browse files

am 8b448629: am 16092b7a: Merge "fs_mgr: allow for zramsize to be specified as...

am 8b448629: am 16092b7a: Merge "fs_mgr: allow for zramsize to be specified as percentage of total memory" into lmp-mr1-dev

* commit '8b448629':
  fs_mgr: allow for zramsize to be specified as percentage of total memory
parents 6269a95a 8b448629
Loading
Loading
Loading
Loading
+21 −1
Original line number Original line Diff line number Diff line
@@ -15,10 +15,12 @@
 */
 */


#include <ctype.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/mount.h>
#include <unistd.h>


#include "fs_mgr_priv.h"
#include "fs_mgr_priv.h"


@@ -75,6 +77,19 @@ static struct flag_list fs_mgr_flags[] = {
    { 0,             0 },
    { 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,
static int parse_flags(char *flags, struct flag_list *fl,
                       struct fs_mgr_flag_values *flag_vals,
                       struct fs_mgr_flag_values *flag_vals,
                       char *fs_options, int fs_options_len)
                       char *fs_options, int fs_options_len)
@@ -156,7 +171,12 @@ static int parse_flags(char *flags, struct flag_list *fl,
                } else if ((fl[i].flag == MF_SWAPPRIO) && flag_vals) {
                } else if ((fl[i].flag == MF_SWAPPRIO) && flag_vals) {
                    flag_vals->swap_prio = strtoll(strchr(p, '=') + 1, NULL, 0);
                    flag_vals->swap_prio = strtoll(strchr(p, '=') + 1, NULL, 0);
                } else if ((fl[i].flag == MF_ZRAMSIZE) && flag_vals) {
                } 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;
                break;
            }
            }