From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E20A0C433EF for ; Fri, 20 May 2022 15:44:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B1746B0071; Fri, 20 May 2022 11:44:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 45E056B0072; Fri, 20 May 2022 11:44:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2FF996B0073; Fri, 20 May 2022 11:44:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 21B1B6B0071 for ; Fri, 20 May 2022 11:44:19 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E474921901 for ; Fri, 20 May 2022 15:44:18 +0000 (UTC) X-FDA: 79486542996.08.4776E26 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by imf07.hostedemail.com (Postfix) with ESMTP id 0C83540014 for ; Fri, 20 May 2022 15:44:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653061458; x=1684597458; h=message-id:subject:from:to:cc:date:in-reply-to: references:mime-version:content-transfer-encoding; bh=Sm6rTxFjZJcJqtXNux3YigLFzIK7e0k9ReiYe3hBU1c=; b=ZV2PZPE6UD3Z8w9CM+V9+ILAA+csIRvu3GI8Uv34pZpkoQk7UOXI/bGA GX/6CkFms5t/Lq7ewaWpOGWWN7j8i6itMZiZ3KD6dDPK2BBpepmy8r4R6 PEKfB3JrAy8iymICUXnosi/V26Yjc5aHHGT4Za1m7x5VXdFqW3RQpjZ3q NG0pYW9/ly6wy1m5ofzmt6ncDnWbG4owsAjrFQkhhB0je4n1GMNgp8qlw USunHAUQ+wlypFrO66rwfbEY2FqMYEEwPhd1HY/yCSVr4xjUq9zUuNDRl eLR0BXBR3YFGlp6UDGILJ6yxeBWMe6ZyCSQAcoaVpDu2ElRrlk5NkVmgV A==; X-IronPort-AV: E=McAfee;i="6400,9594,10353"; a="333267356" X-IronPort-AV: E=Sophos;i="5.91,239,1647327600"; d="scan'208";a="333267356" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 May 2022 08:44:16 -0700 X-IronPort-AV: E=Sophos;i="5.91,239,1647327600"; d="scan'208";a="546737649" Received: from kcaccard-mobl.amr.corp.intel.com (HELO kcaccard-mobl1.jf.intel.com) ([10.209.83.65]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 May 2022 08:44:15 -0700 Message-ID: <12ba3f76f06d1336d78e4bfe0f36ba83fbf2f2d1.camel@linux.intel.com> Subject: Re: [PATCH v2] x86/sgx: Set active memcg prior to shmem allocation From: Kristen Carlson Accardi To: Shakeel Butt Cc: linux-sgx@vger.kernel.org, Jarkko Sakkinen , Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , stable , LKML , Linux MM , Michal Hocko , Roman Gushchin , Johannes Weiner Date: Fri, 20 May 2022 08:44:14 -0700 In-Reply-To: References: <20220519210445.5310-1-kristen@linux.intel.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.30.5 (3.30.5-1.fc29) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Queue-Id: 0C83540014 X-Stat-Signature: bzupubqbdypy5p3i1r833ez6xn4oais8 Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=ZV2PZPE6; spf=none (imf07.hostedemail.com: domain of kristen@linux.intel.com has no SPF policy when checking 134.134.136.31) smtp.mailfrom=kristen@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspamd-Server: rspam03 X-HE-Tag: 1653061448-737791 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, 2022-05-19 at 14:22 -0700, Shakeel Butt wrote: > On Thu, May 19, 2022 at 2:05 PM Kristen Carlson Accardi > wrote: > > When the system runs out of enclave memory, SGX can reclaim EPC > > pages > > by swapping to normal RAM. These backing pages are allocated via a > > per-enclave shared memory area. Since SGX allows unlimited over > > commit on EPC memory, the reclaimer thread can allocate a large > > number of backing RAM pages in response to EPC memory pressure. > > > > When the shared memory backing RAM allocation occurs during > > the reclaimer thread context, the shared memory is charged to > > the root memory control group, and the shmem usage of the enclave > > is not properly accounted for, making cgroups ineffective at > > limiting the amount of RAM an enclave can consume. > > > > For example, when using a cgroup to launch a set of test > > enclaves, the kernel does not properly account for 50% - 75% of > > shmem page allocations on average. In the worst case, when > > nearly all allocations occur during the reclaimer thread, the > > kernel accounts less than a percent of the amount of shmem used > > by the enclave's cgroup to the correct cgroup. > > > > SGX stores a list of mm_structs that are associated with > > an enclave. Pick one of them during reclaim and charge that > > mm's memcg with the shmem allocation. The one that gets picked > > is arbitrary, but this list almost always only has one mm. The > > cases where there is more than one mm with different memcg's > > are not worth considering. > > > > Create a new function - sgx_encl_alloc_backing(). This function > > is used whenever a new backing storage page needs to be > > allocated. Previously the same function was used for page > > allocation as well as retrieving a previously allocated page. > > Prior to backing page allocation, if there is a mm_struct > > associated > > with the enclave that is requesting the allocation, it is set > > as the active memory control group. > > > > Signed-off-by: Kristen Carlson Accardi > > For the memcg part: > > Reviewed-by: Shakeel Butt Thanks!