Skip to content

Commit

Permalink
proc: Don't let Google Camera run in the background
Browse files Browse the repository at this point in the history
Google Camera burns through CPU in the background doing nothing useful.
It indefinitely causes Google Photos' CPU usage to go to 150% and
increases the CPU utilization of some other system processes.

Kill it when it becomes backgrounded to prevent it from killing battery
life.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
  • Loading branch information
kerneltoast authored and acuicultor committed Sep 15, 2021
1 parent 371648a commit 2d2f424
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions fs/proc/base.c
Expand Up @@ -105,6 +105,22 @@
#include <oneplus/houston/houston_helper.h>
#include <linux/oem/control_center.h>


struct task_kill_info {
struct task_struct *task;
struct work_struct work;
};

static void proc_kill_task(struct work_struct *work)
{
struct task_kill_info *kinfo = container_of(work, typeof(*kinfo), work);
struct task_struct *task = kinfo->task;

send_sig(SIGKILL, task, 0);
put_task_struct(task);
kfree(kinfo);
}

/* NOTE:
* Implementing inode permission operations in /proc is almost
* certainly an error. Permission checks need to happen during
Expand Down Expand Up @@ -1197,6 +1213,7 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
{
static DEFINE_MUTEX(oom_adj_mutex);
struct mm_struct *mm = NULL;
char task_comm[TASK_COMM_LEN];
struct task_struct *task;
int err = 0;

Expand Down Expand Up @@ -1247,6 +1264,8 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
if (!legacy && has_capability_noaudit(current, CAP_SYS_RESOURCE))
task->signal->oom_score_adj_min = (short)oom_adj;
trace_oom_score_adj_update(task);
if (oom_adj >= 700)
strncpy(task_comm, task->comm, TASK_COMM_LEN);

if (mm) {
struct task_struct *p;
Expand Down Expand Up @@ -1274,6 +1293,20 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
err_unlock:
mutex_unlock(&oom_adj_mutex);
put_task_struct(task);
/* These apps burn through CPU in the background. Don't let them. */
if (!err && oom_adj >= 700) {
if (!strcmp(task_comm, "id.GoogleCamera")) {
struct task_kill_info *kinfo;

kinfo = kmalloc(sizeof(*kinfo), GFP_KERNEL);
if (kinfo) {
get_task_struct(task);
kinfo->task = task;
INIT_WORK(&kinfo->work, proc_kill_task);
schedule_work(&kinfo->work);
}
}
}
return err;
}

Expand Down

0 comments on commit 2d2f424

Please sign in to comment.