From: Jarkko Sakkinen <jarkko@kernel.org>
To: Dave Hansen <dave.hansen@intel.com>
Cc: linux-sgx@vger.kernel.org, haitao.huang@intel.com,
dan.j.williams@intel.com, Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86/sgx: Add a basic NUMA allocation scheme to sgx_alloc_epc_page()
Date: Wed, 24 Feb 2021 19:29:49 +0200 [thread overview]
Message-ID: <YDaNDcJvnAen0wZn@kernel.org> (raw)
In-Reply-To: <3b3391bc-8c40-cf08-d09d-90ff1517ff8c@intel.com>
On Tue, Feb 23, 2021 at 11:14:10AM -0800, Dave Hansen wrote:
> On 2/21/21 4:54 PM, Dave Hansen wrote:
> > Instead of having a for-each-section loop, I'd make it for-each-node ->
> > for-each-section. Something like:
> >
> > for (i = 0; i < num_possible_nodes(); i++) {
> > node = (numa_node_id() + i) % num_possible_nodes()
> >
> > if (!node_isset(nid, sgx_numa_mask))
> > continue;
> >
> > list_for_each_entry(section, &sgx_numa_nodes[nid],
> > section_list) {
> > __sgx_alloc_epc_page_from_section(section)
> > }
> > }
>
> OK, here's an almost completely fleshed-out loop:
>
> page = NULL;
> node = numa_node_id();
> start_node = node;
> while (1) {
> list_for_each_entry(section, &sgx_numa_nodes[nid],
> section_list) {
> page = __sgx_alloc_epc(section);
> if (page)
> break;
> }
> if (page)
> break;
>
> /*
> * EPC allocation failed on 'node'. Fall
> * back with round-robin to other nodes with
> * EPC:
> */
> node = next_node_in(node, sgx_numa_mask);
>
> /* Give up if allocation wraps back to the start: */
> if (node == start_node)
> break;
> }
>
> This will:
> 1. Always start close to the CPU that started the allocation
> 2. Always spread the allocations out among nodes evenly, never
> concentrating allocations on node 0, for instance. (This could also
> be node_random() and get a similar effect, but this probably has
> slightly better default NUMA behavior).
> 3. Efficiently look among all nodes because of 'sgx_numa_mask'
> 4. Have no special case for the first allocation. All allocations will
> be satisfied from this unified loop.
> 5. Compile down to no loop on CONFIG_NUMA=y systems.
> 6. Be guaranteed to make forward progress even if preempted and
> numa_node_id() changes in the loop.
>
> BTW, I think the name of __sgx_alloc_epc_page_from_section() can be
> shortened down. It's passed a section and returns a page, so both of
> those could be removed from the name.
I would start with what I have with minimal changes, and then continue
with a patch that completely wipes the section list.
Then fallback can just take a page from a flat FIFO of EPC pages.
/Jarkko
next prev parent reply other threads:[~2021-02-24 17:31 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-21 2:06 [PATCH] x86/sgx: Add a basic NUMA allocation scheme to sgx_alloc_epc_page() Jarkko Sakkinen
2021-02-22 0:54 ` Dave Hansen
2021-02-23 19:14 ` Dave Hansen
2021-02-24 17:29 ` Jarkko Sakkinen [this message]
2021-02-23 19:17 ` Jarkko Sakkinen
2021-02-23 19:20 ` Dave Hansen
2021-02-23 19:33 ` Jarkko Sakkinen
2021-02-23 21:42 ` Dave Hansen
2021-02-24 17:31 ` Jarkko Sakkinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YDaNDcJvnAen0wZn@kernel.org \
--to=jarkko@kernel.org \
--cc=bp@alien8.de \
--cc=dan.j.williams@intel.com \
--cc=dave.hansen@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=haitao.huang@intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sgx@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox