wmark based pro-active compaction
Subsystems (4)
Hi,
I didn't originally want to send this proposal because Vlastimil is planning to do some work in this area so I've expected him to send something similar. But the recent discussion about the THP defrag options pushed me to send out my thoughts.
So what is the problem? The demand for high order pages is growing and that seems to be the general trend. The problem is that while they can bring performance benefit they can get be really expensive to allocate especially when we enter the direct compaction. So we really want to prevent from expensive path and defer as much as possible to the background. A huge step forward was kcompactd introduced by Vlastimil. We are still not there yet though, because it might be already quite late when we wakeup_kcompactd(). The memory might be already fragmented when we hit there. Moreover we do not have any way to actually tell which orders we do care about.
Therefore I believe we need a watermark based pro-active compaction which would keep the background compaction busy as long as we have less pages of the configured order. kcompactd should wake up periodically, I think, and check for the status so that we can catch the fragmentation before we get low on memory.
The interface could look something like:/proc/sys/vm/compact_wmarktime_period order count
There are many details that would have to be solved of course - e.g. do not burn cycles pointlessly when we know that no further progress can be made etc... but in principle the idea show work.
Signature · 8 lines
Michal Hocko SUSE Labs -- 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-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 26 lines · Michal Hocko
Hi,
I didn't originally want to send this proposal because Vlastimil is planning to do some work in this area so I've expected him to send something similar. But the recent discussion about the THP defrag options pushed me to send out my thoughts.So what is the problem? The demand for high order pages is growing and that seems to be the general trend. The problem is that while they can bring performance benefit they can get be really expensive to allocate especially when we enter the direct compaction. So we really want to prevent from expensive path and defer as much as possible to the background. A huge step forward was kcompactd introduced by Vlastimil. We are still not there yet though, because it might be already quite late when we
wakeup_kcompactd(). The memory might be already fragmented when we hit there. Moreover we do not have any way to actually tell which orders we do care about.Therefore I believe we need a watermark based pro-active compaction which would keep the background compaction busy as long as we have less pages of the configured order. kcompactd should wake up periodically, I think, and check for the status so that we can catch the fragmentation before we get low on memory.
The interface could look something like:/proc/sys/vm/compact_wmarktime_periodorder count
Quoted 3 lines
There are many details that would have to be solved of course - e.g. do not burn cycles pointlessly when we know that no further progress can be made etc... but in principle the idea show work.
I'd be very interested in this. I'd also like to add to the list to revisit the concept of pre-emptively moving movable pages from pageblocks stolen for unmovable pages to reduce future events that degrade fragmentation. Before the Christmas I was mulling over whether it would be appropriate to have a workqueue of pageblocks that need "cleaning". This could be either instead of or in conjunction with wmark-based compaction.
Signature · 8 lines
Mel Gorman SUSE Labs -- 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-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
[CC Joonsoo and Johannes]
Quoted 6 lines · Mel Gorman
Quoted 5 lines · Michal Hocko
Hi,
I didn't originally want to send this proposal because Vlastimil is planning to do some work in this area so I've expected him to send something similar. But the recent discussion about the THP defrag options pushed me to send out my thoughts.
No problem.
Quoted 9 lines
Quoted 9 lines
So what is the problem? The demand for high order pages is growing and that seems to be the general trend. The problem is that while they can bring performance benefit they can get be really expensive to allocate especially when we enter the direct compaction. So we really want to prevent from expensive path and defer as much as possible to the background. A huge step forward was kcompactd introduced by Vlastimil. We are still not there yet though, because it might be already quite late when we
wakeup_kcompactd(). The memory might be already fragmented when we hit there.
Right.
Quoted 2 lines
Quoted 2 lines
Moreover we do not have any way to actually tell
which orders we do care about.
Who is "we" here? The system admin?
Quoted 3 lines
Quoted 3 lines
Therefore I believe we need a watermark based pro-active compaction which would keep the background compaction busy as long as we have less pages of the configured order.
Again, configured by what, admin? I would rather try to avoid tunables here, if possible. While THP is quite well known example with stable order, the pressure for other orders is rather implementation specific (drivers, SLAB/SLUB) and may change with kernel versions (e.g. virtually mapped stacks, although that example is about non-costly order). Would the admin be expected to study the implementation to know which orders are needed, or react to page allocation failure reports? Neither sounds nice.
Quoted 6 lines
Quoted 6 lines
kcompactd should wake up
periodically, I think, and check for the status so that we can catch the fragmentation before we get low on memory.
The interface could look something like:/proc/sys/vm/compact_wmarktime_periodorder count
IMHO it would be better if the system could auto-tune this, e.g. by counting high-order alloc failures/needs for direct compaction per order between wakeups, and trying to bring them to zero.
Quoted 3 lines
Quoted 3 lines
There are many details that would have to be solved of course - e.g. do not burn cycles pointlessly when we know that no further progress can be made etc... but in principle the idea show work.
Yeah with auto-tuning there's even more inputs to consider and parameters that would be auto-adjusted based on them. Right now I can think of:
Inputs
- the per-order "pressure" (e.g. the failures/direct compactions above)
- ideally somehow including the "importance". That might be the
trickiest part when wanting to avoid tunables. THP failures might be least important, allocations with expensive or no fallback most important. Probably not just simple relation between order. Hopefully gfp flags such as __GFP_NORETRY and __GFP_REPEAT can help here? Without such metric, everything will easily be dominated by THP pressure.
- recent compaction efficiency (as you mentioned above)
Parameters
- wake up period for kcompactd
- target per-order goals for kcompactd
- lowest efficiency where it's still considered worth to compact?
An important question: how to evaluate this? Metrics should be feasible (improved success rate, % of compaction that was handled by kcompactd and not direct compaction...), but what are the good testcases?
Quoted 6 lines
I'd be very interested in this. I'd also like to add to the list to revisit the concept of pre-emptively moving movable pages from pageblocks stolen for unmovable pages to reduce future events that degrade fragmentation. Before the Christmas I was mulling over whether it would be appropriate to have a workqueue of pageblocks that need "cleaning". This could be either instead of or in conjunction with wmark-based compaction.
Yes, that could be useful as well.
Ideally I would also revisit the topic of compaction mechanism (migrate and free scanners) itself. It's been shown that they usually meet in the 1/3 or 1/2 of zone, which means the rest of the zone is only defragmented by "plugging free holes" by migrated pages, although it might actually contain pageblocks more suitable for migrating from, than the first part of the zone. It's also expensive for the free scanner to actually find free pages, according to the stats.
Some approaches were proposed in recent years, but never got far as it's always some kind of a trade-off (this partially goes back to the problem of evaluation, often limited to stress-highalloc from mmtests):
- "pivot" based approach where scanners' starting point changes and isn't always zone boundaries [1]
- both scanners scan whole zone moving in the same direction, just making sure they don't operate on the same pageblock at the same time [2]
- replacing free scanner by directly taking free pages from freelist
However, the problem with this subtopic is that it might be too much specialized for the full MM room.
[1] https://lkml.org/lkml/2015/1/19/158
[2] https://lkml.org/lkml/2015/6/24/706
[3] https://lkml.org/lkml/2015/12/3/63
--
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-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Michal Hocko
reviewerQuoted 22 lines · Vlastimil Babka
[CC Joonsoo and Johannes]
Quoted 6 lines · Mel Gorman
Quoted 5 lines · Michal Hocko
Hi,
I didn't originally want to send this proposal because Vlastimil is planning to do some work in this area so I've expected him to send something similar. But the recent discussion about the THP defrag options pushed me to send out my thoughts.No problem.
Quoted 9 lines
Quoted 9 lines
So what is the problem? The demand for high order pages is growing and that seems to be the general trend. The problem is that while they can bring performance benefit they can get be really expensive to allocate especially when we enter the direct compaction. So we really want to prevent from expensive path and defer as much as possible to the background. A huge step forward was kcompactd introduced by Vlastimil. We are still not there yet though, because it might be already quite late when we
wakeup_kcompactd(). The memory might be already fragmented when we hit there.
Quoted 6 lines
Right.
Quoted 2 lines
Quoted 2 lines
Moreover we do not have any way to actually tell
which orders we do care about.Who is "we" here? The system admin?
yes
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Therefore I believe we need a watermark based pro-active compaction which would keep the background compaction busy as long as we have less pages of the configured order.
Quoted 8 lines
Again, configured by what, admin? I would rather try to avoid tunables here, if possible. While THP is quite well known example with stable order, the pressure for other orders is rather implementation specific (drivers, SLAB/SLUB) and may change with kernel versions (e.g. virtually mapped stacks, although that example is about non-costly order). Would the admin be expected to study the implementation to know which orders are needed, or react to page allocation failure reports? Neither sounds nice.
That is a good question but I expect that there are more users than THP which use stable orders. E.g. networking stack tends to depend on the packet size. A tracepoint with some histogram output would tell us what is the requested orders distribution.
Quoted 10 lines
Quoted 6 lines
Quoted 6 lines
kcompactd should wake up
periodically, I think, and check for the status so that we can catch the fragmentation before we get low on memory.
The interface could look something like:/proc/sys/vm/compact_wmarktime_periodorder countIMHO it would be better if the system could auto-tune this, e.g. by counting high-order alloc failures/needs for direct compaction per order between wakeups, and trying to bring them to zero.
auto-tunning is usually preferable I am just wondering how the admin can tell what is still the system load price he is willing to pay. I suspect we will see growing number of opportunistic high order requests over time and auto tunning shouldn't try to accomodate with it without any bounds. There is still some cost/benefit to be evaluated from the system level point of view which I am afraid is hard to achive from the kcompactd POV.
Signature · 8 lines
Michal Hocko SUSE Labs -- 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-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 14 lines · Michal Hocko
Quoted 4 lines · Vlastimil Babka
Quoted 3 lines
Quoted 3 lines
Therefore I believe we need a watermark based pro-active compaction which would keep the background compaction busy as long as we have less pages of the configured order.
Quoted 8 lines
Again, configured by what, admin? I would rather try to avoid tunables here, if possible. While THP is quite well known example with stable order, the pressure for other orders is rather implementation specific (drivers, SLAB/SLUB) and may change with kernel versions (e.g. virtually mapped stacks, although that example is about non-costly order). Would the admin be expected to study the implementation to know which orders are needed, or react to page allocation failure reports? Neither sounds nice.
Quoted 4 lines
That is a good question but I expect that there are more users than THP which use stable orders. E.g. networking stack tends to depend on the packet size. A tracepoint with some histogram output would tell us what is the requested orders distribution.
Maybe, but there might be also multiple users of the same order but different "importance"...
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
Quoted 6 lines
kcompactd should wake up
periodically, I think, and check for the status so that we can catch the fragmentation before we get low on memory.
The interface could look something like:/proc/sys/vm/compact_wmarktime_periodorder countIMHO it would be better if the system could auto-tune this, e.g. by counting high-order alloc failures/needs for direct compaction per order between wakeups, and trying to bring them to zero.
Quoted 7 lines
auto-tunning is usually preferable I am just wondering how the admin can tell what is still the system load price he is willing to pay. I suspect we will see growing number of opportunistic high order requests over time and auto tunning shouldn't try to accomodate with it without any bounds.There is still some cost/benefit to be evaluated from the system level point of view which I am afraid is hard to achive from the kcompactd POV.
That's why I mentioned that importance should be judged somehow. Opportunistic requests should be recognizable by their gfp flags, so hopefully there's a way. I wouldn't mind some general tunable(s) to express how much effort to give to "important" allocations and opportunistic ones, but rather not in such implementation-detail form as "time_period order count".
--
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-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hello,
I'm also interested in this topic.
lkml.kernel.org/r/[email protected]
Quoted 22 lines · Vlastimil Babka
[CC Joonsoo and Johannes]
Quoted 6 lines · Mel Gorman
Quoted 5 lines · Michal Hocko
Hi,
I didn't originally want to send this proposal because Vlastimil is planning to do some work in this area so I've expected him to send something similar. But the recent discussion about the THP defrag options pushed me to send out my thoughts.No problem.
Quoted 9 lines
Quoted 9 lines
So what is the problem? The demand for high order pages is growing and that seems to be the general trend. The problem is that while they can bring performance benefit they can get be really expensive to allocate especially when we enter the direct compaction. So we really want to prevent from expensive path and defer as much as possible to the background. A huge step forward was kcompactd introduced by Vlastimil. We are still not there yet though, because it might be already quite late when we
wakeup_kcompactd(). The memory might be already fragmented when we hit there.
Quoted 1 line
Right.
Before we talk about pro-active compaction, I'd like to know the usecase that really needs pro-active compaction. For THP, IMHO, it's better not to do pro-active compaction, because high-order page made by pro-active compaction could be broken before it is used. And, THP page can be setup lately by THP daemon. Benefit of pro-active compaction would not compensate overhead of it in this case. I guess that almost cases that have a fallback would hit this category.
For the order lower than costly order, system would have such a freepage usually. So, my question is pro-active compaction is really needed even if it's cost is really high? Reason I ask this question is that I tested some patches to do pro-active compaction and found that cost looks too much high. I heard that someone want this feature but I'm not sure they will use it with this high cost. Anyway, I will post some patches for pro-active compaction, soon.
Quoted 10 lines
Quoted 3 lines
Quoted 3 lines
Moreover we do not have any way to actually tell
which orders we do care about.Who is "we" here? The system admin?
Quoted 3 lines
Quoted 3 lines
Therefore I believe we need a watermark based pro-active compaction which would keep the background compaction busy as long as we have less pages of the configured order.
Quoted 8 lines
Again, configured by what, admin? I would rather try to avoid tunables here, if possible. While THP is quite well known example with stable order, the pressure for other orders is rather implementation specific (drivers, SLAB/SLUB) and may change with kernel versions (e.g. virtually mapped stacks, although that example is about non-costly order). Would the admin be expected to study the implementation to know which orders are needed, or react to page allocation failure reports? Neither sounds nice.
It would be really good if we can auto tune this. My patches mentioned above just use tunables that you don't like. :)
Quoted 29 lines
Quoted 6 lines
Quoted 6 lines
kcompactd should wake up
periodically, I think, and check for the status so that we can catch the fragmentation before we get low on memory.
The interface could look something like:/proc/sys/vm/compact_wmarktime_periodorder countIMHO it would be better if the system could auto-tune this, e.g. by counting high-order alloc failures/needs for direct compaction per order between wakeups, and trying to bring them to zero.
Quoted 3 lines
Quoted 3 lines
There are many details that would have to be solved of course - e.g. do not burn cycles pointlessly when we know that no further progress can be made etc... but in principle the idea show work.
Yeah with auto-tuning there's even more inputs to consider and parameters that would be auto-adjusted based on them. Right now I can think of:
Inputs
- the per-order "pressure" (e.g. the failures/direct compactions above)
- ideally somehow including the "importance". That might be the
trickiest part when wanting to avoid tunables. THP failures might be least important, allocations with expensive or no fallback most important. Probably not just simple relation between order. Hopefully gfp flags such as__GFP_NORETRYand__GFP_REPEATcan help here? Without such metric, everything will easily be dominated by THP pressure.
- recent compaction efficiency (as you mentioned above)
Quoted 8 lines
Parameters
- wake up period for kcompactd
- target per-order goals for kcompactd
- lowest efficiency where it's still considered worth to compact?An important question: how to evaluate this? Metrics should be feasible (improved success rate, % of compaction that was handled by kcompactd and not direct compaction...), but what are the good testcases?
Usecase should be defined first? Anyway, I hope that new testcase would be finished in short time. stress-highalloc test takes too much time to test various ideas.
Quoted 8 lines
Quoted 6 lines
I'd be very interested in this. I'd also like to add to the list to revisit the concept of pre-emptively moving movable pages from pageblocks stolen for unmovable pages to reduce future events that degrade fragmentation. Before the Christmas I was mulling over whether it would be appropriate to have a workqueue of pageblocks that need "cleaning". This could be either instead of or in conjunction with wmark-based compaction.
Yes, that could be useful as well.
I tried this one, too. :)
lkml.kernel.org/r/[email protected]
My approach is to maintain dedicated thread and it migrates all movable pages in the pageblock stolen for unmovable allocation to prevent the future event that unmovable allocation happens in another movable pageblock. This patches help to prevent it but not perfectly since it sometimes cannot catch-up allocation speed. With pro-active compaction, we may prevent it, too.
Quoted 3 lines
Ideally I would also revisit the topic of compaction mechanism (migrate and free scanners) itself. It's been shown that they usually meet in the
+1
Quoted 5 lines
1/3 or 1/2 of zone, which means the rest of the zone is only defragmented by "plugging free holes" by migrated pages, although it might actually contain pageblocks more suitable for migrating from, than the first part of the zone. It's also expensive for the free scanner to actually find free pages, according to the stats.
Scalable approach would be [3] since it finds freepage by O(1) unlike others that are O(N).
Quoted 5 lines
Some approaches were proposed in recent years, but never got far as it's always some kind of a trade-off (this partially goes back to the problem of evaluation, often limited to stress-highalloc from mmtests):
Quoted 8 lines
- "pivot" based approach where scanners' starting point changes and isn't always zone boundaries [1]
- both scanners scan whole zone moving in the same direction, just making sure they don't operate on the same pageblock at the same time [2]
- replacing free scanner by directly taking free pages from freelistHowever, the problem with this subtopic is that it might be too much specialized for the full MM room.
Right. :)
Thanks.
Quoted 4 lines
[1] https://lkml.org/lkml/2015/1/19/158
[2] https://lkml.org/lkml/2015/6/24/706
[3] https://lkml.org/lkml/2015/12/3/63
--
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-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 10 lines · Joonsoo Kim
Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
So what is the problem? The demand for high order pages is growing and that seems to be the general trend. The problem is that while they can bring performance benefit they can get be really expensive to allocate especially when we enter the direct compaction. So we really want to prevent from expensive path and defer as much as possible to the background. A huge step forward was kcompactd introduced by Vlastimil. We are still not there yet though, because it might be already quite late when we
wakeup_kcompactd(). The memory might be already fragmented when we hit there.
Quoted 6 lines
Quoted 1 line
Right.
Before we talk about pro-active compaction, I'd like to know the usecase that really needs pro-active compaction. For THP, IMHO, it's better not to do pro-active compaction, because high-order page made by pro-active compaction could be broken before it is used. And,
I agree that THP should be given lower priority, but wouldn't rule it out completely.
Quoted 2 lines
THP page can be setup lately by THP daemon. Benefit of pro-active compaction would not compensate overhead of it in this case.
khugepaged can only help in the longer term, but we can still help shorter-lived processes
Quoted 2 lines
I guess
that almost cases that have a fallback would hit this category.
Yes, ideally we can derive this info from the GFP flags and prioritize accordingly.
Quoted 7 lines
For the order lower than costly order, system would have such a freepage usually. So, my question is pro-active compaction is really needed even if it's cost is really high? Reason I ask this question is that I tested some patches to do pro-active compaction and found that cost looks too much high. I heard that someone want this feature but I'm not sure they will use it with this high cost. Anyway, I will post some patches for pro-active compaction, soon.
David Rientjes mentioned their workloads benefit from background compaction in the discussion about THP's "defrag" setting.
[...]
Quoted 5 lines
Quoted 5 lines
Parameters
- wake up period for kcompactd
- target per-order goals for kcompactd
- lowest efficiency where it's still considered worth to compact?
Quoted 7 lines
Quoted 3 lines
An important question: how to evaluate this? Metrics should be feasible (improved success rate, % of compaction that was handled by kcompactd and not direct compaction...), but what are the good testcases?
Usecase should be defined first? Anyway, I hope that new testcase would be finished in short time. stress-highalloc test takes too much time to test various ideas.
Yeah, that too. But mainly it's too artificial.
Quoted 6 lines
Quoted 3 lines
Ideally I would also revisit the topic of compaction mechanism (migrate and free scanners) itself. It's been shown that they usually meet in the
+1
Quoted 8 lines
Quoted 5 lines
1/3 or 1/2 of zone, which means the rest of the zone is only defragmented by "plugging free holes" by migrated pages, although it might actually contain pageblocks more suitable for migrating from, than the first part of the zone. It's also expensive for the free scanner to actually find free pages, according to the stats.
Scalable approach would be [3] since it finds freepage by O(1) unlike others that are O(N).
There's however the issue that we need to skip (or potentially isolate on a private list) freepages that lie in the area we are migrating from, which is potentially O(N) where N is NR_FREE. This gets worse with multiple compactors so we might have to e.g. reuse the pageblock skip bits to indicate to others to go away, and rely on too_many_isolated() or something similar to limit the number of concurrent compactors.
Quoted 23 lines
Quoted 5 lines
Some approaches were proposed in recent years, but never got far as it's always some kind of a trade-off (this partially goes back to the problem of evaluation, often limited to stress-highalloc from mmtests):
Quoted 8 lines
- "pivot" based approach where scanners' starting point changes and isn't always zone boundaries [1]
- both scanners scan whole zone moving in the same direction, just making sure they don't operate on the same pageblock at the same time [2]
- replacing free scanner by directly taking free pages from freelistHowever, the problem with this subtopic is that it might be too much specialized for the full MM room.
Right. :)
Thanks.
Quoted 4 lines
[1] https://lkml.org/lkml/2015/1/19/158
[2] https://lkml.org/lkml/2015/6/24/706
[3] https://lkml.org/lkml/2015/12/3/63
Quoted 6 lines
--
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-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
--
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-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 26 lines · Michal Hocko
Hi,
I didn't originally want to send this proposal because Vlastimil is planning to do some work in this area so I've expected him to send something similar. But the recent discussion about the THP defrag options pushed me to send out my thoughts.So what is the problem? The demand for high order pages is growing and that seems to be the general trend. The problem is that while they can bring performance benefit they can get be really expensive to allocate especially when we enter the direct compaction. So we really want to prevent from expensive path and defer as much as possible to the background. A huge step forward was kcompactd introduced by Vlastimil. We are still not there yet though, because it might be already quite late when we
wakeup_kcompactd(). The memory might be already fragmented when we hit there. Moreover we do not have any way to actually tell which orders we do care about.Therefore I believe we need a watermark based pro-active compaction which would keep the background compaction busy as long as we have less pages of the configured order. kcompactd should wake up periodically, I think, and check for the status so that we can catch the fragmentation before we get low on memory.
The interface could look something like:/proc/sys/vm/compact_wmarktime_periodorder count
Quoted 3 lines
There are many details that would have to be solved of course - e.g. do not burn cycles pointlessly when we know that no further progress can be made etc... but in principle the idea show work.
OK, LSF/MM is near, so I'll post my approach up for discussion. It's very RFC state, I've worked at it last year and now I just rebased it to 4.11-rc1 and updated some comments. Maybe I'll manage to do some tests before LSF/MM, but no guarantees. Comments welcome.
----8<----
From: Vlastimil Babka <[email protected]>
Subject: [RFC] mm: make kcompactd more proactive
Kcompactd activity is currently tied to kswapd - it is woken up when kswapd goes to sleep, and compacts to make a single high-order page available, of order that was used to wake up kswapd. This leaves the rest of free pages fragmented and results in direct compaction when the demand for fresh high-order pages is higher than a single page per kswapd cycle.
Another extreme would be to let kcompactd compact whole zone the same way as manual compaction from /proc interface. This would be wasteful if the resulting high-order pages would be split down to base pages for allocations.
This patch aims to adjust the kcompactd effort through observed demand for high-order pages. This is done by hooking into alloc_pages_slowpath() and counting (per each order > 0) allocation attempts that would pass the order-0 watermarks, but don't have the high-order page available. This demand is (currently) recorded per node and then redistributed per zones in each node according to their relative sizes.
Kcompactd then uses a different termination criteria than direct compaction. It checks whether for each order, the recorded number of attempted allocations would fit within the free pages of that order of with possible splitting of higher orders, assuming there would be no allocations of other orders. This should make kcompactd effort reflect the high-order demand.
In the worst case, the demand is so high that kcompactd will in fact compact the whole zone and would have to be run with higher frequency than kswapd to make a larger difference. That possibility can be explored later.
--- include/linux/compaction.h | 6 ++ include/linux/mmzone.h | 2 + mm/compaction.c | 165 ++++++++++++++++++++++++++++++++++++++++++++- mm/page_alloc.c | 12 ++++ 4 files changed, 182 insertions(+), 3 deletions(-)
include/linux/compaction.h +6 -0
@@ -176,6 +176,8 @@ bool compaction_zonelist_suitable(struct alloc_context *ac, int order,extern int kcompactd_run (int nid);extern void kcompactd_stop (int nid);extern void wakeup_kcompactd (pg_data_t *pgdat,int order,int classzone_idx); +extern void kcompactd_inc_free_target (gfp_t gfp_mask,unsigned int order, +int alloc_flags,struct alloc_context *ac);#else static inline void reset_isolation_suitable (pg_data_t *pgdat)
@@ -224,6 +226,10 @@ static inline void wakeup_kcompactd(pg_data_t *pgdat, int order, int classzone_i { } +static inline void kcompactd_inc_free_target (gfp_t gfp_mask,unsigned int order, +int alloc_flags,struct alloc_context *ac) +{ +}#endif /* CONFIG_COMPACTION */ #if defined(CONFIG_COMPACTION ) && defined(CONFIG_SYSFS ) && defined(CONFIG_NUMA )
include/linux/mmzone.h +2 -0
@@ -478,6 +478,7 @@ struct zone {unsigned int compact_considered;unsigned int compact_defer_shift;int compact_order_failed; +unsigned int compact_free_target[MAX_ORDER ];#endif #if definedCONFIG_COMPACTION || definedCONFIG_CMA
@@ -635,6 +636,7 @@ typedef struct pglist_data {enum zone_type kcompactd_classzone_idx;wait_queue_head_t kcompactd_wait;struct task_struct *kcompactd; +atomic_t compact_free_target[MAX_ORDER ];#endif #ifdef CONFIG_NUMA_BALANCING /* Lock serializing the migrate rate limiting window */
mm/compaction.c +162 -3
213 lines not on this page · raw message
mm/page_alloc.c +12 -0
@@ -3697,6 +3697,14 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, goto got_pg;/* +* If it looks like increased kcompactd effort could have spared +* us from direct compaction (or allocation failure if we cannot +* compact), increase kcompactd's target. +*/ +if (order >0 ) +kcompactd_inc_free_target (gfp_mask, order, alloc_flags, ac); + +/* * For costly allocations, try direct compaction first, as it's likely * that we have enough base pages and don't need to reclaim. Don't try * that for allocations that are allowed to ignore watermarks, as the
@@ -5946,6 +5954,7 @@ static unsigned long __paginginit calc_memmap_size(unsigned long spanned_pages,*/ static void __paginginit free_area_init_core(struct pglist_data *pgdat) { +int i;enum zone_type j;int nid = pgdat->node_id;int ret;
@@ -5965,6 +5974,9 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat)init_waitqueue_head (&pgdat->pfmemalloc_wait);#ifdef CONFIG_COMPACTION init_waitqueue_head (&pgdat->kcompactd_wait); +for (i =0 ; i <MAX_ORDER ; i++) +//FIXME: I can't use ATOMIC_INIT, can I? +atomic_set (&pgdat->compact_free_target[i],0 );#endif pgdat_page_ext_init (pgdat);spin_lock_init (&pgdat->lru_lock);
Signature · 8 lines
2.12.0 -- 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-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>