Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7640556rwb; Tue, 15 Nov 2022 15:40:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf7LuOYvk7xXM5hYH87BDT7clul1y7deDR6urpaeb5u3IPmmdliVL2/UQIyW+N2LqEjaFQjB X-Received: by 2002:a50:ff04:0:b0:462:709:9f7b with SMTP id a4-20020a50ff04000000b0046207099f7bmr17697136edu.263.1668555642577; Tue, 15 Nov 2022 15:40:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668555642; cv=none; d=google.com; s=arc-20160816; b=yACLTZSH7keKqD/GRIe2jgeJgOW7Hs7ZMP6+ACWZitCD0dHbHW2VE2zPhl8LOylvHj X4K4VPuZ7FYPmjT5BTMaKTmgfaTd9MLVM/CK/Qiwqnfws3Ng21br96xEgflaFL92ABNa g/9kQy40+/lcEqNrFctEve6Vm+z1/d6Lrd6dBGllkGDVONC9RRiwtro3bwJBBxdsozQY uvUL84whlf/TuEkmgj3GhN6mP332BgUHsi7iMXLdIi0N3FawtoPCTuuZ3yh4aKTISJYo ftyhMNf5xv4TxUlWwvSU/XR+xVQuKoyNElRWsLLzzHK+2n2Zqd3CsQK92vBHs5aklDg4 yQYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=e7qH3/AyziBFi+k/ASDlxKriA4GnpIeE8MN7+kHKTzo=; b=079TIMX0AU3CsE2S2kkiK5BBFkHxvohpxVEl3WvZvEtvrCfsYQsBO3QGjxPhJw5vkS Xlpl9zxdqonprH1T3EAcff5tUAwfk62vA36bfySc3yPEf3nRqZ6O3O5FOtW/Lfy4kfW3 i+2IuLrS72SPPwXOJWxsF8hyqlSB8BQf2VO7efk8RJxghccQdsAZ+RgbUVqfzbsZW2Kq +EjPqU1IQHujzkXuAAFylWSbrV67IJgKqORZ9CvVrEmukwWbHuLQPaJVBQZ671ekuaaZ JvJywp001nZ8Kgjg5oFBmc6VxvCWHSuCbHesCdWhng2pI3sTPCK3Sm7BhPZ3mguX+POZ lVMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ln62TKu1; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l20-20020a056402255400b0044e987f3a34si14693374edb.489.2022.11.15.15.40.20; Tue, 15 Nov 2022 15:40:42 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=ln62TKu1; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231450AbiKOX2D (ORCPT + 91 others); Tue, 15 Nov 2022 18:28:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229607AbiKOX1l (ORCPT ); Tue, 15 Nov 2022 18:27:41 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08B5027930; Tue, 15 Nov 2022 15:27:40 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 99E486178B; Tue, 15 Nov 2022 23:27:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FBCEC433D6; Tue, 15 Nov 2022 23:27:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668554859; bh=w0ksqa3sKu6KJhhOKvS+AupK4IwA9FEjgKk5vq3U3tw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ln62TKu1ZIyIpWsRg++DjRXNcsharCAUz2MPbVXfne17UYIAMd2VsEWpiBXA9JSk6 DwkYJsdm7o/Mpkhs/qIORc2l2K8aCASLvO8Y3vj0GKj/u43/vBAMF6djiZyHlpMj6t uzEBNxpRawrlEQgHqbgXHNGqNa5TGNpPK9e4ebB1UJ2BGI/GfGIRsclEPsHXuaiioE W3tUFa2HYqeyi5MiO5A5aia8qN4s6YQRsX+F4vKT6b79+nFA1pkeZzh9uiXgs6P/hD jKQAws2PBDXK69U7h1GliXPXCwYI6Jt6u7uyIx5RllGmKm1rmLiHYrj4sPhtNewKja ojhWpBNjcu4cg== Date: Wed, 16 Nov 2022 01:27:35 +0200 From: Jarkko Sakkinen To: Kristen Carlson Accardi Cc: dave.hansen@linux.kernel.org, tj@kernel.org, linux-kernel@vger.kernel.org, linux-sgx@vger.kernel.org, cgroups@vger.kernel.org, Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , zhiquan1.li@intel.com, Sean Christopherson Subject: Re: [PATCH 01/26] x86/sgx: Call cond_resched() at the end of sgx_reclaim_pages() Message-ID: References: <20221111183532.3676646-1-kristen@linux.intel.com> <20221111183532.3676646-2-kristen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221111183532.3676646-2-kristen@linux.intel.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 Fri, Nov 11, 2022 at 10:35:06AM -0800, Kristen Carlson Accardi wrote: > From: Sean Christopherson > > In order to avoid repetition of cond_resched() in ksgxd() and > sgx_alloc_epc_page(), move the invocation of post-reclaim cond_resched() > inside sgx_reclaim_pages(). Except in the case of sgx_reclaim_direct(), > sgx_reclaim_pages() is always called in a loop and is always followed > by a call to cond_resched(). This will hold true for the EPC cgroup > as well, which adds even more calls to sgx_reclaim_pages() and thus > cond_resched(). Calls to sgx_reclaim_direct() may be performance > sensitive. Allow sgx_reclaim_direct() to avoid the cond_resched() > call by moving the original sgx_reclaim_pages() call to > __sgx_reclaim_pages() and then have sgx_reclaim_pages() become a > wrapper around that call with a cond_resched(). > > Signed-off-by: Sean Christopherson > Signed-off-by: Kristen Carlson Accardi > Cc: Sean Christopherson > --- > arch/x86/kernel/cpu/sgx/main.c | 17 +++++++++++------ > 1 file changed, 11 insertions(+), 6 deletions(-) > > diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c > index 160c8dbee0ab..ffce6fc70a1f 100644 > --- a/arch/x86/kernel/cpu/sgx/main.c > +++ b/arch/x86/kernel/cpu/sgx/main.c > @@ -287,7 +287,7 @@ static void sgx_reclaimer_write(struct sgx_epc_page *epc_page, > * problematic as it would increase the lock contention too much, which would > * halt forward progress. > */ > -static void sgx_reclaim_pages(void) > +static void __sgx_reclaim_pages(void) > { > struct sgx_epc_page *chunk[SGX_NR_TO_SCAN]; > struct sgx_backing backing[SGX_NR_TO_SCAN]; > @@ -369,6 +369,12 @@ static void sgx_reclaim_pages(void) > } > } > > +static void sgx_reclaim_pages(void) > +{ > + __sgx_reclaim_pages(); > + cond_resched(); > +} > + > static bool sgx_should_reclaim(unsigned long watermark) > { > return atomic_long_read(&sgx_nr_free_pages) < watermark && > @@ -378,12 +384,14 @@ static bool sgx_should_reclaim(unsigned long watermark) > /* > * sgx_reclaim_direct() should be called (without enclave's mutex held) > * in locations where SGX memory resources might be low and might be > - * needed in order to make forward progress. > + * needed in order to make forward progress. This call to > + * __sgx_reclaim_pages() avoids the cond_resched() in sgx_reclaim_pages() > + * to improve performance. > */ > void sgx_reclaim_direct(void) > { > if (sgx_should_reclaim(SGX_NR_LOW_PAGES)) > - sgx_reclaim_pages(); > + __sgx_reclaim_pages(); Is it a big deal to have "extra" cond_resched? > } > > static int ksgxd(void *p) > @@ -410,8 +418,6 @@ static int ksgxd(void *p) > > if (sgx_should_reclaim(SGX_NR_HIGH_PAGES)) > sgx_reclaim_pages(); > - > - cond_resched(); > } > > return 0; > @@ -582,7 +588,6 @@ struct sgx_epc_page *sgx_alloc_epc_page(void *owner, bool reclaim) > } > > sgx_reclaim_pages(); > - cond_resched(); > } > > if (sgx_should_reclaim(SGX_NR_LOW_PAGES)) > -- > 2.37.3 > BR, Jarkko