Merge "Fix vmalloc memory accounting (DO NOT MERGE)." into mnc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
e48cca2a20
@@ -568,6 +568,29 @@ static jlong android_os_Debug_getPss(JNIEnv *env, jobject clazz)
|
|||||||
return android_os_Debug_getPssPid(env, clazz, getpid(), NULL, NULL);
|
return android_os_Debug_getPssPid(env, clazz, getpid(), NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static long get_allocated_vmalloc_memory() {
|
||||||
|
char line[1024];
|
||||||
|
long size, vmalloc_allocated_size = 0;
|
||||||
|
FILE* fp = fopen("/proc/vmallocinfo", "r");
|
||||||
|
if (fp == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
while (true) {
|
||||||
|
if (fgets(line, 1024, fp) == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strstr(line, "ioremap")) {
|
||||||
|
// Ignore ioremap regions, since they don't actually consume memory
|
||||||
|
if (sscanf(line, "%*x-%*x %ld", &size) == 1) {
|
||||||
|
vmalloc_allocated_size += size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
return vmalloc_allocated_size;
|
||||||
|
}
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
MEMINFO_TOTAL,
|
MEMINFO_TOTAL,
|
||||||
MEMINFO_FREE,
|
MEMINFO_FREE,
|
||||||
@@ -588,7 +611,7 @@ enum {
|
|||||||
static void android_os_Debug_getMemInfo(JNIEnv *env, jobject clazz, jlongArray out)
|
static void android_os_Debug_getMemInfo(JNIEnv *env, jobject clazz, jlongArray out)
|
||||||
{
|
{
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
int numFound = 0;
|
size_t numFound = 0;
|
||||||
|
|
||||||
if (out == NULL) {
|
if (out == NULL) {
|
||||||
jniThrowNullPointerException(env, "out == null");
|
jniThrowNullPointerException(env, "out == null");
|
||||||
@@ -646,7 +669,7 @@ static void android_os_Debug_getMemInfo(JNIEnv *env, jobject clazz, jlongArray o
|
|||||||
long mem[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
long mem[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||||
|
|
||||||
char* p = buffer;
|
char* p = buffer;
|
||||||
while (*p && numFound < 13) {
|
while (*p && numFound < (sizeof(tagsLen) / sizeof(tagsLen[0]))) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (tags[i]) {
|
while (tags[i]) {
|
||||||
if (strncmp(p, tags[i], tagsLen[i]) == 0) {
|
if (strncmp(p, tags[i], tagsLen[i]) == 0) {
|
||||||
@@ -679,6 +702,9 @@ static void android_os_Debug_getMemInfo(JNIEnv *env, jobject clazz, jlongArray o
|
|||||||
mem[MEMINFO_ZRAM_TOTAL] = atoll(buffer)/1024;
|
mem[MEMINFO_ZRAM_TOTAL] = atoll(buffer)/1024;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Recompute Vmalloc Used since the value in meminfo
|
||||||
|
// doesn't account for I/O remapping which doesn't use RAM.
|
||||||
|
mem[MEMINFO_VMALLOC_USED] = get_allocated_vmalloc_memory() / 1024;
|
||||||
|
|
||||||
int maxNum = env->GetArrayLength(out);
|
int maxNum = env->GetArrayLength(out);
|
||||||
if (maxNum > MEMINFO_COUNT) {
|
if (maxNum > MEMINFO_COUNT) {
|
||||||
@@ -693,6 +719,7 @@ static void android_os_Debug_getMemInfo(JNIEnv *env, jobject clazz, jlongArray o
|
|||||||
env->ReleaseLongArrayElements(out, outArray, 0);
|
env->ReleaseLongArrayElements(out, outArray, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static jint read_binder_stat(const char* stat)
|
static jint read_binder_stat(const char* stat)
|
||||||
{
|
{
|
||||||
FILE* fp = fopen(BINDER_STATS, "r");
|
FILE* fp = fopen(BINDER_STATS, "r");
|
||||||
|
|||||||
Reference in New Issue
Block a user