Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp2501391rdh; Sun, 26 Nov 2023 08:28:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IHnzilhvYwEnhU8B/5uOkIwCXc/skPaF+XiRZ3lxQFNi4XyKmDqUN+GAhrKScM6kwW/CPua X-Received: by 2002:a17:902:b687:b0:1cf:a533:e692 with SMTP id c7-20020a170902b68700b001cfa533e692mr5791236pls.34.1701016097599; Sun, 26 Nov 2023 08:28:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701016097; cv=none; d=google.com; s=arc-20160816; b=Y0jLwUA7wXC9sSvG9jZ+CoZWE4I0ToqwszwYgbeZntnyDg02BQG2bWVQaEPvCg2eQx S4Wsv3a8p+rzSdQSEajYqUgfQ9g8FnIhDo3/rfnnnfBeKEb73Rm7ArynFjvtExI6YLUS ZgP9NYxHJ2eExicEPJJr2XRgxy6W8VfDXfAn9oyqxL6Hgazu7ArvMBlBuVGFQWiS6vE8 pBAKfNutaUjCxYQhbIZ1488rWwLu3+oY21izXnIIiJ42EDaDeMuYW3TtVTVLY8L47V6P LtetAXjYptAic0Xqgy9sf+PyLQOQmpsoQaQHsNeB+fS4CCZmiZ5R/PgYopRbgs2TWCRM 0WDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:message-id:organization :from:content-transfer-encoding:mime-version:date:references:subject :cc:to:dkim-signature; bh=VholybO9gaMsK7k0JzxWRkC3LFYdUYCl17d9hhSr5oI=; fh=6piHGeTS3Qc8WUQKl1RrBK75Ci69xG4hiFRLfzlL6uI=; b=H8W5yRXRCfhyteXie+Q/sHOR4gmq1GIedxABPbVOCWW3jUCJqmsPWmWnRBc9+ovtba KnvyBCD0UzJjXT/lX5kf7wMmLRCYWzA5h5yTQPOnBYbvWrfi2pJIWliKvzfL/131CNOq amvQtEccsAbia1Ts5Kqm/JZtADlrPHuVMrWSNgrnHkPMHCXIXeYcyuStJ9AmdWEEOKgu 2F4jrTKbl13wrdfjkCF9j+6EKDRk2f6RwL0LclYsqqqoYR3y78ef3dd4h0/5wlXxX0NZ Ez4Cx9QVmA514TwrdazNMHF5t8tTriztlmIJHNAqp9TWR0oKLli+EyXtoaYhMiFWk2Es doyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VoujsxvK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id p2-20020a170902e74200b001cfb1dab1b0si4150822plf.589.2023.11.26.08.28.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 08:28:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VoujsxvK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id A45AA8098EB6; Sun, 26 Nov 2023 08:28:11 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229562AbjKZQ1n (ORCPT + 99 others); Sun, 26 Nov 2023 11:27:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbjKZQ1m (ORCPT ); Sun, 26 Nov 2023 11:27:42 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F13BD3; Sun, 26 Nov 2023 08:27:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701016068; x=1732552068; h=to:cc:subject:references:date:mime-version: content-transfer-encoding:from:message-id:in-reply-to; bh=aI1kuUAX1aIYfPW4zBmDRxcAyohGsXeNpLue5KrlY18=; b=VoujsxvKXZuNtu/GUQKL/N4435i/He82sl/2TOrvQYLuTsTbi3HMjuIC ExmFEXl6vCMCIHtzHr7Diw+JeFLdkUw9HEknycxGUyg+IBzsQCfCVM9GF ugW2F3hnG15d+CbcC+Yz110TH7Tc0MkslGWGWrXUkPpa3io1HBkHllCHn WSdsL8xgoJgHH5Oan3+cveGwD8gYrOrH+bkrFM/A9kniDyf3/bMYxGiHI PtxmUrhn83tEbOvYgjEDhGbwtD7hYueHkZOcFGlTNsrt8PfqNivpUICsJ SGmRCZ0seW2G6IrIBiAiAOq9oZOjVwyGKD7IMhUh2XsaT6Whpd/KBPEh4 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10906"; a="377624197" X-IronPort-AV: E=Sophos;i="6.04,229,1695711600"; d="scan'208";a="377624197" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Nov 2023 08:27:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,229,1695711600"; d="scan'208";a="9406610" Received: from hhuan26-mobl.amr.corp.intel.com ([10.124.112.56]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-SHA; 26 Nov 2023 08:27:43 -0800 Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes To: "hpa@zytor.com" , "linux-sgx@vger.kernel.org" , "x86@kernel.org" , "dave.hansen@linux.intel.com" , "jarkko@kernel.org" , "cgroups@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "mkoutny@suse.com" , "tglx@linutronix.de" , "Mehta, Sohil" , "tj@kernel.org" , "mingo@redhat.com" , "bp@alien8.de" , "Huang, Kai" Cc: "mikko.ylinen@linux.intel.com" , "seanjc@google.com" , "Zhang, Bo" , "kristen@linux.intel.com" , "yangjie@microsoft.com" , "sean.j.christopherson@intel.com" , "Li, Zhiquan1" , "anakrish@microsoft.com" Subject: Re: [PATCH v6 09/12] x86/sgx: Restructure top-level EPC reclaim function References: <20231030182013.40086-1-haitao.huang@linux.intel.com> <20231030182013.40086-10-haitao.huang@linux.intel.com> Date: Mon, 27 Nov 2023 00:27:39 +0800 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: "Haitao Huang" Organization: Intel Message-ID: In-Reply-To: User-Agent: Opera Mail/1.0 (Win32) X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Sun, 26 Nov 2023 08:28:11 -0800 (PST) On Mon, 20 Nov 2023 11:45:46 +0800, Huang, Kai wrote: > On Mon, 2023-10-30 at 11:20 -0700, Haitao Huang wrote: >> From: Sean Christopherson >> >> To prepare for per-cgroup reclamation, separate the top-level reclaim >> function, sgx_reclaim_epc_pages(), into two separate functions: >> >> - sgx_isolate_epc_pages() scans and isolates reclaimable pages from a >> given LRU list. >> - sgx_do_epc_reclamation() performs the real reclamation for the >> already isolated pages. >> >> Create a new function, sgx_reclaim_epc_pages_global(), calling those two >> in succession, to replace the original sgx_reclaim_epc_pages(). The >> above two functions will serve as building blocks for the reclamation >> flows in later EPC cgroup implementation. >> >> sgx_do_epc_reclamation() returns the number of reclaimed pages. The EPC >> cgroup will use the result to track reclaiming progress. >> >> sgx_isolate_epc_pages() returns the additional number of pages to scan >> for current epoch of reclamation. The EPC cgroup will use the result to >> determine if more scanning to be done in LRUs in its children groups. > > This changelog says nothing about "why", but only mentions the > "implementation". > > For instance, assuming we need to reclaim @npages_to_reclaim from the > @epc_cgrp_to_reclaim and its descendants, why cannot we do: > > for_each_cgroup_and_descendants(&epc_cgrp_to_reclaim, &epc_cgrp) { > if (npages_to_reclaim <= 0) > return; > > npages_to_reclaim -= sgx_reclaim_pages_lru(&epc_cgrp->lru, > npages_to_reclaim); > } > > Is there any difference to have "isolate" + "reclaim"? > This is to optimize "reclaim". See how etrack was done in sgx_encl_ewb. Here we just follow the same design as ksgxd for each reclamation cycle. >> >> Signed-off-by: Sean Christopherson >> Co-developed-by: Kristen Carlson Accardi >> Signed-off-by: Kristen Carlson Accardi >> Co-developed-by: Haitao Huang >> Signed-off-by: Haitao Huang >> Cc: Sean Christopherson >> --- >> > > [...] > >> +/** >> + * sgx_do_epc_reclamation() - Perform reclamation for isolated EPC >> pages. >> + * @iso: List of isolated pages for reclamation >> + * >> + * Take a list of EPC pages and reclaim them to the enclave's private >> shmem files. Do not >> + * reclaim the pages that have been accessed since the last scan, and >> move each of those pages >> + * to the tail of its tracking LRU list. >> + * >> + * Limit the number of pages to be processed up to SGX_NR_TO_SCAN_MAX >> per call in order to >> + * degrade amount of IPI's and ETRACK's potentially required. >> sgx_encl_ewb() does degrade a bit >> + * among the HW threads with three stage EWB pipeline (EWB, ETRACK + >> EWB and IPI + EWB) but not >> + * sufficiently. Reclaiming one page at a time would also be >> problematic as it would increase >> + * the lock contention too much, which would halt forward progress. > > This is kinda optimization, correct? Is there any real performance data > to > justify this? The above sentences were there originally. This optimization was justified. > If this optimization is useful, shouldn't we bring this > optimization to the current sgx_reclaim_pages() instead, e.g., just > increase > SGX_NR_TO_SCAN (16) to SGX_NR_TO_SCAN_MAX (32)? > SGX_NR_TO_SCAN_MAX might be designed earlier for other reasons I don't know. Currently it is really the buffer size allocated in sgx_reclaim_pages(). Both cgroup and ksgxd scan 16 pages a time.Maybe we should just use SGX_NR_TO_SCAN. No _MAX needed. The point was to batch reclamation to certain number to minimize impact of EWB pipeline. 16 was the original design. Thanks Haitao