Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1462176lqa; Mon, 29 Apr 2024 09:05:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUiEYgBTwciZzv4TEnJlZ17gXfzZAdfVszW2DHGCzlzJYXDzsjiEwYnfiAxKgg8abJSKVyuMzThtlLTsbZ78pKcsVRGeF9xCo58PB4Bgw== X-Google-Smtp-Source: AGHT+IGVcDfnbkQibp8Hs7hDEPBdECAbrbivJeW9r+j2Z9isKKBNVxp1NCzP9aZVI51rwsk81rxV X-Received: by 2002:a17:906:7d3:b0:a58:ed37:8c38 with SMTP id m19-20020a17090607d300b00a58ed378c38mr17256ejc.50.1714406753045; Mon, 29 Apr 2024 09:05:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714406753; cv=pass; d=google.com; s=arc-20160816; b=QVyG7x2vaX2Jx8EJtarVRjc3zT5VuDLHzonDhIML5lXmI9oNYoMmoutYJY8QXJN+d+ e76f53J4gau97GeKU2AGR0lzh/poP1S0o24DWQezxMh8yJmYYJkTRHWDdS86GlzwRZrN ZwfATDe9JysHM7gs3RjOlOj+y9CJo/hQuHreFBd/7zJwl2Zm4oTtCeveez1BrL5imHC2 X9QPNm1F8AlxjF4YhmlwlCY7b1ccdHop92a4TD5JEf9smGrNGUxOI7ZZXY6fuzrvRaSS gWxnpyhMlL8Z+7ViQyBYVbhrIJoDSw2IBeR2IifkuEv4eNFw2zW4uZCszfH1bzdplkYz cF4Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:message-id:organization:from :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:references:subject:cc:to :dkim-signature; bh=37RHKgJQTZ4PC1bff/YS3f6Bbz2h20gfkHIKYx0pceQ=; fh=c7DqcBeHQipkJPapvB1JyMl2o5pSykTZfPfI9Aaj+Z8=; b=DLZ5775+BRrgYpxjc7a7xrUCLzI/kEzQYAffh6Nps4g1J3ysYO2opoukGhXpWja3Rd qxz7IwuJ+p/dn4IWQqpZHRNlhjyD8AG51WFmA+cjTs9bmXNEBQvPh5xJa32Ko5/wKv96 /7ki6H/iW+3zn3P5f0H/x9PvB6EXfhcD5xV8YB3QkDCdFSL0Eeg1ZWKIhlSO2AtOvV9O SzM9MIFnXUXgVo3Pm63CqVHvIMVLp44Tt4SLNDNGAgMOfTv0wO3FB/nYRJYxypx3fosd VEvZRaG0l8Zq6OkLTOEFaT+yuA9OxLL1B4yl8zeXXrSf7o3IBdXvQ7TSQFQCH5d9ncrW VWAg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bTuJhVWN; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-162648-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162648-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id q20-20020a1709066ad400b00a55b559860bsi9881380ejs.320.2024.04.29.09.05.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 09:05:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-162648-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bTuJhVWN; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-162648-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162648-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 9AFAC1F24AFF for ; Mon, 29 Apr 2024 16:05:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E7C5484D39; Mon, 29 Apr 2024 16:05:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="bTuJhVWN" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E4E3839FF; Mon, 29 Apr 2024 16:05:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714406733; cv=none; b=VfABcwvX9C/jshJ22kfh9AOEIFir39o85Dh9FwwGmkmo2w4YqPI+X+HZFwWyUjmRF7sI8a+QDQ5BGuCJvWri0RE2Yb+6BR8GMGF88q2vKKtG+ajb+zfcZwihJi+ID68yXs5tHtORgqVuAsA+YillFAu1fA3iv2nRYWWWfTcd6vU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714406733; c=relaxed/simple; bh=YD/OxqV+lEnK7x1x1U/zl0bii0aWAk483FiEemFo+Fo=; h=Content-Type:To:Cc:Subject:References:Date:MIME-Version:From: Message-ID:In-Reply-To; b=l7p8Mzsm6+QuH39k4dXlurDGV949xEM5Ewwn0Sa/5o8JFCW3+JtN644803hMFwF9MA9276bIlxclQvUh1I64CMpY1sgqsrk/BrAZ1tJdiiUn3yjkbfbEdByFLb+RfUSTdaHMvz8lQmOwAZFXnX1O1A1bRCrsZm1L89ChDNaEOLY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=bTuJhVWN; arc=none smtp.client-ip=198.175.65.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1714406732; x=1745942732; h=to:cc:subject:references:date:mime-version: content-transfer-encoding:from:message-id:in-reply-to; bh=YD/OxqV+lEnK7x1x1U/zl0bii0aWAk483FiEemFo+Fo=; b=bTuJhVWNhicWyNdQICvu1ORlN1R+rP2ALR8OqJKSDMEVg2/S/R42KPFn wE23rVRgpmIF8ggx02W72VqIYpmlYy0EL2YWiGOkS0wtQk26myrCsZ+DX L59LIR1fIwOFoOCpIUSUK/2na4gyDmggIx4ODrY85+xGgRa9evkcHRpBD r/BuN2hEynxfeCTnckCxcWu+vcmACCBTC2MCGPmbcfdGpkm5wAuLPf9cD x5Bh+1J1sjqYPzsnhX7gcnES2Dfn5oIAPwz0rMqzzib/BxrPHVXY8N5d9 V1o/3lbLjGiucr5MZ5gY5LHlwKHavzvnZ+Wg5G4oWgho6RqRDqNzY6uyY g==; X-CSE-ConnectionGUID: zMC3DCQdQ1OCPDOH8byl1Q== X-CSE-MsgGUID: FmI4aMRDQuiGHoM3LjzPbg== X-IronPort-AV: E=McAfee;i="6600,9927,11059"; a="21227659" X-IronPort-AV: E=Sophos;i="6.07,239,1708416000"; d="scan'208";a="21227659" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2024 09:05:26 -0700 X-CSE-ConnectionGUID: 67nfouXGRO+tO2l77+282Q== X-CSE-MsgGUID: Tg2PHMGkRXSTk8vOSprIGQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,239,1708416000"; d="scan'208";a="30977079" Received: from hhuan26-mobl.amr.corp.intel.com ([10.125.99.222]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/AES256-SHA; 29 Apr 2024 09:05:23 -0700 Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes To: "hpa@zytor.com" , "tim.c.chen@linux.intel.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" , "anakrish@microsoft.com" , "Zhang, Bo" , "kristen@linux.intel.com" , "yangjie@microsoft.com" , "Li, Zhiquan1" , "chrisyan@microsoft.com" Subject: Re: [PATCH v12 12/14] x86/sgx: Turn on per-cgroup EPC reclamation References: <20240416032011.58578-1-haitao.huang@linux.intel.com> <20240416032011.58578-13-haitao.huang@linux.intel.com> <524cf9b081d86ae61342fdfc370a3639d0010f94.camel@intel.com> Date: Mon, 29 Apr 2024 11:05:21 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: "Haitao Huang" Organization: Intel Message-ID: In-Reply-To: <524cf9b081d86ae61342fdfc370a3639d0010f94.camel@intel.com> User-Agent: Opera Mail/1.0 (Win32) On Mon, 29 Apr 2024 05:49:13 -0500, Huang, Kai wrote: > >> +/* >> + * Get the per-cgroup or global LRU list that tracks the given >> reclaimable page. >> + */ >> static inline struct sgx_epc_lru_list *sgx_lru_list(struct >> sgx_epc_page *epc_page) >> { >> +#ifdef CONFIG_CGROUP_MISC >> + /* >> + * epc_page->sgx_cg here is never NULL during a reclaimable epc_page's >> + * life between sgx_alloc_epc_page() and sgx_free_epc_page(): >> + * >> + * In sgx_alloc_epc_page(), epc_page->sgx_cg is set to the return from >> + * sgx_get_current_cg() which is the misc cgroup of the current task, >> or >> + * the root by default even if the misc cgroup is disabled by kernel >> + * command line. >> + * >> + * epc_page->sgx_cg is only unset by sgx_free_epc_page(). >> + * >> + * This function is never used before sgx_alloc_epc_page() or after >> + * sgx_free_epc_page(). >> + */ >> + return &epc_page->sgx_cg->lru; >> +#else >> return &sgx_global_lru; >> +#endif >> } >> >> /* >> @@ -42,7 +63,8 @@ static inline struct sgx_epc_lru_list >> *sgx_lru_list(struct sgx_epc_page *epc_pag >> */ >> static inline bool sgx_can_reclaim(void) >> { >> - return !list_empty(&sgx_global_lru.reclaimable); >> + return !sgx_cgroup_lru_empty(misc_cg_root()) || >> + !list_empty(&sgx_global_lru.reclaimable); >> } > > Shouldn't this be: > > if (IS_ENABLED(CONFIG_CGROUP_MISC)) > return !sgx_cgroup_lru_empty(misc_cg_root()); > else > return !list_empty(&sgx_global_lru.reclaimable); > ? > > In this way, it is consistent with the sgx_reclaim_pages_global() below. > I changed to this way because sgx_cgroup_lru_empty() is now defined in both KConfig cases. And it seems better to minimize use of the KConfig variables based on earlier feedback (some are yours). Don't really have strong preference here. So let me know one way of the other. >> >> static atomic_long_t sgx_nr_free_pages = ATOMIC_LONG_INIT(0); >> @@ -404,7 +426,10 @@ static bool sgx_should_reclaim(unsigned long >> watermark) >> >> static void sgx_reclaim_pages_global(struct mm_struct *charge_mm) >> { >> - sgx_reclaim_pages(&sgx_global_lru, charge_mm); >> + if (IS_ENABLED(CONFIG_CGROUP_MISC)) >> + sgx_cgroup_reclaim_pages(misc_cg_root(), charge_mm); >> + else >> + sgx_reclaim_pages(&sgx_global_lru, charge_mm); >> } >> >> /* >> @@ -414,6 +439,14 @@ static void sgx_reclaim_pages_global(struct >> mm_struct *charge_mm) >> */ >> void sgx_reclaim_direct(void) >> { >> + struct sgx_cgroup *sgx_cg = sgx_get_current_cg(); >> + >> + /* Make sure there are some free pages at cgroup level */ >> + if (sgx_cg && sgx_cgroup_should_reclaim(sgx_cg)) { >> + sgx_cgroup_reclaim_pages(misc_from_sgx(sgx_cg), current->mm); >> + sgx_put_cg(sgx_cg); >> + } > > Empty line. > Sure >> + /* Make sure there are some free pages at global level */ >> if (sgx_should_reclaim(SGX_NR_LOW_PAGES)) > > Looking at the code, to me sgx_should_reclaim() is a little bit vague > because from the name we don't know whether it interally checks the > current cgroup or the global. > It's better to rename to sgx_should_reclaim_global(). > > Ditto for sgx_can_reclaim() -> sgx_can_reclaim_global(). > > And I think you can do the renaming in the previous patch, because in the > changelog of your previous patch, it seems you have called out the two > functions are for global reclaim. > ok Thanks Haitao