Re: [PATCH v9 09/15] x86/sgx: Charge mem_cgroup for per-cgroup reclamation

From: Haitao Huang
Date: Fri Feb 16 2024 - 01:07:58 EST


Hi Dave,

On Thu, 15 Feb 2024 17:43:18 -0600, Dave Hansen <dave.hansen@xxxxxxxxx> wrote:

On 2/5/24 13:06, Haitao Huang wrote:
static struct mem_cgroup *sgx_encl_get_mem_cgroup(struct sgx_encl *encl)
{
@@ -1003,14 +1001,6 @@ static struct mem_cgroup *sgx_encl_get_mem_cgroup(struct sgx_encl *encl)
struct sgx_encl_mm *encl_mm;
int idx;

- /*
- * If called from normal task context, return the mem_cgroup
- * of the current task's mm. The remainder of the handling is for
- * ksgxd.
- */
- if (!current_is_ksgxd())
- return get_mem_cgroup_from_mm(current->mm);

Why is this being removed?

Searching the enclave mm list is a last resort. It's expensive and
imprecise.

get_mem_cgroup_from_mm(current->mm), on the other hand is fast and precise.


I introduced a boolean flag to indicate caller is in kthread (ksgxd or cgroup workqueue), so sgx_encl_alloc_backing only calls this function if that flag is true, meaning search through the mm_list is needed.

But now I think a more straightforward way is to just replace current_is_ksgxd() with (current->flags & PF_KTHREAD).

Thanks

Haitao