Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1546082 > unrolled thread
| Started by | David Rientjes <rientjes@google.com> |
|---|---|
| First post | 2016-12-22 01:30 +0100 |
| Last post | 2017-01-04 23:10 +0100 |
| Articles | 9 on this page of 29 — 5 participants |
Back to article view | Back to linux.kernel
[patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred David Rientjes <rientjes@google.com> - 2016-12-22 01:30 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred "Kirill A. Shutemov" <kirill@shutemov.name> - 2016-12-22 09:40 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred Michal Hocko <mhocko@kernel.org> - 2016-12-22 11:10 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred David Rientjes <rientjes@google.com> - 2016-12-22 22:10 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred Michal Hocko <mhocko@kernel.org> - 2016-12-23 10:00 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred David Rientjes <rientjes@google.com> - 2016-12-23 11:10 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred Michal Hocko <mhocko@kernel.org> - 2016-12-23 12:20 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred David Rientjes <rientjes@google.com> - 2016-12-23 23:50 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred Michal Hocko <mhocko@kernel.org> - 2016-12-26 10:10 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred David Rientjes <rientjes@google.com> - 2016-12-27 02:00 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred "Kirill A. Shutemov" <kirill@shutemov.name> - 2016-12-27 03:40 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred Michal Hocko <mhocko@kernel.org> - 2016-12-27 10:50 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred David Rientjes <rientjes@google.com> - 2016-12-27 22:40 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred Michal Hocko <mhocko@kernel.org> - 2016-12-28 09:50 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred David Rientjes <rientjes@google.com> - 2016-12-28 22:40 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred Michal Hocko <mhocko@kernel.org> - 2016-12-29 09:30 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred Mel Gorman <mgorman@techsingularity.net> - 2016-12-30 13:40 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred Michal Hocko <mhocko@kernel.org> - 2016-12-30 14:00 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred Mel Gorman <mgorman@techsingularity.net> - 2016-12-30 15:10 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred David Rientjes <rientjes@google.com> - 2016-12-30 23:40 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred Mel Gorman <mgorman@techsingularity.net> - 2017-01-03 11:40 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred David Rientjes <rientjes@google.com> - 2017-01-03 23:00 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred Mel Gorman <mgorman@techsingularity.net> - 2017-01-04 11:20 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred David Rientjes <rientjes@google.com> - 2017-01-04 23:00 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred Vlastimil Babka <vbabka@suse.cz> - 2017-01-02 09:40 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred David Rientjes <rientjes@google.com> - 2017-01-03 23:50 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred Vlastimil Babka <vbabka@suse.cz> - 2017-01-04 09:40 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred Michal Hocko <mhocko@kernel.org> - 2017-01-04 10:50 +0100
Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred David Rientjes <rientjes@google.com> - 2017-01-04 23:10 +0100
Page 2 of 2 — ← Prev page 1 [2]
| From | Mel Gorman <mgorman@techsingularity.net> |
|---|---|
| Date | 2017-01-03 11:40 +0100 |
| Subject | Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred |
| Message-ID | <sVuFz-4UG-1@gated-at.bofh.it> |
| In reply to | #1548743 |
On Fri, Dec 30, 2016 at 02:30:32PM -0800, David Rientjes wrote: > On Fri, 30 Dec 2016, Mel Gorman wrote: > > > Michal is correct in that my intent for defer was to have "never stall" > > as the default behaviour. This was because of the number of severe stalls > > users experienced that lead to recommendations in tuning guides to always > > disable THP. I'd also seen multiple instances in bug reports for stalls > > where it was suggested that THP be disabled even when it could not have > > been a factor. It would be preferred to keep the default behaviour to > > avoid reintroducing such bugs. > > > > I sympathize with that, I've dealt with a number of issues that we have > encountered where thp defrag was either at fault or wasn't, and there were > also suggestions to set defrag to "madvise" to rule it out and that > impacted other users. > > I'm curious if you could show examples where there were severe stalls > being encountered by applications that did madvise(MADV_HUGEPAGE) I do not have a bug report that is specific to MADV_HUGEPAGE. Until very recently they would have been masked by THP fault overhead in general. The current defer logic isn't in the field long enough to generate bugs that are detailed enough to catch something like this. > and > users were forced to set madvise to "never". In the bugs I've dealt with, the switch was between "always" and "never". I haven't seen a bug specific to "madvise". > That is, after all, the only > topic for consideration in this thread: the direct impact to users of > madvise(MADV_HUGEPAGE). If an application does it, I believe that's a > demand for work to be done at allocation time to try to get hugepages. > They can certainly provide an application-level option to not do the > MADV_HUGEPAGE. Qemu is no different, you can add options to do > madvise(MADV_HUGEPAGE) or not, and you can also do it after fault. > True, it's possible that this is minor hence why I didn't want to outright Nak the patch. > The problem with the current option set is that we don't have the ability > to trigger background compaction for everybody, which only very minimally > impacts their page fault latency since it just wakes up kcompactd, and > allow MADV_HUGEPAGE users to accept that up-front cost by doing direct > compaction. My usecase, remapping .text segment and faulting thp memory > at startup, demands that ability. Setting defrag=madvise gets that > behavior, but nobody else triggers background compaction when thp memory > fails and we _want_ that behavior so work is being done to defrag. > Setting defrag=defer makes MADV_HUGEPAGE a no-op for page fault, and I > argue that's the wrong behavior. > Again, I accept your reasoning and I don't have direct evidence that it'll be a problem. In an emergency, it could also be worked around using LD_PRELOAD or a systemtap script until a kernel fix could be applied. Unfortunately it could also be years before a patch like this would hit enough users for me to spot the problem in the field. That's not enough to Nak the patch but it was enough to suggest an alternative that would side-step the problem ever occurring. > > I'll neither ack nor nak this patch. However, I would much prefer an > > additional option be added to sysfs called defer-fault that would avoid > > all fault-based stalls but still potentially stall for MADV_HUGEPAGE. I > > would also prefer that the default option is "defer" for both MADV_HUGEPAGE > > and faults. > > > > If you want a fifth option added to sysfs for thp defrag, that's fine, we > can easily do that. I'm slightly concerned with more and more options > added that we will eventually approach the 2^4 option count that I > mentioned earlier and nobody will know what to select. I'm fine with the > kernel default remaining as "madvise," I find it hard to believe this one *can* explode. There are a limited number of user-triggable actions that can trigger stalls. > we will just set it to whatever > gets us "direct for madvise, background for everybody else" behavior as we > were planning on using "defer." > > We can either do > > (1) merge this patch and allow madvise(MADV_HUGEPAGE) users to always try > to get hugepages, potentially adding options to qemu to suppress > their MADV_HUGEPAGE if users have complained (would even fix the > issue on 2.6 kernels) or do it after majority has been faulted, or > > (2) add a fifth defrag option to do this suggested behavior and maintain > that option forever. > > I'd obviously prefer the former since I consider MADV_HUGEPAGE and not > willing to stall as a userspace issue that can _trivially_ be worked > around in userspace, but in the interest of moving forward on this we can > do the latter if you'd prefer. The latter is preferred because it prevents any possibility of encountering this in the field and being unable to workaround it with LD_PRELOAD or systemtap hackery but I won't nak the former either on the grounds I have no data it's a problem and it could be a year or more before I have an example. If it's encountered, we'll be back at introducing another sysfs option. -- Mel Gorman SUSE Labs
[toc] | [prev] | [next] | [standalone]
| From | David Rientjes <rientjes@google.com> |
|---|---|
| Date | 2017-01-03 23:00 +0100 |
| Subject | Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred |
| Message-ID | <sVFhD-3PT-9@gated-at.bofh.it> |
| In reply to | #1549680 |
On Tue, 3 Jan 2017, Mel Gorman wrote: > > I sympathize with that, I've dealt with a number of issues that we have > > encountered where thp defrag was either at fault or wasn't, and there were > > also suggestions to set defrag to "madvise" to rule it out and that > > impacted other users. > > > > I'm curious if you could show examples where there were severe stalls > > being encountered by applications that did madvise(MADV_HUGEPAGE) > > I do not have a bug report that is specific to MADV_HUGEPAGE. Until very > recently they would have been masked by THP fault overhead in general. I parse this, the masking of thp fault overhead in general, as an indication that the qemu user was using defrag set to "always" rather than the new kernel default of "madvise". I wholeheartedly agree that we don't want defrag to be set to "always" be default, but that's not really a huge concern: we can easily set it to anything else by initscripts. Qemu, when they added the MADV_HUGEPAGE, obviously wanted to try to allocate hugepages at fault using the available means when defrag was set to "madvise": https://patchwork.ozlabs.org/patch/177695 So now qemu notices no difference that the kernel default has changed, but you later reference qemu in your email about bugs concerning "slow start times." It's puzzling unless you're offering a defrag setting of "defer" to workaround this potential bug report, which affects the whole machine and now qemu users have _no_ option to try to get thp at fault because the admin thinks he knows better, essentially making MADV_HUGEPAGE a no-op with no alternative provided. That's specifically what I'm arguing against. Qemu can be fixed, and I'll do it myself if necessary, when allocating a new RAMBlock or translation buffer to suppress the MADV_HUGEPAGE if configured. It's a very trivial change, and I can do that if you'll kindly point me to the initial bug report so I can propose it to the appropriate user. As Vlastimil also correctly brings up, there is already a prctl(PR_SET_THP_DISABLE) option available to prevent hugepages at fault and simply requires you to fork the process in the correct context to inherit the vma setting, see commit 1e1836e84f87. > The current defer logic isn't in the field long enough to generate bugs > that are detailed enough to catch something like this. > Let us consider this email as a generating a bug that we, the users of MADV_HUGEPAGE that are using the madvise(2) correctly and add flags to suppress it when desired correctly, have no option to allow background compaction for everybody when we cannot allocate thp immediately but also allow users of our library to accept the cost of direct compaction at fault because they really want their .text segment remapped and backed by hugepages. > > The problem with the current option set is that we don't have the ability > > to trigger background compaction for everybody, which only very minimally > > impacts their page fault latency since it just wakes up kcompactd, and > > allow MADV_HUGEPAGE users to accept that up-front cost by doing direct > > compaction. My usecase, remapping .text segment and faulting thp memory > > at startup, demands that ability. Setting defrag=madvise gets that > > behavior, but nobody else triggers background compaction when thp memory > > fails and we _want_ that behavior so work is being done to defrag. > > Setting defrag=defer makes MADV_HUGEPAGE a no-op for page fault, and I > > argue that's the wrong behavior. > > > > Again, I accept your reasoning and I don't have direct evidence that it'll be > a problem. In an emergency, it could also be worked around using LD_PRELOAD > or a systemtap script until a kernel fix could be applied. Unfortunately it > could also be years before a patch like this would hit enough users for me > to spot the problem in the field. That's not enough to Nak the patch but > it was enough to suggest an alternative that would side-step the problem > ever occurring. > Or simply forking the application after doing prctl(PR_SET_THP_DISABLE)? What exactly are you working around with a LD_PRELOAD that isn't addressed by this? Btw, is there a qemu bug filed that makes doing the MADV_HUGEPAGE configurable? I don't find it at https://bugs.launchpad.net/qemu. > > If you want a fifth option added to sysfs for thp defrag, that's fine, we > > can easily do that. I'm slightly concerned with more and more options > > added that we will eventually approach the 2^4 option count that I > > mentioned earlier and nobody will know what to select. I'm fine with the > > kernel default remaining as "madvise," > > I find it hard to believe this one *can* explode. There are a limited > number of user-triggable actions that can trigger stalls. > I'm confused as to whether you support the addition of a fifth option that users will have to learn what they want, or whether you are open to changing the behavior of "defer" to actually respect userspace madvise(2)?
[toc] | [prev] | [next] | [standalone]
| From | Mel Gorman <mgorman@techsingularity.net> |
|---|---|
| Date | 2017-01-04 11:20 +0100 |
| Subject | Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred |
| Message-ID | <sVQPL-3lt-7@gated-at.bofh.it> |
| In reply to | #1550240 |
On Tue, Jan 03, 2017 at 01:57:33PM -0800, David Rientjes wrote: > On Tue, 3 Jan 2017, Mel Gorman wrote: > > > > I sympathize with that, I've dealt with a number of issues that we have > > > encountered where thp defrag was either at fault or wasn't, and there were > > > also suggestions to set defrag to "madvise" to rule it out and that > > > impacted other users. > > > > > > I'm curious if you could show examples where there were severe stalls > > > being encountered by applications that did madvise(MADV_HUGEPAGE) > > > > I do not have a bug report that is specific to MADV_HUGEPAGE. Until very > > recently they would have been masked by THP fault overhead in general. > > I parse this, the masking of thp fault overhead in general, as an > indication that the qemu user was using defrag set to "always" rather than > the new kernel default of "madvise". > There is a slight disconnect. The bug reports I'm aware of predate the introduction of "defer" and the current "madvise" semantics for defrag. The current semantics have not had enough time in the field to generate reports. I expect lag before users are aware of "defer" due to the number of recommendations out there about blindly disabling THP. This because the majority of users I deal with are not running mainline kernels. > <SNIP> > > Qemu can be fixed, and I'll do it myself if necessary, when allocating a > new RAMBlock or translation buffer to suppress the MADV_HUGEPAGE if > configured. It's a very trivial change, and I can do that if you'll > kindly point me to the initial bug report so I can propose it to the > appropriate user. > I don't have a QEMU-related bug to point to. Even if I did, it would be an enterprise distribution bug that isn't public. My expectation is that if I get a bug, that it's going to be QEMU-related but I'm guessing. > As Vlastimil also correctly brings up, there is already a > prctl(PR_SET_THP_DISABLE) option available to prevent hugepages at fault > and simply requires you to fork the process in the correct context to > inherit the vma setting, see commit 1e1836e84f87. > That disables everything and functionally similar to disabling THP. > > The current defer logic isn't in the field long enough to generate bugs > > that are detailed enough to catch something like this. > > > > Let us consider this email as a generating a bug that we, the users of > MADV_HUGEPAGE that are using the madvise(2) correctly and add flags to > suppress it when desired correctly, have no option to allow background > compaction for everybody when we cannot allocate thp immediately but also > allow users of our library to accept the cost of direct compaction at > fault because they really want their .text segment remapped and backed by > hugepages. > Again, I accept that. A new option for the semantics you want instead of adjusting the existing "defer" semantics is preferred to give the "more heavyweight version of madvise" you're looking for. This is simply because it's easier to resolve in the field when users are not always that knowledgable and are typically reluctant to modify application launching but usually open to adjusting kernel tunables. > > > The problem with the current option set is that we don't have the ability > > > to trigger background compaction for everybody, which only very minimally > > > impacts their page fault latency since it just wakes up kcompactd, and > > > allow MADV_HUGEPAGE users to accept that up-front cost by doing direct > > > compaction. My usecase, remapping .text segment and faulting thp memory > > > at startup, demands that ability. Setting defrag=madvise gets that > > > behavior, but nobody else triggers background compaction when thp memory > > > fails and we _want_ that behavior so work is being done to defrag. > > > Setting defrag=defer makes MADV_HUGEPAGE a no-op for page fault, and I > > > argue that's the wrong behavior. > > > > > > > Again, I accept your reasoning and I don't have direct evidence that it'll be > > a problem. In an emergency, it could also be worked around using LD_PRELOAD > > or a systemtap script until a kernel fix could be applied. Unfortunately it > > could also be years before a patch like this would hit enough users for me > > to spot the problem in the field. That's not enough to Nak the patch but > > it was enough to suggest an alternative that would side-step the problem > > ever occurring. > > > > Or simply forking the application after doing prctl(PR_SET_THP_DISABLE)? > What exactly are you working around with a LD_PRELOAD that isn't addressed > by this? > LD_PRELOAD can mask the MADV flag for get the existing "defer" semantics. Disabling THP entirely is something else. > Btw, is there a qemu bug filed that makes doing the MADV_HUGEPAGE > configurable? I don't find it at https://bugs.launchpad.net/qemu. > Not that I'm aware of but I didn't go looking either. > > > If you want a fifth option added to sysfs for thp defrag, that's fine, we > > > can easily do that. I'm slightly concerned with more and more options > > > added that we will eventually approach the 2^4 option count that I > > > mentioned earlier and nobody will know what to select. I'm fine with the > > > kernel default remaining as "madvise," > > > > I find it hard to believe this one *can* explode. There are a limited > > number of user-triggable actions that can trigger stalls. > > > > I'm confused as to whether you support the addition of a fifth option that > users will have to learn what they want, or whether you are open to > changing the behavior of "defer" to actually respect userspace madvise(2)? I would prefer the fifth option and have users select the option if they need it and preserve the existing semantics of defer. However, as I've stated before, as I'm not actually aware of problems with madvise and the current semantics so I cannot nak the patch you have. It'll simply require to have some solution in mind if a bug is encountered. When THP was first introduced, it was months before users started reporting bugs as most users I deal with are not running mainline kernels. There was similar lag when automatic NUMA balancing was introduced. I expect a similar lag for the existing "madvise" default and some education about using "defer" instead of disabling THP entirely when stalls are encountered. It's the hazard of dealing with users that lag behind mainline and it's not a unique problem. -- Mel Gorman SUSE Labs
[toc] | [prev] | [next] | [standalone]
| From | David Rientjes <rientjes@google.com> |
|---|---|
| Date | 2017-01-04 23:00 +0100 |
| Subject | Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred |
| Message-ID | <sW1Lb-1ZK-1@gated-at.bofh.it> |
| In reply to | #1550610 |
On Wed, 4 Jan 2017, Mel Gorman wrote: > There is a slight disconnect. The bug reports I'm aware of predate the > introduction of "defer" and the current "madvise" semantics for defrag. The > current semantics have not had enough time in the field to generate > reports. I expect lag before users are aware of "defer" due to the number > of recommendations out there about blindly disabling THP. This because > the majority of users I deal with are not running mainline kernels. > I find it sad that we need to have five options for thp defrag and that people now need to research options that don't break their userspace and affect all applications on the system, especially when one of those options now appears to have a hypothetical usecase, but in the interest of making forward progress in this area for support that we truly need, I'll reluctantly propose it as a patch.
[toc] | [prev] | [next] | [standalone]
| From | Vlastimil Babka <vbabka@suse.cz> |
|---|---|
| Date | 2017-01-02 09:40 +0100 |
| Subject | Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred |
| Message-ID | <sV6jU-4bE-7@gated-at.bofh.it> |
| In reply to | #1546082 |
On 12/22/2016 01:21 AM, David Rientjes wrote:
> Currently, when defrag is set to "madvise", thp allocations will direct
> reclaim. However, when defrag is set to "defer", all thp allocations do
> not attempt reclaim regardless of MADV_HUGEPAGE.
>
> This patch always directly reclaims for MADV_HUGEPAGE regions when defrag
> is not set to "never." The idea is that MADV_HUGEPAGE regions really
> want to be backed by hugepages and are willing to endure the latency at
> fault as it was the default behavior prior to commit 444eb2a449ef ("mm:
> thp: set THP defrag by default to madvise and add a stall-free defrag
> option").
>
> In this form, "defer" is a stronger, more heavyweight version of
> "madvise".
>
> Signed-off-by: David Rientjes <rientjes@google.com>
I'm late to the thread (I did read it fully though), so instead of
multiple responses, I'll just list my observations here:
- "defer", e.g. background kswapd+compaction is not a silver bullet, it
will also affect the system. Mel already mentioned extra reclaim.
Compaction also has CPU costs, just hides the accounting to a kernel
thread so it's not visible as latency. It also increases zone/node
lru_lock and lock pressure.
For the same reasons, admin might want to limit direct compaction for
THP, even for madvise() apps. It's also likely that "defer" might have
lower system overhead than "madvise", as with "defer",
reclaim/compaction is done by one per-node thread at a time, but there
might be multiple madvise() threads. So there might be sense in not
allowing madvise() apps to do direct reclaim/compaction on "defer".
- for overriding specific apps such as QEMU (including their madvise()
usage, AFAICS), we have PR_SET_THP_DISABLE prctl(), so no need to
LD_PRELOAD stuff IMO.
- I have wondered about exactly the issue here when Mel proposed the
defer option [1]. Mel responded that it doesn't seem needed at that
point. Now it seems it is. Too bad you didn't raise it then, but to be
fair you were not CC'd.
So would something like this be possible?
> echo "defer madvise" > /sys/kernel/mm/transparent_hugepage/defrag
> cat /sys/kernel/mm/transparent_hugepage/defrag
always [defer] [madvise] never
I'm not sure about the analogous kernel boot option though, I guess
those can't use spaces, so maybe comma-separated?
If that's not acceptable, then I would probably rather be for changing
"madvise" to include "defer", than the other way around. When we augment
kcompactd to be more proactive, it might easily be that it will
effectively act as "defer", even when defrag=none is set, anyway.
[1] http://marc.info/?l=linux-mm&m=145683613929750&w=2
> ---
> Documentation/vm/transhuge.txt | 7 +++++--
> mm/huge_memory.c | 10 ++++++----
> 2 files changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/Documentation/vm/transhuge.txt b/Documentation/vm/transhuge.txt
> --- a/Documentation/vm/transhuge.txt
> +++ b/Documentation/vm/transhuge.txt
> @@ -121,8 +121,11 @@ to utilise them.
>
> "defer" means that an application will wake kswapd in the background
> to reclaim pages and wake kcompact to compact memory so that THP is
> -available in the near future. It's the responsibility of khugepaged
> -to then install the THP pages later.
> +available in the near future, unless it is for a region where
> +madvise(MADV_HUGEPAGE) has been used, in which case direct reclaim will be
> +used. Kcompactd will attempt to make hugepages available for allocation in
> +the near future and khugepaged will try to collapse existing memory into
> +hugepages later.
>
> "madvise" will enter direct reclaim like "always" but only for regions
> that are have used madvise(MADV_HUGEPAGE). This is the default behaviour.
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -619,15 +619,17 @@ static int __do_huge_pmd_anonymous_page(struct vm_fault *vmf, struct page *page,
> */
> static inline gfp_t alloc_hugepage_direct_gfpmask(struct vm_area_struct *vma)
> {
> - bool vma_madvised = !!(vma->vm_flags & VM_HUGEPAGE);
> + const bool vma_madvised = !!(vma->vm_flags & VM_HUGEPAGE);
>
> if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG,
> &transparent_hugepage_flags) && vma_madvised)
> return GFP_TRANSHUGE;
> else if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG,
> - &transparent_hugepage_flags))
> - return GFP_TRANSHUGE_LIGHT | __GFP_KSWAPD_RECLAIM;
> - else if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG,
> + &transparent_hugepage_flags)) {
> + return GFP_TRANSHUGE_LIGHT |
> + (vma_madvised ? __GFP_DIRECT_RECLAIM :
> + __GFP_KSWAPD_RECLAIM);
> + } else if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG,
> &transparent_hugepage_flags))
> return GFP_TRANSHUGE | (vma_madvised ? 0 : __GFP_NORETRY);
>
>
[toc] | [prev] | [next] | [standalone]
| From | David Rientjes <rientjes@google.com> |
|---|---|
| Date | 2017-01-03 23:50 +0100 |
| Subject | Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred |
| Message-ID | <sVG41-4nb-9@gated-at.bofh.it> |
| In reply to | #1549025 |
On Mon, 2 Jan 2017, Vlastimil Babka wrote: > I'm late to the thread (I did read it fully though), so instead of > multiple responses, I'll just list my observations here: > > - "defer", e.g. background kswapd+compaction is not a silver bullet, it > will also affect the system. Mel already mentioned extra reclaim. > Compaction also has CPU costs, just hides the accounting to a kernel > thread so it's not visible as latency. It also increases zone/node > lru_lock and lock pressure. > > For the same reasons, admin might want to limit direct compaction for > THP, even for madvise() apps. It's also likely that "defer" might have > lower system overhead than "madvise", as with "defer", > reclaim/compaction is done by one per-node thread at a time, but there > might be multiple madvise() threads. So there might be sense in not > allowing madvise() apps to do direct reclaim/compaction on "defer". > Hmm, is there a significant benefit to setting "defer" rather than "never" if you can rely on khugepaged to trigger compaction when it tries to allocate. I suppose if there is nothing to collapse that this won't do compaction, but is this not intended for users who always want to defer when not immediately available? "Defer" in it's current setting is useless, in my opinion, other than providing it as a simple workaround to users when their applications are doing MADV_HUGEPAGE without allowing them to configure it. We would love to use "defer" if it didn't completely break MADV_HUGEPAGE, though. > - for overriding specific apps such as QEMU (including their madvise() > usage, AFAICS), we have PR_SET_THP_DISABLE prctl(), so no need to > LD_PRELOAD stuff IMO. > Very good point, and I think it's also worthwhile to allow users to suppress the MADV_HUGEPAGE when allocating a translation buffer in qemu if they choose to do so; it's a very trivial patch to qemu to allow this to be configurable. I haven't proposed it because I don't personally have a need for it, and haven't been pointed to anyone who has a need for it. > - I have wondered about exactly the issue here when Mel proposed the > defer option [1]. Mel responded that it doesn't seem needed at that > point. Now it seems it is. Too bad you didn't raise it then, but to be > fair you were not CC'd. > My understanding is that the defer option is available to users who cannot modify their binary to suppress an madvise(MADV_HUGEPAGE) and are unaware that PR_SET_THP_DISABLE exists. The prctl was added specifically when you cannot control your binary. > So would something like this be possible? > > > echo "defer madvise" > /sys/kernel/mm/transparent_hugepage/defrag > > cat /sys/kernel/mm/transparent_hugepage/defrag > always [defer] [madvise] never > > I'm not sure about the analogous kernel boot option though, I guess > those can't use spaces, so maybe comma-separated? > > If that's not acceptable, then I would probably rather be for changing > "madvise" to include "defer", than the other way around. When we augment > kcompactd to be more proactive, it might easily be that it will > effectively act as "defer", even when defrag=none is set, anyway. > The concern I have with changing the behavior of "madvise" is that it changes long standing behavior that people have correctly implemented userspace applications with. I suggest doing this only with "defer" since it's an option that is new, nobody appears to be deploying with, and makes it much more powerful. I think we could make the kernel default as "defer" later as well and not break userspace that has been setting "madvise" ever since the 2.6 kernel. My position is this: userspace that does MADV_HUGEPAGES knows what it's doing. Let it stall if it wants to stall. If users don't want it to be done, allow them to configure it. If a binary has forced you into using it, use the prctl. Otherwise, I think "defer" doing background compaction for everybody and direct compaction for users who really want hugepages is appropriate and is precisely what I need.
[toc] | [prev] | [next] | [standalone]
| From | Vlastimil Babka <vbabka@suse.cz> |
|---|---|
| Date | 2017-01-04 09:40 +0100 |
| Subject | Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred |
| Message-ID | <sVPh0-2aY-9@gated-at.bofh.it> |
| In reply to | #1550266 |
On 01/03/2017 11:44 PM, David Rientjes wrote: > On Mon, 2 Jan 2017, Vlastimil Babka wrote: > >> I'm late to the thread (I did read it fully though), so instead of >> multiple responses, I'll just list my observations here: >> >> - "defer", e.g. background kswapd+compaction is not a silver bullet, it >> will also affect the system. Mel already mentioned extra reclaim. >> Compaction also has CPU costs, just hides the accounting to a kernel >> thread so it's not visible as latency. It also increases zone/node >> lru_lock and lock pressure. >> >> For the same reasons, admin might want to limit direct compaction for >> THP, even for madvise() apps. It's also likely that "defer" might have >> lower system overhead than "madvise", as with "defer", >> reclaim/compaction is done by one per-node thread at a time, but there >> might be multiple madvise() threads. So there might be sense in not >> allowing madvise() apps to do direct reclaim/compaction on "defer". >> > > Hmm, is there a significant benefit to setting "defer" rather than "never" > if you can rely on khugepaged to trigger compaction when it tries to > allocate. I suppose if there is nothing to collapse that this won't do > compaction, but is this not intended for users who always want to defer > when not immediately available? I guess two things - khugepaged is quite sleepy and will not respond to demand quickly, so it won't compact that much than kcompactd triggered by "defer" - thus with "defer" it's more likely that although some THP faults will fail, others in near future will succeed and benefit from THP immediately. Again, khugepaged is much slower. But it may recover long-running processes that were unlucky in the initial faults, so it's not useless. > "Defer" in it's current setting is useless, in my opinion, other than > providing it as a simple workaround to users when their applications are > doing MADV_HUGEPAGE without allowing them to configure it. I don't think the primary motivation for "defer" was to restrict MADV_HUGEPAGE apps, but rather to prevent latency to the majority of apps oblivious to THP when the default was "always". On the other hand, setting "madvise" would make performance needlessly worse in some scenarios, so "defer" is a compromise that tries to provide THP's but without the latency, and still much more timely than khugepaged. But that's just my POV, Mel probably has/had also the MADV_HUGEPAGE restriction in mind. I'd expect that the "you have to disable THP" cargo-cult originated around apps (databases?) that did not use MADV_HUGEPAGE, though. > We would love > to use "defer" if it didn't completely break MADV_HUGEPAGE, though. Right. >> - for overriding specific apps such as QEMU (including their madvise() >> usage, AFAICS), we have PR_SET_THP_DISABLE prctl(), so no need to >> LD_PRELOAD stuff IMO. >> > > Very good point, and I think it's also worthwhile to allow users to > suppress the MADV_HUGEPAGE when allocating a translation buffer in qemu if > they choose to do so; it's a very trivial patch to qemu to allow this to > be configurable. I haven't proposed it because I don't personally have a > need for it, and haven't been pointed to anyone who has a need for it. > >> - I have wondered about exactly the issue here when Mel proposed the >> defer option [1]. Mel responded that it doesn't seem needed at that >> point. Now it seems it is. Too bad you didn't raise it then, but to be >> fair you were not CC'd. >> > > My understanding is that the defer option is available to users who cannot > modify their binary to suppress an madvise(MADV_HUGEPAGE) and are unaware > that PR_SET_THP_DISABLE exists. The prctl was added specifically when you > cannot control your binary. Yeah, it's easier than LD_PRELOAD, but still not system-wide transparent. >> So would something like this be possible? >> >>> echo "defer madvise" > /sys/kernel/mm/transparent_hugepage/defrag >>> cat /sys/kernel/mm/transparent_hugepage/defrag >> always [defer] [madvise] never >> >> I'm not sure about the analogous kernel boot option though, I guess >> those can't use spaces, so maybe comma-separated? No opinion on the above? I think it could be somewhat more elegant than a fifth-option that Mel said he would prefer, and deliver the same flexibility. >> If that's not acceptable, then I would probably rather be for changing >> "madvise" to include "defer", than the other way around. When we augment >> kcompactd to be more proactive, it might easily be that it will >> effectively act as "defer", even when defrag=none is set, anyway. >> > > The concern I have with changing the behavior of "madvise" is that it > changes long standing behavior that people have correctly implemented > userspace applications with. I suggest doing this only with "defer" since > it's an option that is new, nobody appears to be deploying with, and makes > it much more powerful. I think we could make the kernel default as > "defer" later as well and not break userspace that has been setting > "madvise" ever since the 2.6 kernel. > > My position is this: userspace that does MADV_HUGEPAGES knows what it's > doing. Let it stall if it wants to stall. If users don't want it to be > done, allow them to configure it. If a binary has forced you into using > it, use the prctl. Otherwise, I think "defer" doing background compaction > for everybody and direct compaction for users who really want hugepages is > appropriate and is precisely what I need. I'm not completely against this. But we haven't really ruled out the most flexible option yet... > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> >
[toc] | [prev] | [next] | [standalone]
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2017-01-04 10:50 +0100 |
| Subject | Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred |
| Message-ID | <sVQmJ-2QA-19@gated-at.bofh.it> |
| In reply to | #1550518 |
On Wed 04-01-17 09:32:55, Vlastimil Babka wrote: > On 01/03/2017 11:44 PM, David Rientjes wrote: > > On Mon, 2 Jan 2017, Vlastimil Babka wrote: [...] > >>> echo "defer madvise" > /sys/kernel/mm/transparent_hugepage/defrag > >>> cat /sys/kernel/mm/transparent_hugepage/defrag > >> always [defer] [madvise] never > >> > >> I'm not sure about the analogous kernel boot option though, I guess > >> those can't use spaces, so maybe comma-separated? > > No opinion on the above? I think it could be somewhat more elegant than > a fifth-option that Mel said he would prefer, and deliver the same > flexibility. I am not sure we have considered the kcompactd watermark option throughly as well. In case the relation is not clear because I admit that the propsal was scattered in more emails. So let me summarize it here. Let's add a system configuration whih would control the pro-active background compaction which would - wake up kcompactd pro-actively even when there is no immediate memory pressure - based on the timeout - keep compacting as long as the requested order is under the configured watermark and the compaction makes further progress. Admin can set up this tunable to reflect demand for the THP in the particular workload. Now how it would play with the THP specific defrag options? - never - THP allocations will be tried without any feedback to kcopactd - no stalls in the page fault path - defer - THP allocations will be tried and kcompactd woken up outside of its wmark setting to catch with the workload - no stalls in the page fault path - madvise - do the direct compaction for madvised VMAs and rely on kcompactd watermarks setting to do the background compaction - always - do the direct compaction for all VMAs We won't have to add or modify any new THP specific option and we will have a generic user independent tunable to tell that the system should try to generate high order pages which is something that is demand for. Such a solution would be more flexible as well because the configuration could reflect the demand much better. Is there any reason, except for not being implemented yet, that would make it inappropriate for the described usecase? -- Michal Hocko SUSE Labs
[toc] | [prev] | [next] | [standalone]
| From | David Rientjes <rientjes@google.com> |
|---|---|
| Date | 2017-01-04 23:10 +0100 |
| Subject | Re: [patch] mm, thp: always direct reclaim for MADV_HUGEPAGE even when deferred |
| Message-ID | <sW1UT-2ik-57@gated-at.bofh.it> |
| In reply to | #1550518 |
On Wed, 4 Jan 2017, Vlastimil Babka wrote: > > Hmm, is there a significant benefit to setting "defer" rather than "never" > > if you can rely on khugepaged to trigger compaction when it tries to > > allocate. I suppose if there is nothing to collapse that this won't do > > compaction, but is this not intended for users who always want to defer > > when not immediately available? > > I guess two things > - khugepaged is quite sleepy and will not respond to demand quickly, so > it won't compact that much than kcompactd triggered by "defer" That's configurable, so if a user sets defrag to never, they also have the ability to make khugepaged more aggressive in the background to complement that decision. > I don't think the primary motivation for "defer" was to restrict > MADV_HUGEPAGE apps, but rather to prevent latency to the majority of > apps oblivious to THP when the default was "always". On the other hand, > setting "madvise" would make performance needlessly worse in some > scenarios, so "defer" is a compromise that tries to provide THP's but > without the latency, and still much more timely than khugepaged. > It's disappointing we need to have an option that exists solely to suppress a userspace MADV_HUGEPAGE and not actually fix the userspace to not do the MADV_HUGEPAGE in the first place by making it configurable. That is backwards compatible and doesn't require a new kernel version. This never gets answered in the thread, however, and I offered to make the very trivial patch to qemu to do that for the translation buffer but nobody who uses qemu is even asking for this. It's baffling. > >> So would something like this be possible? > >> > >>> echo "defer madvise" > /sys/kernel/mm/transparent_hugepage/defrag > >>> cat /sys/kernel/mm/transparent_hugepage/defrag > >> always [defer] [madvise] never > >> > >> I'm not sure about the analogous kernel boot option though, I guess > >> those can't use spaces, so maybe comma-separated? > > No opinion on the above? I think it could be somewhat more elegant than > a fifth-option that Mel said he would prefer, and deliver the same > flexibility. > I think this would work, but I'm concerned about two things: (1) the kernel command line format as you pointed out earlier, (2) allowing two options to be combined but not other options (always + never), so it takes even more explaining to do to say what you can actually formulate and what the results of that combining is. The tristate, quadstate, and now quint-state options for thp were never extendable, but now this appears to be the most desired option. We can await the bug reports of users who say their MADV_HUGEPAGE is a no-op, though, and tell them their admin needs to switch away from "defer" if anybody actually ever uses that setting. I think you, me, and Kirill are mostly on the same page with respect to this, but I can't argue against hypothetical usecases and how we need to wait years for "defer" to be available to see if any bug reports are generated to make a decision in this area, so my final proposal in this matter will be the reluctant fifth option and if it doesn't work I'll just carry this for ourselves (we have no use for "defer" without this patch).
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | linux.kernel
csiph-web