size_t viv_gpu_resmem_query(struct task_struct *p, struct reserved_memory_account *m) { gcuDATABASE_INFO info; unsigned int processid = p->pid; gckKERNEL gpukernel = m->data; /* ignore error happens in this api. */ if (gckKERNEL_QueryProcessDB(gpukernel, processid, false, gcvDB_VIDEO_MEMORY, &info) != gcvSTATUS_OK) return 0; /* we return pages. */ if (info.counters.bytes > 0) return info.counters.bytes / PAGE_SIZE; return 0; }
static int force_contiguous_lowmem_shrink(IN gckKERNEL Kernel) { struct task_struct *p; struct task_struct *selected = NULL; int tasksize; int ret = -1; int min_adj = 0; int selected_tasksize = 0; int selected_oom_adj; /* * If we already have a death outstanding, then * bail out right away; indicating to vmscan * that we have nothing further to offer on * this pass. * */ if (lowmem_deathpending && time_before_eq(jiffies, lowmem_deathpending_timeout)) return 0; selected_oom_adj = min_adj; rcu_read_lock(); for_each_process(p) { struct mm_struct *mm; struct signal_struct *sig; gcuDATABASE_INFO info; int oom_adj; task_lock(p); mm = p->mm; sig = p->signal; if (!mm || !sig) { task_unlock(p); continue; } oom_adj = sig->oom_score_adj; if (oom_adj < min_adj) { task_unlock(p); continue; } tasksize = 0; task_unlock(p); rcu_read_unlock(); if (gckKERNEL_QueryProcessDB(Kernel, p->pid, gcvFALSE, gcvDB_VIDEO_MEMORY, &info) == gcvSTATUS_OK){ tasksize += info.counters.bytes / PAGE_SIZE; } if (gckKERNEL_QueryProcessDB(Kernel, p->pid, gcvFALSE, gcvDB_CONTIGUOUS, &info) == gcvSTATUS_OK){ tasksize += info.counters.bytes / PAGE_SIZE; } rcu_read_lock(); if (tasksize <= 0) continue; gckOS_Print("<gpu> pid %d (%s), adj %d, size %d \n", p->pid, p->comm, oom_adj, tasksize); if (selected) { if (oom_adj < selected_oom_adj) continue; if (oom_adj == selected_oom_adj && tasksize <= selected_tasksize) continue; } selected = p; selected_tasksize = tasksize; selected_oom_adj = oom_adj; } if (selected) { gckOS_Print("<gpu> send sigkill to %d (%s), adj %d, size %d\n", selected->pid, selected->comm, selected_oom_adj, selected_tasksize); lowmem_deathpending = selected; lowmem_deathpending_timeout = jiffies + HZ; force_sig(SIGKILL, selected); ret = 0; } rcu_read_unlock(); return ret; }