Merge "lmkd: Remove uses of hardcoded 4k PAGE_SIZE macro" into main am: f6f744fcc9 am: 8649898f6c am: 6aff556a55 am: 9add92ee7f
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/2694569 Change-Id: I95d86740b48e0108cfe5a9a296e66c4b26ce993f Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
5164031220
|
|
@ -51,6 +51,11 @@ enum lmk_cmd {
|
||||||
*/
|
*/
|
||||||
#define CTRL_PACKET_MAX_SIZE (sizeof(int) * (MAX_TARGETS * 2 + 1))
|
#define CTRL_PACKET_MAX_SIZE (sizeof(int) * (MAX_TARGETS * 2 + 1))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Max number of characters in line.
|
||||||
|
*/
|
||||||
|
#define LINE_MAX 128
|
||||||
|
|
||||||
/* LMKD packet - first int is lmk_cmd followed by payload */
|
/* LMKD packet - first int is lmk_cmd followed by payload */
|
||||||
typedef int LMKD_CTRL_PACKET[CTRL_PACKET_MAX_SIZE / sizeof(int)];
|
typedef int LMKD_CTRL_PACKET[CTRL_PACKET_MAX_SIZE / sizeof(int)];
|
||||||
|
|
||||||
|
|
|
||||||
20
lmkd.cpp
20
lmkd.cpp
|
|
@ -91,7 +91,6 @@ static inline void trace_kill_end() {}
|
||||||
#define PROC_STATUS_TGID_FIELD "Tgid:"
|
#define PROC_STATUS_TGID_FIELD "Tgid:"
|
||||||
#define PROC_STATUS_RSS_FIELD "VmRSS:"
|
#define PROC_STATUS_RSS_FIELD "VmRSS:"
|
||||||
#define PROC_STATUS_SWAP_FIELD "VmSwap:"
|
#define PROC_STATUS_SWAP_FIELD "VmSwap:"
|
||||||
#define LINE_MAX 128
|
|
||||||
|
|
||||||
#define PERCEPTIBLE_APP_ADJ 200
|
#define PERCEPTIBLE_APP_ADJ 200
|
||||||
|
|
||||||
|
|
@ -550,8 +549,8 @@ static uint16_t killcnt[MAX_DISTINCT_OOM_ADJ];
|
||||||
static int killcnt_free_idx = 0;
|
static int killcnt_free_idx = 0;
|
||||||
static uint32_t killcnt_total = 0;
|
static uint32_t killcnt_total = 0;
|
||||||
|
|
||||||
/* PAGE_SIZE / 1024 */
|
static int pagesize;
|
||||||
static long page_k;
|
static long page_k; /* page size in kB */
|
||||||
|
|
||||||
static bool update_props();
|
static bool update_props();
|
||||||
static bool init_monitors();
|
static bool init_monitors();
|
||||||
|
|
@ -627,7 +626,7 @@ static ssize_t read_all(int fd, char *buf, size_t max_len)
|
||||||
*/
|
*/
|
||||||
static char *reread_file(struct reread_data *data) {
|
static char *reread_file(struct reread_data *data) {
|
||||||
/* start with page-size buffer and increase if needed */
|
/* start with page-size buffer and increase if needed */
|
||||||
static ssize_t buf_size = PAGE_SIZE;
|
static ssize_t buf_size = pagesize;
|
||||||
static char *new_buf, *buf = NULL;
|
static char *new_buf, *buf = NULL;
|
||||||
ssize_t size;
|
ssize_t size;
|
||||||
|
|
||||||
|
|
@ -848,7 +847,7 @@ static void poll_kernel(int poll_fd) {
|
||||||
if (fields_read == 10 && group_leader_pid == pid) {
|
if (fields_read == 10 && group_leader_pid == pid) {
|
||||||
ctrl_data_write_lmk_kill_occurred((pid_t)pid, (uid_t)uid);
|
ctrl_data_write_lmk_kill_occurred((pid_t)pid, (uid_t)uid);
|
||||||
mem_st.process_start_time_ns = starttime * (NS_PER_SEC / sysconf(_SC_CLK_TCK));
|
mem_st.process_start_time_ns = starttime * (NS_PER_SEC / sysconf(_SC_CLK_TCK));
|
||||||
mem_st.rss_in_bytes = rss_in_pages * PAGE_SIZE;
|
mem_st.rss_in_bytes = rss_in_pages * pagesize;
|
||||||
|
|
||||||
struct kill_stat kill_st = {
|
struct kill_stat kill_st = {
|
||||||
.uid = static_cast<int32_t>(uid),
|
.uid = static_cast<int32_t>(uid),
|
||||||
|
|
@ -1109,7 +1108,7 @@ static void cmd_procprio(LMKD_CTRL_PACKET packet, int field_count, struct ucred
|
||||||
bool is_system_server;
|
bool is_system_server;
|
||||||
struct passwd *pwdrec;
|
struct passwd *pwdrec;
|
||||||
int64_t tgid;
|
int64_t tgid;
|
||||||
char buf[PAGE_SIZE];
|
char buf[pagesize];
|
||||||
|
|
||||||
lmkd_pack_get_procprio(packet, field_count, ¶ms);
|
lmkd_pack_get_procprio(packet, field_count, ¶ms);
|
||||||
|
|
||||||
|
|
@ -2322,7 +2321,7 @@ static int kill_one_process(struct proc* procp, int min_oom_score, struct kill_i
|
||||||
int64_t tgid;
|
int64_t tgid;
|
||||||
int64_t rss_kb;
|
int64_t rss_kb;
|
||||||
int64_t swap_kb;
|
int64_t swap_kb;
|
||||||
char buf[PAGE_SIZE];
|
char buf[pagesize];
|
||||||
char desc[LINE_MAX];
|
char desc[LINE_MAX];
|
||||||
|
|
||||||
if (!procp->valid || !read_proc_status(pid, buf, sizeof(buf))) {
|
if (!procp->valid || !read_proc_status(pid, buf, sizeof(buf))) {
|
||||||
|
|
@ -3456,10 +3455,9 @@ static int init(void) {
|
||||||
int i;
|
int i;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
page_k = sysconf(_SC_PAGESIZE);
|
// Initialize page size
|
||||||
if (page_k == -1)
|
pagesize = getpagesize();
|
||||||
page_k = PAGE_SIZE;
|
page_k = pagesize / 1024;
|
||||||
page_k /= 1024;
|
|
||||||
|
|
||||||
epollfd = epoll_create(MAX_EPOLL_EVENTS);
|
epollfd = epoll_create(MAX_EPOLL_EVENTS);
|
||||||
if (epollfd == -1) {
|
if (epollfd == -1) {
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include <lmkd.h>
|
||||||
#include <processgroup/processgroup.h>
|
#include <processgroup/processgroup.h>
|
||||||
|
|
||||||
#ifdef LMKD_LOG_STATS
|
#ifdef LMKD_LOG_STATS
|
||||||
|
|
@ -67,7 +68,7 @@ static struct proc* pid_lookup(int pid) {
|
||||||
return procp;
|
return procp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void memory_stat_parse_line(char* line, struct memory_stat* mem_st) {
|
static void memory_stat_parse_line(const char* line, struct memory_stat* mem_st) {
|
||||||
char key[MAX_TASKNAME_LEN + 1];
|
char key[MAX_TASKNAME_LEN + 1];
|
||||||
int64_t value;
|
int64_t value;
|
||||||
|
|
||||||
|
|
@ -102,8 +103,8 @@ static int memory_stat_from_cgroup(struct memory_stat* mem_st, int pid, uid_t ui
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char buf[PAGE_SIZE];
|
char buf[LINE_MAX];
|
||||||
while (fgets(buf, PAGE_SIZE, fp) != NULL) {
|
while (fgets(buf, LINE_MAX, fp) != NULL) {
|
||||||
memory_stat_parse_line(buf, mem_st);
|
memory_stat_parse_line(buf, mem_st);
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue