2.3.x mem balancing
Some of what's been discussed here about NUMA has me concerned. You can't treat a system with NUMA the same as a regular shared memory system. Let me take a moment to describe some of the issues I have w/ NUMA & see if this changes the way you interpret what needs to be done with memory balancing.... I'll let someone else comment on the other issues.
NUMA - Non Uniform Memory Access means what it says - access to memory is not uniform. To the user of a system [not the kernel developer], NUMA works similar to cache memory. If the memory you access is "local" to where the processing is taking place, the access is much faster than if the memory is "far away". The difference in performance can be over 10:1 in terms of latency.
Let's use a specific shared memory vs. NUMA example to illustrate. Many years ago, SGI produced the Challenge product line with a high speed backplane connecting CPU's and shared memory (a traditional shared memory system). More recently, SGI developed "cache coherent NUMA" as part of the Origin 2000 product line. We have been considering the Origin platform and its successors as an upgrade path for existing Challenge XL systems (24 CPU's, 2G shared memory).
To us, the main difference between a Challenge and Origin is that the Origin performance range is much better than on the Challenge. However, access to the memory is equally fast across the entire memory range on the Challenge and "non uniform" [faster & slower] on the Origin. Some reported numbers on the Origin indicate a maximum latency of 200 nsec to 700 nsec with systems with 16 to 32 processors. More processors makes the effect somewhat worse with the "absolute worst case" around 1 microsecond (1000 nsec). To me, these kind of numbers make the cost of a cache miss staggering when compared to the cycle times of new processors.
Our concern with NUMA basically is that the structure of our application must be changed to account for that latency. NUMA works best when you can put the data and the processing in the same area. However, our current implementation for exchanging information between processes is through a large shared memory area. That area will only be "close" to a few processors - the rest will be accessing it remotely. Yes, the connections are very fast, but I worry about the latency [and resulting execution stalls] much more. To us, it means that we must arrange to have the information sent across those fast interfaces before we expect to need it at the destination. Those extra "memory copies" are something we didn't have to worry about before. I see similar problems in the kernel.
In the context of "memory balancing" - all processors and all memory is NOT equal in a NUMA system. To get the best performance from the hardware, you prefer to put "all" of the memory for each process into a single memory unit - then run that process from a processor "near" that memory unit. This seemingly simple principle has a lot of problems behind it. What about...
- shared read only memory (e.g., libraries) [to clone or not?]
- shared read/write memory [how to schedule work to be done when load >> "local
capacity"]
- when memory is low, which pages should I remove?
- when I start a new job, even when there is lots of free memory, where should
I load the job?
These are issues that need to be addressed if you expect to use this high cost hardware effectively. Please don't implement a solution for virtual memory that does not have the ability to scale to solve the problems with NUMA. Thanks.
--Mark H Johnson
<mailto:[email protected]>
|--------+-----------------------> | | Andrea | | | Arcangeli | | | <andrea@suse.| | | de> | | | | | | 04/26/00 | | | 09:19 AM | | | | |--------+----------------------->
Quoted 1 line
----------------------------------------------------------------------------|
| | | To: [email protected] | | cc: Linus Torvalds <[email protected]>, [email protected], | | (bcc: Mark H Johnson/RTS/Raytheon/US) | | Subject: Re: 2.3.x mem balancing | >----------------------------------------------------------------------------|
Quoted 10 lines · Rik van Riel
Quoted 9 lines · Andrea Arcangeli
Quoted 7 lines · Linus Torvalds
Quoted 5 lines · Andrea Arcangeli
The design I'm using is infact that each zone know about each other, each zone have a
free_pagesand aclasszone_free_pages. The additionalclasszone_free_pagesgives us the information about the free pages on the classzone and it's also inclusve of thefree_pagesof all the lower zones.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
AND WHAT ABOUT SETUPS WHERE THERE ISNO INCLUSION?
They're simpler. The classzone for them matches with the zone.
It doesn't. Think NUMA.
NUMA is irrelevant. If there's no inclusion the classzone matches with the zone.
[snip]
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/
Quoted 4 lines · On Wed, 26 Apr 2000 [email protected] wrote:
In the context of "memory balancing" - all processors and all memory is NOT equal in a NUMA system. To get the best performance from the hardware, you prefer to put "all" of the memory for each process into a single memory unit - then run that process from a processor "near" that memory unit. This seemingly
The classzone approch (aka overlapped zones approch) is irrelevant with NUMA problematics as far I can tell.
NUMA is a problematic that belongs outside the pg_data_t. It doesn't matter how we restructure the internal of the zone_t.
I only changed the internal structure of one node. Not at all how to policy the allocations and the balance between different nodes (that decisions have to live in the linux/arch/ tree and not in __alloc_pages).
On NUMA hardware you have only one zone per node since nobody uses ISA-DMA on such machines and you have PCI64 or you can use the PCI-DMA sg for PCI32. So on NUMA hardware you are going to have only one zone per node (at least this was the setup of the NUMA machine I was playing with). So you don't mind at all about classzone/zone. Classzone and zone are the same thing in such a setup, they both are the plain ZONE_DMA zone_t. Finished. Said that you don't care anymore about the changes of how the overlapped zones are handled since you don't have overlapped zones in first place.
Now on NUMA when you want to allocate memory you have to use alloc_pages_node so that you can tell also which node allocate from.
Here Linus was proposing of making alloc_pages_node this way:
alloc_pages_node(nid, gfpmask, order)
{
zonelist_t ** zonelist = nid2zonelist(nid, gfpmask);
__alloc_pages(zonelist, order);
}and then having the automatic falling back between nodes and numa memory balancing handled by __alloc_pages and by the current 2.3.99-pre6-5 zonelist falling back trick.
I care to explain why I think that's not the right approch for handling NUMA allocations and balancing decisions.
As first it's clear that the above described NUMA approch is abusing zonelist_t by looking the size of the zonelist_t structure:
typedef struct zonelist_struct {
zone_t * zones [MAX_NR_ZONES+1]; // NULL delimited
int gfp_mask;
} zonelist_t;If zonelist was designed for NUMA it should be something like:
typedef struct zonelist_struct {
zone_t * zones [max(MAX_NR_ZONES*MAX_NR_NODES)+1]; // NULL delimited
int gfp_mask;
} zonelist_t;however we can fix that easily by enlarging the zones array in the zonelist.
and as second the zonelist-NUMA solution isn't enough flexible since if there's lots of cache allocate in one node we may prefer to move or shrink the cache than to allocate mapped areas of the same task in different nodes (as the __alloc_pages would do).
With the zonelist_t abused to do NUMA we _don't_ have flexibility.
If you move the NUMA balancing and node selection into the higher layer as I was proposing, instead you can do clever things.
And as soon as you move the decisions at the higher layer you don't mind anymore about the node internals. Or better you only care to be able to find the current life-state of a node and you of course can do that. Then once you know the state of the interesting node you can do the decision of what to do _still_ at the highlever layer.
At the highlevel layer you can see that the node is filled with 90% of cache, and then you can say: ok allocate from this node anyway and let it to shrink some cache if necessary.
Then the lower layer (__alloc_pages) will do automatically the balancing and it will try to allocate memory from such node. You can also grab the per-node spinlock in the highlever layer before checking the state of the node so that you'll know the state of the node won't change from under you while doing the allocation.
Quoted 1 line
These are issues that need to be addressed if you expect to use this
I always tried to keep these issues in mind (also before writing the classzone approch).
Andrea
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/
Quoted 10 lines
On NUMA hardware you have only one zone per node since nobody uses ISA-DMA on such machines and you have PCI64 or you can use the PCI-DMA sg for PCI32. So on NUMA hardware you are going to have only one zone per node (at least this was the setup of the NUMA machine I was playing with). So you don't mind at all about classzone/zone. Classzone and zone are the same thing in such a setup, they both are the plain
ZONE_DMAzone_t. Finished. Said that you don't care anymore about the changes of how the overlapped zones are handled since you don't have overlapped zones in first place.
Andrea, are you talking about the SGI Origin platform, or are you using some other NUMA platform? In any case, the SGI platform in fact does not support ISA-DMA, but unfortunately, I don't think just because it has PCI mapping registers, you can assume that all memory is DMAable. For us to be able to consider all memory as dmaable, before each dma operation starts, we need to have a pci-dma type hook to program the mapping registers. As far as I know, such a hook is not used on all drivers (in 2.4 timeframe), so very unfortunately, I think we need to keep the option open about each node having more than just ZONE_DMA. Finally, I am not sure how things will work, we are still busy trying to get the Origin/Linux port going.
FWIW, I think the IBM/Sequent NUMA machines in fact have nodes that have only nondmaable memory.
Quoted 4 lines
If you move the NUMA balancing and node selection into the higher layer as I was proposing, instead you can do clever things.
For an example and a (old) patch for this, look at
http://oss.sgi.com/projects/numa/download/numa.gen.42b
http://oss.sgi.com/projects/numa/download/numa.plat.42b
Kanoj
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/
Quoted 2 lines · Kanoj Sarcar
[..] As far as I know, such a hook is not used on all drivers (in 2.4 timeframe), [..]
That's also why I still have the alpha HIGHMEM support in my TODO list so we can ship a binary only kernel that doesn't risk to break with >2g RAM.
Andrea
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/
Quoted 11 lines
In the context of "memory balancing" - all processors and all memory is NOT equal in a NUMA system. To get the best performance from the hardware, you prefer to put "all" of the memory for each process into a single memory unit - then run that process from a processor "near" that memory unit. This seemingly simple principle has a lot of problems behind it. What about...
- shared read only memory (e.g., libraries) [to clone or not?]
- shared read/write memory [how to schedule work to be done when load >> "local
capacity"]
- when memory is low, which pages should I remove?
- when I start a new job, even when there is lots of free memory, where should
I load the job?
The problem is, every app has different requirements, and performs best under different resource (cpu/memory) scheduling policies. IRIX provides a tool called "dplace", that will allow performance experts specify which threads of a program should be run on cpus on which node, and how different sections of the address space should have their pages allocated (that is, on which nodes; possible policies: firsttouch, ie, allocate the page on the node which has the processor that first accesses that page, roundrobin, ie, round robin the allocations across all nodes, etc etc).
Linux is a little away from providing such flexible options, specially since it is not even possible to pin a process to a cpu or node yet. The page allocation strategies are of course much more work to implement.
For global issues like "when memory is low, which pages should I remove" the problem is a little more complex. Having a kswapd per node is an option, although I think it is too early to decide that. I am hoping we can get a multinode system up soon, and investigate these issues.
Kanoj
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/