Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp460207ioo; Sat, 21 May 2022 04:26:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtR6mUdT3bt348L/1jI/B3CuWXyJyxTSxeTn58gm+1EhNXJsyuw5x9GoYuag7wp3h7aY4s X-Received: by 2002:a05:6402:3682:b0:42a:c348:7248 with SMTP id ej2-20020a056402368200b0042ac3487248mr15376048edb.197.1653132399123; Sat, 21 May 2022 04:26:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653132399; cv=none; d=google.com; s=arc-20160816; b=FWZVKfRT7xGkWw3+bdlyHt0elnmxYjNM06aAEpqpRhUYrMePBFIWs6hxW4nhhqJsl6 MXvqHIEbsf3exgdg5AuUhmM3lj6jLYU3PE1Rxtrhj7m//VV4qrOV+UL3GYg/uWfKv8Fj Xw/Ce+rLWKlOLKDjQzUpjUwD3y9Mp3yECJ7MXs5gsPolgHaEGjxDl56nsB7TJkJz8N9d W7tOTS4lwB4hxxdBM3mKWhEHNsPWLo6CEjMu65giBOzO9CqpEki1OwIbTrIeFhSjhyPK sxozS64snOdAt8xLmBc0UqTfJYG0kadnXFYJ2zp9rMRUnM1xZ58mhqSsEoub6eU0tIPD nffw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=IhywgsDH8s+5Cu2nR9F4v4G5nhaoRuY1wGdZWPtOZ64=; b=xUV80yvIKa3KgQ16GZQ4XWiTGm4s5cXcpnTWDnYQVB58nVdEqN+Ji0U0qRUjN8Uggq vmP/MFCPkGGeq/9bP43xGtY3iEy5I1U0XPQIhcwCHOHP1RHawsIi7ntefSJOsq/Y1iy9 kdifGWl0/7M55OVgm/ODelLrXrQ4enheNo/UnvZbh3siHNBvqniRb+myPrc5hq4LoWkV pF4iot/wSpbcHWwMgkH0gR56uao2GWQGSCSGyUjuBc8Cnjrq1En2+e8TgcQOvAy5AmlU iTQJ7ejDVewldRtXYNeVirJgZCU3FAxaw8ja4aZ5fDjuYpIosrPK2D8ceKFlPAI1ndJY IZng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XQbtRWnE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z12-20020a05640235cc00b0042aee970d15si10849855edc.533.2022.05.21.04.26.13; Sat, 21 May 2022 04:26:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XQbtRWnE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350997AbiETPoU (ORCPT + 99 others); Fri, 20 May 2022 11:44:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349157AbiETPoR (ORCPT ); Fri, 20 May 2022 11:44:17 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38BEB9D067; Fri, 20 May 2022 08:44:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653061457; x=1684597457; h=message-id:subject:from:to:cc:date:in-reply-to: references:mime-version:content-transfer-encoding; bh=Sm6rTxFjZJcJqtXNux3YigLFzIK7e0k9ReiYe3hBU1c=; b=XQbtRWnEf7LrEzUXPP/g9dqCG9TbgGLNldJywYiN6hGSCLmo42hlK0M1 V+6Xre2KP/DKIxHvo4b8V0J+pQYNIQZDPWFeTLNVC0jXUzagF96UQYKo6 lTmBKJ/z7KEPZmmt+3k2xsrC9wgTsYZWyFDPFk0ZFyuuzk/0PZ59PSwTr DVpiBkkkUYGs0mA7vQzGLJOhL6LDCtMTxAxyniFm+kq2tmlNX6nRlJII5 n8XC8hsjo1MnQZgsjYRyqwyzB02SN7rDCyhRqM12+heQeNR99fZ6sfo8H nluHdIH+YEXe5ShYGM62UeSZl1wG6RJ/Qz4yuT/Ma31lJhp7bD+f3n4pO g==; X-IronPort-AV: E=McAfee;i="6400,9594,10353"; a="272766035" X-IronPort-AV: E=Sophos;i="5.91,239,1647327600"; d="scan'208";a="272766035" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.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-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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!