Memory policy question for NUMA arch....
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hello,
PS - Please 'CC' me on the emails.I have not subscribed to the list.
Quoted 14 lines
Hi Andy,
--- On Wed, 4/7/10, Andi Kleen <[email protected]>
Quoted 1 line · wrote:
On Tue, Apr 06, 2010 at 01:46:44PM -0700, Rick Sherm
Quoted 1 line · wrote:
Quoted 1 line
On a NUMA host, if a driver calls
__get_free_pages()Quoted 6 lines
then
Quoted 1 line
it will eventually invoke
->alloc_pages_current(..). The comment
Quoted 1 line
above/within
alloc_pages_current()says'
current->mempolicy' will beQuoted 1 line
used.So what memory policy will kick-in if the
Quoted 11 lines
driver
Quoted 6 lines
is trying to
Quoted 1 line
allocate some memory blocks during driver load
time(say from probe_one)? System-wide default
policy,correct?Actually the policy of the modprobe or the kernel boot
up
Quoted 3 lines
if built in
(which is interleaving)
I may be wrong but I think there's a difference. system-wide run-time default policy is M_PREFERRED | M_LOCAL and not Interleaving.
So, if current->mempolicy is set then default_policy will not be used. And now if you don't want the default_policy mode then what?
I'm stuck in this confused state too. So we have two cases to take care off -
Case1) current->mempolicy is initialized and so we can just set it to whatever we like and then reset it once we are done with __get_free_pages(..) etc.
Case2) current->mempolicy is not initialized. Then default_policy is used. Now if we have to muck with the default_policy then we will need to lock it down. Otherwise some other consumer will get affected by it.
But both the above solutions are twisted.Why not just create a different wrapper? This way we can leave both current & default_policy alone.
#ifdef CONFIG_NUMA__get_free_policy_pages(policy,mask,order)??
endif
For now I may end up hacking my kernel and implementing the above mentioned quick and dirty solution. But if there's a cleaner approach then please let me know.
PS - We should create some wrapper's that will automatically figure out the MSIX-affinity(if present/set) and then default the allocation to that node? Also, is there a way to configure irqbalance and ask it to leave these guys alone? Like a config file that says - leave these irqs/pci-devices alone.For now I've shut down irqbalance.
Quoted 7 lines
Quoted 3 lines
-Andi
Thanks
Rick
thanks
Chetan Loke
Quoted 1 line
I may be wrong but I think there's a difference. system-wide run-time default policy is
M_PREFERRED|M_LOCALand not Interleaving.
The policy at early kernel boot time (before mounting root) is interleaving.
-Andi
Andi,
Quoted 5 lines · Andi Kleen
From: Andi Kleen <[email protected]>
Subject: Re: Memory policy question for NUMA arch....
To: "Chetan Loke" <[email protected]>
Cc: [email protected], [email protected], [email protected], [email protected]
Date: Saturday, April 17, 2010, 6:35 AM
Quoted 7 lines
Quoted 1 line
I may be wrong but I think
there's a difference. system-wide run-time default policy is
M_PREFERRED|M_LOCALand not Interleaving.The policy at early kernel boot time (before mounting root) is interleaving.
Yup.
PS - What do you think about __get_free_policy_pages(..)? Good/bad idea?
Quoted 2 lines
-Andi
thanks
Chetan Loke
Quoted 1 line
PS - What do you think about
__get_free_policy_pages(..)? Good/bad idea?
You can do it today by temporarily replacing the policy in current. It's somewhat ugly. Interrupts don't use the policy, so it's not racy.
But yes if it's common it would seem reasonable to have a cleaner function for it, if you have a clear use case and you can do it without impacting the page allocator fast path.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Quoted 32 lines · Chetan Loke
Hello,
PS - Please 'CC' me on the emails.I have not subscribed to the list.
Quoted 14 lines
Hi Andy,
--- On Wed, 4/7/10, Andi Kleen <[email protected]>
Quoted 1 line · wrote:
On Tue, Apr 06, 2010 at 01:46:44PM -0700, Rick Sherm
Quoted 1 line · wrote:
Quoted 1 line
On a NUMA host, if a driver calls
__get_free_pages()Quoted 6 lines
then
Quoted 1 line
it will eventually invoke
->alloc_pages_current(..). The comment
Quoted 1 line
above/within
alloc_pages_current()says'
current->mempolicy' will beQuoted 1 line
used.So what memory policy will kick-in if the
Quoted 11 lines
driver
Quoted 6 lines
is trying to
Quoted 1 line
allocate some memory blocks during driver load
time(say from probe_one)? System-wide default
policy,correct?Actually the policy of the modprobe or the kernel boot
up
Quoted 3 lines
if built in
(which is interleaving)I may be wrong but I think there's a difference. system-wide run-time default policy is
M_PREFERRED|M_LOCALand not Interleaving.
Quoted 7 lines
So, if
current->mempolicyis set thendefault_policywill not be used. And now if you don't want thedefault_policymode then what?
I'm stuck in this confused state too. So we have two cases to take care off -Case1)
current->mempolicyis initialized and so we can just set it to whatever we like and then reset it once we are done with__get_free_pages(..)etc.
Yes, as Andi mentioned. Also, see my response to Rick at:
http://marc.info/?l=linux-kernel&m=127066130315241&w=4
Quoted 5 lines
Case2)
current->mempolicyis not initialized. Thendefault_policyis used. Now if we have to muck with thedefault_policythen we will need to lock it down. Otherwise some other consumer will get affected by it.
If current->mempolicy is not initialized, you can create a new one and set it temporarily. You could probably call do_set_mempolicy() directly the way numa_policy_init() does and then call numa_default_policy() to restore it to default.
You should never change the system default once the system is up and running.
Quoted 8 lines
But both the above solutions are twisted.Why not just create a different wrapper? This way we can leave both current &
default_policyalone.#ifdef
CONFIG_NUMA__get_free_policy_pages(policy,mask,order)??
endif
As Andi mentioned in his response, you could certainly do this as long as it doesn't impact the normal allocation path.
Quoted 8 lines
For now I may end up hacking my kernel and implementing the above mentioned quick and dirty solution. But if there's a cleaner approach then please let me know.
PS - We should create some wrapper's that will automatically figure out the MSIX-affinity(if present/set) and then default the allocation to that node?
Still not clear on what your requirements are but, if existing interfaces don't suffice, such a wrapper might make sense. __get_free_pages() is simply a wrapper around alloc_pages() that then returns page_address() of the resulting page. So, something like 'get_free_pages_node()'--which should probably live in mm/page_alloc.c--would just be a wrapper around alloc_pages_node() that then returns the page_address() of the page.
A device-centric interface--e.g., 'get_free_pages_dev()'--could get the device/bus node affinity via dev_to_node() and then do the
allocation/conversion. I think this is close to what you're suggesting
above. See dma_generic_alloc_coherent() [in arch/x86/kernel/pci-dma.c] for an example of a wrapper that does the device affinity lookup and allocation in one function.
Of course, you could just do this in your driver, as well.
Quoted 3 lines
Also, is there a way to configure irqbalance and ask it to leave these guys alone? Like a config file that says - leave these irqs/pci-devices alone.For now I've shut down irqbalance.
You can set the environment variable IRQBALANCE_BANNED_INTERRUPTS--when starting irqbalance--to list of interrupts that irqbalance should ignore if you're using a version that supports that. Check the init script that starts irqbalance on your distro of choice.
Regards,
Lee