Loading core/java/android/os/Process.java +13 −0 Original line number Diff line number Diff line Loading @@ -893,6 +893,19 @@ public class Process { */ public static final native boolean setOomAdj(int pid, int amt); /** * Adjust the swappiness level for a process. * * @param pid The process identifier to set. * @param is_increased Whether swappiness should be increased or default. * * @return Returns true if the underlying system supports this * feature, else false. * * {@hide} */ public static final native boolean setSwappiness(int pid, boolean is_increased); /** * Change this process's argv[0] parameter. This can be useful to show * more descriptive information in things like the 'ps' command. Loading core/jni/android_util_Process.cpp +28 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ #include <sys/errno.h> #include <sys/resource.h> #include <sys/types.h> #include <sys/stat.h> #include <dirent.h> #include <fcntl.h> #include <grp.h> Loading Loading @@ -381,6 +382,32 @@ jboolean android_os_Process_setOomAdj(JNIEnv* env, jobject clazz, return false; } jboolean android_os_Process_setSwappiness(JNIEnv *env, jobject clazz, jint pid, jboolean is_increased) { char text[64]; if (is_increased) { strcpy(text, "/sys/fs/cgroup/memory/sw/tasks"); } else { strcpy(text, "/sys/fs/cgroup/memory/tasks"); } struct stat st; if (stat(text, &st) || !S_ISREG(st.st_mode)) { return false; } int fd = open(text, O_WRONLY); if (fd >= 0) { sprintf(text, "%d", pid); write(fd, text, strlen(text)); close(fd); } return true; } void android_os_Process_setArgV0(JNIEnv* env, jobject clazz, jstring name) { if (name == NULL) { Loading Loading @@ -1022,6 +1049,7 @@ static const JNINativeMethod methods[] = { {"setProcessGroup", "(II)V", (void*)android_os_Process_setProcessGroup}, {"getProcessGroup", "(I)I", (void*)android_os_Process_getProcessGroup}, {"setOomAdj", "(II)Z", (void*)android_os_Process_setOomAdj}, {"setSwappiness", "(IZ)Z", (void*)android_os_Process_setSwappiness}, {"setArgV0", "(Ljava/lang/String;)V", (void*)android_os_Process_setArgV0}, {"setUid", "(I)I", (void*)android_os_Process_setUid}, {"setGid", "(I)I", (void*)android_os_Process_setGid}, Loading services/java/com/android/server/am/ActivityManagerService.java +2 −0 Original line number Diff line number Diff line Loading @@ -14510,6 +14510,8 @@ public final class ActivityManagerService extends ActivityManagerNative } } } Process.setSwappiness(app.pid, app.curSchedGroup <= Process.THREAD_GROUP_BG_NONINTERACTIVE); } } if (app.repProcState != app.curProcState) { Loading
core/java/android/os/Process.java +13 −0 Original line number Diff line number Diff line Loading @@ -893,6 +893,19 @@ public class Process { */ public static final native boolean setOomAdj(int pid, int amt); /** * Adjust the swappiness level for a process. * * @param pid The process identifier to set. * @param is_increased Whether swappiness should be increased or default. * * @return Returns true if the underlying system supports this * feature, else false. * * {@hide} */ public static final native boolean setSwappiness(int pid, boolean is_increased); /** * Change this process's argv[0] parameter. This can be useful to show * more descriptive information in things like the 'ps' command. Loading
core/jni/android_util_Process.cpp +28 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ #include <sys/errno.h> #include <sys/resource.h> #include <sys/types.h> #include <sys/stat.h> #include <dirent.h> #include <fcntl.h> #include <grp.h> Loading Loading @@ -381,6 +382,32 @@ jboolean android_os_Process_setOomAdj(JNIEnv* env, jobject clazz, return false; } jboolean android_os_Process_setSwappiness(JNIEnv *env, jobject clazz, jint pid, jboolean is_increased) { char text[64]; if (is_increased) { strcpy(text, "/sys/fs/cgroup/memory/sw/tasks"); } else { strcpy(text, "/sys/fs/cgroup/memory/tasks"); } struct stat st; if (stat(text, &st) || !S_ISREG(st.st_mode)) { return false; } int fd = open(text, O_WRONLY); if (fd >= 0) { sprintf(text, "%d", pid); write(fd, text, strlen(text)); close(fd); } return true; } void android_os_Process_setArgV0(JNIEnv* env, jobject clazz, jstring name) { if (name == NULL) { Loading Loading @@ -1022,6 +1049,7 @@ static const JNINativeMethod methods[] = { {"setProcessGroup", "(II)V", (void*)android_os_Process_setProcessGroup}, {"getProcessGroup", "(I)I", (void*)android_os_Process_getProcessGroup}, {"setOomAdj", "(II)Z", (void*)android_os_Process_setOomAdj}, {"setSwappiness", "(IZ)Z", (void*)android_os_Process_setSwappiness}, {"setArgV0", "(Ljava/lang/String;)V", (void*)android_os_Process_setArgV0}, {"setUid", "(I)I", (void*)android_os_Process_setUid}, {"setGid", "(I)I", (void*)android_os_Process_setGid}, Loading
services/java/com/android/server/am/ActivityManagerService.java +2 −0 Original line number Diff line number Diff line Loading @@ -14510,6 +14510,8 @@ public final class ActivityManagerService extends ActivityManagerNative } } } Process.setSwappiness(app.pid, app.curSchedGroup <= Process.THREAD_GROUP_BG_NONINTERACTIVE); } } if (app.repProcState != app.curProcState) {