Re: [PATCH v38 16/24] x86/sgx: Add a page reclaimer

Sean Christopherson
2020-09-29T08:35:36Z

On Tue, Sep 29, 2020 at 06:50:10AM +0300, Jarkko Sakkinen wrote:
> On Mon, Sep 28, 2020 at 06:14:39PM -0700, Sean Christopherson wrote:
> > On Tue, Sep 22, 2020 at 05:03:23PM +0300, Jarkko Sakkinen wrote:
> > > On Tue, Sep 22, 2020 at 12:45:38PM +0200, Borislav Petkov wrote:
> > > > > + spin_lock(&sgx_active_page_list_lock);
> > > > > + for (i = 0; i < SGX_NR_TO_SCAN; i++) {
> > > > > + if (list_empty(&sgx_active_page_list))
> > > >
> > > > Isn't it enough to do this once, i.e., not in the loop? You're holding
> > > > sgx_active_page_list_lock...
> >
> > Argh, I missed this until I looked at Jarkko's updated tree.
> >
> > The reason for checking list_empty() on every iteration is that the loop is
> > greedy, i.e. it tries to grab and reclaim up to 16 (SGX_NR_TO_SCAN) EPC pages
> > at a time.
> >
> > > I think that would make sense. Distantly analogous to the EINIT
> > > discussion. Too complex code for yet to be known problem workloads I'd
> > > say.
> >
> > Nooooo. Please no.
>
> I added this comment in the beginning of the sgx_reclaim_pages() based
> on your response:
>
> /*
> * Take a fixed number of pages from the head of the active page pool and
> * reclaim them to the enclave's private shmem files. Skip the pages, which have
> * been accessed since the last scan. Move those pages to the tail of active
> * page pool so that the pages get scanned in LRU like fashion.
> *
> * Batch process a chunk of pages (at the moment 16) 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.
> */
>
> And reverted reclaimer patch as it was. Do you have anything in mind
> that I should add or modify in it?

Nope, can't think of anything.