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

Commit 2d544cf8 authored by Xin Li's avatar Xin Li
Browse files

DO NOT MERGE - Merge pi-dev@5234907 into stage-aosp-master

Bug: 120848293
Change-Id: I92822048a7862acaa669847b2fa9c8f708159952
parents bf1bcf4c 9a05fb3d
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -23,6 +23,9 @@
extern "C" {
#endif

#define NATIVE_HANDLE_MAX_FDS 1024
#define NATIVE_HANDLE_MAX_INTS 1024

/* Declare a char array for use with native_handle_init */
#define NATIVE_HANDLE_DECLARE_STORAGE(name, maxFds, maxInts) \
    alignas(native_handle_t) char (name)[                            \
+2 −4
Original line number Diff line number Diff line
@@ -22,9 +22,6 @@
#include <string.h>
#include <unistd.h>

static const int kMaxNativeFds = 1024;
static const int kMaxNativeInts = 1024;

native_handle_t* native_handle_init(char* storage, int numFds, int numInts) {
    if ((uintptr_t) storage % alignof(native_handle_t)) {
        errno = EINVAL;
@@ -39,7 +36,8 @@ native_handle_t* native_handle_init(char* storage, int numFds, int numInts) {
}

native_handle_t* native_handle_create(int numFds, int numInts) {
    if (numFds < 0 || numInts < 0 || numFds > kMaxNativeFds || numInts > kMaxNativeInts) {
    if (numFds < 0 || numInts < 0 || numFds > NATIVE_HANDLE_MAX_FDS ||
        numInts > NATIVE_HANDLE_MAX_INTS) {
        errno = EINVAL;
        return NULL;
    }
+17 −62
Original line number Diff line number Diff line
@@ -1006,7 +1006,7 @@ static void memory_stat_parse_line(char* line, struct memory_stat* mem_st) {
        mem_st->swap_in_bytes = value;
}

static int memory_stat_from_cgroup(struct memory_stat* mem_st, int pid, uid_t uid) {
static int memory_stat_parse(struct memory_stat *mem_st,  int pid, uid_t uid) {
   FILE *fp;
   char buf[PATH_MAX];

@@ -1026,44 +1026,6 @@ static int memory_stat_from_cgroup(struct memory_stat* mem_st, int pid, uid_t ui

   return 0;
}

static int memory_stat_from_procfs(struct memory_stat* mem_st, int pid) {
    char path[PATH_MAX];
    char buffer[PROC_STAT_BUFFER_SIZE];
    int fd, ret;

    snprintf(path, sizeof(path), PROC_STAT_FILE_PATH, pid);
    if ((fd = open(path, O_RDONLY | O_CLOEXEC)) < 0) {
        ALOGE("%s open failed: %s", path, strerror(errno));
        return -1;
    }

    ret = read(fd, buffer, sizeof(buffer));
    if (ret < 0) {
        ALOGE("%s read failed: %s", path, strerror(errno));
        close(fd);
        return -1;
    }
    close(fd);

    // field 10 is pgfault
    // field 12 is pgmajfault
    // field 22 is starttime
    // field 24 is rss_in_pages
    int64_t pgfault = 0, pgmajfault = 0, starttime = 0, rss_in_pages = 0;
    if (sscanf(buffer,
               "%*u %*s %*s %*d %*d %*d %*d %*d %*d %" SCNd64 " %*d "
               "%" SCNd64 " %*d %*u %*u %*d %*d %*d %*d %*d %*d "
               "%" SCNd64 " %*d %" SCNd64 "",
               &pgfault, &pgmajfault, &starttime, &rss_in_pages) != 4) {
        return -1;
    }
    mem_st->pgfault = pgfault;
    mem_st->pgmajfault = pgmajfault;
    mem_st->rss_in_bytes = (rss_in_pages * PAGE_SIZE);
    mem_st->process_start_time_ns = starttime * (NS_PER_SEC / sysconf(_SC_CLK_TCK));
    return 0;
}
#endif

/* /prop/zoneinfo parsing routines */
@@ -1354,11 +1316,7 @@ static int kill_one_process(struct proc* procp) {

#ifdef LMKD_LOG_STATS
    if (enable_stats_log) {
        if (per_app_memcg) {
            memory_stat_parse_result = memory_stat_from_cgroup(&mem_st, pid, uid);
        } else {
            memory_stat_parse_result = memory_stat_from_procfs(&mem_st, pid);
        }
        memory_stat_parse_result = memory_stat_parse(&mem_st, pid, uid);
    }
#endif

@@ -1385,10 +1343,7 @@ static int kill_one_process(struct proc* procp) {
        if (memory_stat_parse_result == 0) {
            stats_write_lmk_kill_occurred(log_ctx, LMK_KILL_OCCURRED, uid, taskname,
                    procp->oomadj, mem_st.pgfault, mem_st.pgmajfault, mem_st.rss_in_bytes,
                    mem_st.cache_in_bytes, mem_st.swap_in_bytes, mem_st.process_start_time_ns);
        } else if (enable_stats_log) {
            stats_write_lmk_kill_occurred(log_ctx, LMK_KILL_OCCURRED, uid, taskname, procp->oomadj,
                                          -1, -1, tasksize * BYTES_IN_KILOBYTE, -1, -1, -1);
                    mem_st.cache_in_bytes, mem_st.swap_in_bytes);
        }
#endif
        result = tasksize;
+1 −5
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ int
stats_write_lmk_kill_occurred(android_log_context ctx, int32_t code, int32_t uid,
                              char const* process_name, int32_t oom_score, int64_t pgfault,
                              int64_t pgmajfault, int64_t rss_in_bytes, int64_t cache_in_bytes,
                              int64_t swap_in_bytes, int64_t process_start_time_ns) {
                              int64_t swap_in_bytes) {
    assert(ctx != NULL);
    int ret = -EINVAL;
    if (!ctx) {
@@ -113,9 +113,5 @@ stats_write_lmk_kill_occurred(android_log_context ctx, int32_t code, int32_t uid
        return ret;
    }

    if ((ret = android_log_write_int64(ctx, process_start_time_ns)) < 0) {
        return ret;
    }

    return write_to_logger(ctx, LOG_ID_STATS);
}
+1 −5
Original line number Diff line number Diff line
@@ -64,13 +64,9 @@ struct memory_stat {
    int64_t rss_in_bytes;
    int64_t cache_in_bytes;
    int64_t swap_in_bytes;
    int64_t process_start_time_ns;
};

#define MEMCG_PROCESS_MEMORY_STAT_PATH "/dev/memcg/apps/uid_%u/pid_%u/memory.stat"
#define PROC_STAT_FILE_PATH "/proc/%d/stat"
#define PROC_STAT_BUFFER_SIZE 1024
#define BYTES_IN_KILOBYTE 1024

/**
 * Logs the change in LMKD state which is used as start/stop boundaries for logging
@@ -88,7 +84,7 @@ int
stats_write_lmk_kill_occurred(android_log_context ctx, int32_t code, int32_t uid,
                              char const* process_name, int32_t oom_score, int64_t pgfault,
                              int64_t pgmajfault, int64_t rss_in_bytes, int64_t cache_in_bytes,
                              int64_t swap_in_bytes, int64_t process_start_time_ns);
                              int64_t swap_in_bytes);

__END_DECLS

Loading