Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1643173 > unrolled thread
| Started by | Michal Hocko <mhocko@kernel.org> |
|---|---|
| First post | 2017-05-17 11:30 +0200 |
| Last post | 2017-05-19 13:30 +0200 |
| Articles | 15 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [RFC 1/6] mm, page_alloc: fix more premature OOM due to race with cpuset update Michal Hocko <mhocko@kernel.org> - 2017-05-17 11:30 +0200
Re: [RFC 1/6] mm, page_alloc: fix more premature OOM due to race with cpuset update Christoph Lameter <cl@linux.com> - 2017-05-17 16:00 +0200
Re: [RFC 1/6] mm, page_alloc: fix more premature OOM due to race with cpuset update Michal Hocko <mhocko@kernel.org> - 2017-05-17 16:10 +0200
Re: [RFC 1/6] mm, page_alloc: fix more premature OOM due to race with cpuset update Christoph Lameter <cl@linux.com> - 2017-05-17 16:50 +0200
Re: [RFC 1/6] mm, page_alloc: fix more premature OOM due to race with cpuset update Michal Hocko <mhocko@kernel.org> - 2017-05-17 17:00 +0200
Re: [RFC 1/6] mm, page_alloc: fix more premature OOM due to race with cpuset update Christoph Lameter <cl@linux.com> - 2017-05-17 17:30 +0200
Re: [RFC 1/6] mm, page_alloc: fix more premature OOM due to race with cpuset update Christoph Lameter <cl@linux.com> - 2017-05-17 17:30 +0200
Re: [RFC 1/6] mm, page_alloc: fix more premature OOM due to race with cpuset update Michal Hocko <mhocko@kernel.org> - 2017-05-18 11:10 +0200
Re: [RFC 1/6] mm, page_alloc: fix more premature OOM due to race with cpuset update Christoph Lameter <cl@linux.com> - 2017-05-18 19:00 +0200
Re: [RFC 1/6] mm, page_alloc: fix more premature OOM due to race with cpuset update Michal Hocko <mhocko@kernel.org> - 2017-05-18 19:30 +0200
Re: [RFC 1/6] mm, page_alloc: fix more premature OOM due to race with cpuset update Christoph Lameter <cl@linux.com> - 2017-05-18 21:10 +0200
Re: [RFC 1/6] mm, page_alloc: fix more premature OOM due to race with cpuset update Michal Hocko <mhocko@kernel.org> - 2017-05-19 09:40 +0200
Re: [RFC 1/6] mm, page_alloc: fix more premature OOM due to race with cpuset update Vlastimil Babka <vbabka@suse.cz> - 2017-05-18 12:10 +0200
Re: [RFC 1/6] mm, page_alloc: fix more premature OOM due to race with cpuset update Christoph Lameter <cl@linux.com> - 2017-05-18 19:10 +0200
Re: [RFC 1/6] mm, page_alloc: fix more premature OOM due to race with cpuset update Vlastimil Babka <vbabka@suse.cz> - 2017-05-19 13:30 +0200
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2017-05-17 11:30 +0200 |
| Subject | Re: [RFC 1/6] mm, page_alloc: fix more premature OOM due to race with cpuset update |
| Message-ID | <tI3rj-1fU-11@gated-at.bofh.it> |
On Sun 30-04-17 16:33:10, Cristopher Lameter wrote: > On Wed, 26 Apr 2017, Vlastimil Babka wrote: > > > > Such an application typically already has such logic and executes a > > > binding after discovering its numa node configuration on startup. It would > > > have to be modified to redo that action when it gets some sort of a signal > > > from the script telling it that the node config would be changed. > > > > > > Having this logic in the application instead of the kernel avoids all the > > > kernel messes that we keep on trying to deal with and IMHO is much > > > cleaner. > > > > That would be much simpler for us indeed. But we still IMHO can't > > abruptly start denying page fault allocations for existing applications > > that don't have the necessary awareness. > > We certainly can do that. The failure of the page faults are due to the > admin trying to move an application that is not aware of this and is using > mempols. That could be an error. Trying to move an application that > contains both absolute and relative node numbers is definitely something > that is potentiall so screwed up that the kernel should not muck around > with such an app. > > Also user space can determine if the application is using memory policies > and can then take appropriate measures (message to the sysadmin to eval > tge situation f.e.) or mess aroud with the processes memory policies on > its own. > > So this is certainly a way out of this mess. So how are you going to distinguish VM_FAULT_OOM from an empty mempolicy case in a raceless way? -- Michal Hocko SUSE Labs
[toc] | [next] | [standalone]
| From | Christoph Lameter <cl@linux.com> |
|---|---|
| Date | 2017-05-17 16:00 +0200 |
| Message-ID | <tI7EC-3KY-13@gated-at.bofh.it> |
| In reply to | #1643173 |
On Wed, 17 May 2017, Michal Hocko wrote: > > We certainly can do that. The failure of the page faults are due to the > > admin trying to move an application that is not aware of this and is using > > mempols. That could be an error. Trying to move an application that > > contains both absolute and relative node numbers is definitely something > > that is potentiall so screwed up that the kernel should not muck around > > with such an app. > > > > Also user space can determine if the application is using memory policies > > and can then take appropriate measures (message to the sysadmin to eval > > tge situation f.e.) or mess aroud with the processes memory policies on > > its own. > > > > So this is certainly a way out of this mess. > > So how are you going to distinguish VM_FAULT_OOM from an empty mempolicy > case in a raceless way? You dont have to do that if you do not create an empty mempolicy in the first place. The current kernel code avoids that by first allowing access to the new set of nodes and removing the old ones from the set when done.
[toc] | [prev] | [next] | [standalone]
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2017-05-17 16:10 +0200 |
| Message-ID | <tI7Oi-43z-21@gated-at.bofh.it> |
| In reply to | #1643373 |
On Wed 17-05-17 08:56:34, Cristopher Lameter wrote: > On Wed, 17 May 2017, Michal Hocko wrote: > > > > We certainly can do that. The failure of the page faults are due to the > > > admin trying to move an application that is not aware of this and is using > > > mempols. That could be an error. Trying to move an application that > > > contains both absolute and relative node numbers is definitely something > > > that is potentiall so screwed up that the kernel should not muck around > > > with such an app. > > > > > > Also user space can determine if the application is using memory policies > > > and can then take appropriate measures (message to the sysadmin to eval > > > tge situation f.e.) or mess aroud with the processes memory policies on > > > its own. > > > > > > So this is certainly a way out of this mess. > > > > So how are you going to distinguish VM_FAULT_OOM from an empty mempolicy > > case in a raceless way? > > You dont have to do that if you do not create an empty mempolicy in the > first place. The current kernel code avoids that by first allowing access > to the new set of nodes and removing the old ones from the set when done. which is racy and as Vlastimil pointed out. If we simply fail such an allocation the failure will go up the call chain until we hit the OOM killer due to VM_FAULT_OOM. How would you want to handle that? -- Michal Hocko SUSE Labs
[toc] | [prev] | [next] | [standalone]
| From | Christoph Lameter <cl@linux.com> |
|---|---|
| Date | 2017-05-17 16:50 +0200 |
| Message-ID | <tI8qZ-4kw-1@gated-at.bofh.it> |
| In reply to | #1643379 |
On Wed, 17 May 2017, Michal Hocko wrote: > > > So how are you going to distinguish VM_FAULT_OOM from an empty mempolicy > > > case in a raceless way? > > > > You dont have to do that if you do not create an empty mempolicy in the > > first place. The current kernel code avoids that by first allowing access > > to the new set of nodes and removing the old ones from the set when done. > > which is racy and as Vlastimil pointed out. If we simply fail such an > allocation the failure will go up the call chain until we hit the OOM > killer due to VM_FAULT_OOM. How would you want to handle that? The race is where? If you expand the node set during the move of the application then you are safe in terms of the legacy apps that did not include static bindings. If you have screwy things like static mbinds in there then you are hopelessly lost anyways. You may have moved the process to another set of nodes but the static bindings may refer to a node no longer available. Thus the OOM is legitimate. At least a user space app could inspect the situation and come up with custom ways of dealing with the mess.
[toc] | [prev] | [next] | [standalone]
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2017-05-17 17:00 +0200 |
| Message-ID | <tI8AH-4o1-55@gated-at.bofh.it> |
| In reply to | #1643410 |
On Wed 17-05-17 09:48:25, Cristopher Lameter wrote: > On Wed, 17 May 2017, Michal Hocko wrote: > > > > > So how are you going to distinguish VM_FAULT_OOM from an empty mempolicy > > > > case in a raceless way? > > > > > > You dont have to do that if you do not create an empty mempolicy in the > > > first place. The current kernel code avoids that by first allowing access > > > to the new set of nodes and removing the old ones from the set when done. > > > > which is racy and as Vlastimil pointed out. If we simply fail such an > > allocation the failure will go up the call chain until we hit the OOM > > killer due to VM_FAULT_OOM. How would you want to handle that? > > The race is where? If you expand the node set during the move of the > application then you are safe in terms of the legacy apps that did not > include static bindings. I am pretty sure it is describe in those changelogs and I won't repeat it here. > If you have screwy things like static mbinds in there then you are > hopelessly lost anyways. You may have moved the process to another set > of nodes but the static bindings may refer to a node no longer > available. Thus the OOM is legitimate. The point is that you do _not_ want such a process to trigger the OOM because it can cause other processes being killed. > At least a user space app could inspect > the situation and come up with custom ways of dealing with the mess. I do not really see how would this help to prevent a malicious user from playing tricks. -- Michal Hocko SUSE Labs
[toc] | [prev] | [next] | [standalone]
| From | Christoph Lameter <cl@linux.com> |
|---|---|
| Date | 2017-05-17 17:30 +0200 |
| Message-ID | <tI93I-4Nh-15@gated-at.bofh.it> |
| In reply to | #1643440 |
On Wed, 17 May 2017, Michal Hocko wrote: > > The race is where? If you expand the node set during the move of the > > application then you are safe in terms of the legacy apps that did not > > include static bindings. > > I am pretty sure it is describe in those changelogs and I won't repeat > it here. I cannot figure out what you are referring to. There are numerous patches and discussions about OOM scenarios in this context.
[toc] | [prev] | [next] | [standalone]
| From | Christoph Lameter <cl@linux.com> |
|---|---|
| Date | 2017-05-17 17:30 +0200 |
| Message-ID | <tI93I-4Nh-23@gated-at.bofh.it> |
| In reply to | #1643440 |
On Wed, 17 May 2017, Michal Hocko wrote: > > If you have screwy things like static mbinds in there then you are > > hopelessly lost anyways. You may have moved the process to another set > > of nodes but the static bindings may refer to a node no longer > > available. Thus the OOM is legitimate. > > The point is that you do _not_ want such a process to trigger the OOM > because it can cause other processes being killed. Nope. The OOM in a cpuset gets the process doing the alloc killed. Or what that changed? At this point you have messed up royally and nothing is going to rescue you anyways. OOM or not does not matter anymore. The app will fail. > > At least a user space app could inspect > > the situation and come up with custom ways of dealing with the mess. > > I do not really see how would this help to prevent a malicious user from > playing tricks. How did a malicious user come into this? Of course you can mess up in significant ways if you can overflow nodes and cause an app that has restrictions to fail but nothing is going to change that.
[toc] | [prev] | [next] | [standalone]
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2017-05-18 11:10 +0200 |
| Message-ID | <tIpBw-8eh-27@gated-at.bofh.it> |
| In reply to | #1643464 |
On Wed 17-05-17 10:25:09, Cristopher Lameter wrote: > On Wed, 17 May 2017, Michal Hocko wrote: > > > > If you have screwy things like static mbinds in there then you are > > > hopelessly lost anyways. You may have moved the process to another set > > > of nodes but the static bindings may refer to a node no longer > > > available. Thus the OOM is legitimate. > > > > The point is that you do _not_ want such a process to trigger the OOM > > because it can cause other processes being killed. > > Nope. The OOM in a cpuset gets the process doing the alloc killed. Or what > that changed? > > At this point you have messed up royally and nothing is going to rescue > you anyways. OOM or not does not matter anymore. The app will fail. Not really. If you can trick the system to _think_ that the intersection between mempolicy and the cpuset is empty then the OOM killer might trigger an innocent task rather than the one which tricked it into that situation. -- Michal Hocko SUSE Labs
[toc] | [prev] | [next] | [standalone]
| From | Christoph Lameter <cl@linux.com> |
|---|---|
| Date | 2017-05-18 19:00 +0200 |
| Message-ID | <tIwWm-5mj-3@gated-at.bofh.it> |
| In reply to | #1643998 |
On Thu, 18 May 2017, Michal Hocko wrote: > > Nope. The OOM in a cpuset gets the process doing the alloc killed. Or what > > that changed? !!!!! > > > > At this point you have messed up royally and nothing is going to rescue > > you anyways. OOM or not does not matter anymore. The app will fail. > > Not really. If you can trick the system to _think_ that the intersection > between mempolicy and the cpuset is empty then the OOM killer might > trigger an innocent task rather than the one which tricked it into that > situation. See above. OOM Kill in a cpuset does not kill an innocent task but a task that does an allocation in that specific context meaning a task in that cpuset that also has a memory policty. Regardless of that the point earlier was that the moving logic can avoid creating temporary situations of empty sets of nodes by analysing the memory policies etc and only performing moves when doing so is safe.
[toc] | [prev] | [next] | [standalone]
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2017-05-18 19:30 +0200 |
| Message-ID | <tIxpo-5Nu-31@gated-at.bofh.it> |
| In reply to | #1644754 |
On Thu 18-05-17 11:57:55, Cristopher Lameter wrote: > On Thu, 18 May 2017, Michal Hocko wrote: > > > > Nope. The OOM in a cpuset gets the process doing the alloc killed. Or what > > > that changed? > > !!!!! > > > > > > > At this point you have messed up royally and nothing is going to rescue > > > you anyways. OOM or not does not matter anymore. The app will fail. > > > > Not really. If you can trick the system to _think_ that the intersection > > between mempolicy and the cpuset is empty then the OOM killer might > > trigger an innocent task rather than the one which tricked it into that > > situation. > > See above. OOM Kill in a cpuset does not kill an innocent task but a task > that does an allocation in that specific context meaning a task in that > cpuset that also has a memory policty. No, the oom killer will chose the largest task in the specific NUMA domain. If you just fail such an allocation then a page fault would get VM_FAULT_OOM and pagefault_out_of_memory would kill a task regardless of the cpusets. > Regardless of that the point earlier was that the moving logic can avoid > creating temporary situations of empty sets of nodes by analysing the > memory policies etc and only performing moves when doing so is safe. How are you going to do that in a raceless way? Moreover the whole discussion is about _failing_ allocations on an empty cpuset and mempolicy intersection. -- Michal Hocko SUSE Labs
[toc] | [prev] | [next] | [standalone]
| From | Christoph Lameter <cl@linux.com> |
|---|---|
| Date | 2017-05-18 21:10 +0200 |
| Message-ID | <tIyYa-6Wp-19@gated-at.bofh.it> |
| In reply to | #1644776 |
On Thu, 18 May 2017, Michal Hocko wrote:
> > See above. OOM Kill in a cpuset does not kill an innocent task but a task
> > that does an allocation in that specific context meaning a task in that
> > cpuset that also has a memory policty.
>
> No, the oom killer will chose the largest task in the specific NUMA
> domain. If you just fail such an allocation then a page fault would get
> VM_FAULT_OOM and pagefault_out_of_memory would kill a task regardless of
> the cpusets.
Ok someone screwed up that code. There still is the determination that we
have a constrained alloc:
oom_kill:
/*
* Check if there were limitations on the allocation (only relevant for
* NUMA and memcg) that may require different handling.
*/
constraint = constrained_alloc(oc);
if (constraint != CONSTRAINT_MEMORY_POLICY)
oc->nodemask = NULL;
check_panic_on_oom(oc, constraint);
-- Ok. A constrained failing alloc used to terminate the allocating
process here. But it falls through to selecting a "bad process"
if (!is_memcg_oom(oc) && sysctl_oom_kill_allocating_task &&
current->mm && !oom_unkillable_task(current, NULL, oc->nodemask) &&
current->signal->oom_score_adj != OOM_SCORE_ADJ_MIN) {
get_task_struct(current);
oc->chosen = current;
oom_kill_process(oc, "Out of memory (oom_kill_allocating_task)");
return true;
}
-- A constrained allocation should not get here but fail the process that
attempts the alloc.
select_bad_process(oc);
Can we restore the old behavior? If I just specify the right memory policy
I can cause other processes to just be terminated?
> > Regardless of that the point earlier was that the moving logic can avoid
> > creating temporary situations of empty sets of nodes by analysing the
> > memory policies etc and only performing moves when doing so is safe.
>
> How are you going to do that in a raceless way? Moreover the whole
> discussion is about _failing_ allocations on an empty cpuset and
> mempolicy intersection.
Again this is only working for processes that are well behaved and it
never worked in a different way before. There was always the assumption
that a process does not allocate in the areas that have allocation
constraints and that the process does not change memory policies nor
store them somewhere for late etc etc. HPC apps typically allocate memory
on startup and then go through long times of processing and I/O.
The idea that cpuset node to node migration will work with a running
process that does abitrary activity is a pipe dream that we should give
up. There must be constraints on a process in order to allow this to work
and as far as I can tell this is best done in userspace with a library and
by putting requirements on the applications that desire to be movable that
way.
F.e. an application that does not use memory policies or other allocation
constraints should be fine. That has been working.
[toc] | [prev] | [next] | [standalone]
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2017-05-19 09:40 +0200 |
| Message-ID | <tIKFX-7ky-9@gated-at.bofh.it> |
| In reply to | #1644844 |
On Thu 18-05-17 14:07:45, Cristopher Lameter wrote: > On Thu, 18 May 2017, Michal Hocko wrote: > > > > See above. OOM Kill in a cpuset does not kill an innocent task but a task > > > that does an allocation in that specific context meaning a task in that > > > cpuset that also has a memory policty. > > > > No, the oom killer will chose the largest task in the specific NUMA > > domain. If you just fail such an allocation then a page fault would get > > VM_FAULT_OOM and pagefault_out_of_memory would kill a task regardless of > > the cpusets. > > Ok someone screwed up that code. There still is the determination that we > have a constrained alloc: It would be much more easier if you read emails more carefully. In order to have a constrained OOM you have to have either a non-null nodemask or zonelist which. And as I've said above you do not have them from the pagefault_out_of_memory context. The whole point of this discussion is _that_ failing allocations will not work currently! > oom_kill: > /* > * Check if there were limitations on the allocation (only relevant for > * NUMA and memcg) that may require different handling. > */ > constraint = constrained_alloc(oc); > if (constraint != CONSTRAINT_MEMORY_POLICY) > oc->nodemask = NULL; > check_panic_on_oom(oc, constraint); > > -- Ok. A constrained failing alloc used to terminate the allocating > process here. But it falls through to selecting a "bad process" This behavior is there for ~10 years. [...] > Can we restore the old behavior? If I just specify the right memory policy > I can cause other processes to just be terminated? Not normally. Because out_of_memory called from the page allocator context makes sure to kill tasks from the same NUMA domain (see oom_unkillable_task). > > > Regardless of that the point earlier was that the moving logic can avoid > > > creating temporary situations of empty sets of nodes by analysing the > > > memory policies etc and only performing moves when doing so is safe. > > > > How are you going to do that in a raceless way? Moreover the whole > > discussion is about _failing_ allocations on an empty cpuset and > > mempolicy intersection. > > Again this is only working for processes that are well behaved and it > never worked in a different way before. There was always the assumption > that a process does not allocate in the areas that have allocation > constraints and that the process does not change memory policies nor > store them somewhere for late etc etc. HPC apps typically allocate memory > on startup and then go through long times of processing and I/O. I would call it a bad design which then triggered a lot of work to make it semi-working over years. This is what Vlastimil tries to address now. And yes that might mean we would have to do some restrictions on the semantics. But as you know this is a user visible API and changing something that has been fundamentally underdefined initially is quite hard to fix. -- Michal Hocko SUSE Labs
[toc] | [prev] | [next] | [standalone]
| From | Vlastimil Babka <vbabka@suse.cz> |
|---|---|
| Date | 2017-05-18 12:10 +0200 |
| Subject | Re: [RFC 1/6] mm, page_alloc: fix more premature OOM due to race with cpuset update |
| Message-ID | <tIqxz-Ng-3@gated-at.bofh.it> |
| In reply to | #1643410 |
On 05/17/2017 04:48 PM, Christoph Lameter wrote: > On Wed, 17 May 2017, Michal Hocko wrote: > >>>> So how are you going to distinguish VM_FAULT_OOM from an empty mempolicy >>>> case in a raceless way? >>> >>> You dont have to do that if you do not create an empty mempolicy in the >>> first place. The current kernel code avoids that by first allowing access >>> to the new set of nodes and removing the old ones from the set when done. >> >> which is racy and as Vlastimil pointed out. If we simply fail such an >> allocation the failure will go up the call chain until we hit the OOM >> killer due to VM_FAULT_OOM. How would you want to handle that? > > The race is where? If you expand the node set during the move of the > application then you are safe in terms of the legacy apps that did not > include static bindings. No, that expand/shrink by itself doesn't work against parallel get_page_from_freelist going through a zonelist. Moving from node 0 to 1, with zonelist containing nodes 1 and 0 in that order: - mempolicy mask is 0 - zonelist iteration checks node 1, it's not allowed, skip - mempolicy mask is 0,1 (expand) - mempolicy mask is 1 (shrink) - zonelist iteration checks node 0, it's not allowed, skip - OOM
[toc] | [prev] | [next] | [standalone]
| From | Christoph Lameter <cl@linux.com> |
|---|---|
| Date | 2017-05-18 19:10 +0200 |
| Message-ID | <tIx62-5FV-17@gated-at.bofh.it> |
| In reply to | #1644034 |
On Thu, 18 May 2017, Vlastimil Babka wrote: > > The race is where? If you expand the node set during the move of the > > application then you are safe in terms of the legacy apps that did not > > include static bindings. > > No, that expand/shrink by itself doesn't work against parallel Parallel? I think we are clear that ithis is inherently racy against the app changing policies etc etc? There is a huge issue there already. The app needs to be well behaved in some heretofore undefined way in order to make moves clean. > get_page_from_freelist going through a zonelist. Moving from node 0 to > 1, with zonelist containing nodes 1 and 0 in that order: > > - mempolicy mask is 0 > - zonelist iteration checks node 1, it's not allowed, skip There is an allocation from node 1? This is not allowed before the move. So it should fail. Not skipping to another node. > - mempolicy mask is 0,1 (expand) > - mempolicy mask is 1 (shrink) > - zonelist iteration checks node 0, it's not allowed, skip > - OOM Are you talking about a race here between zonelist scanning and the moving? That has been there forever. And frankly there are gazillions of these races. The best thing to do is to get the cpuset moving logic out of the kernel and into user space. Understand that this is a heuristic and maybe come up with a list of restrictions that make an app safe. An safe app that can be moved must f.e 1. Not allocate new memory while its being moved 2. Not change memory policies after its initialization and while its being moved. 3. Not save memory policy state in some variable (because the logic to translate the memory policies for the new context cannot find it). ... Again cpuset process migration is a huge mess that you do not want to have in the kernel and AFAICT this is a corner case with difficult semantics. Better have that in user space...
[toc] | [prev] | [next] | [standalone]
| From | Vlastimil Babka <vbabka@suse.cz> |
|---|---|
| Date | 2017-05-19 13:30 +0200 |
| Subject | Re: [RFC 1/6] mm, page_alloc: fix more premature OOM due to race with cpuset update |
| Message-ID | <tIOgy-1r7-7@gated-at.bofh.it> |
| In reply to | #1644763 |
On 05/18/2017 07:07 PM, Christoph Lameter wrote: > On Thu, 18 May 2017, Vlastimil Babka wrote: > >>> The race is where? If you expand the node set during the move of the >>> application then you are safe in terms of the legacy apps that did not >>> include static bindings. >> >> No, that expand/shrink by itself doesn't work against parallel > > Parallel? I think we are clear that ithis is inherently racy against the > app changing policies etc etc? There is a huge issue there already. The > app needs to be well behaved in some heretofore undefined way in order to > make moves clean. The code is safe against mbind() changing a vma's mempolicy parallel to another thread page faulting within that vma, because mbind() takes mmap_sem for write, and page faults take it for read. The per-task mempolicy can be changed by set_mempolicy() call which means the task itself doesn't allocate stuff in parallel. So, the application never needed to be "well behaved" wrt changing its own mempolicies. Now with mempolicy rebinding due to cpuset migrations, the application cannot be "well behaved" as it has no way to learn about being under a cpuset, or cpuset change. Any application can be put in a cpuset and we can't really expect that all would be adapted, even if the necessary interfaces existed. Thus, the rebinding implementation in the kernel itself has to be robust against parallel allocations. >> get_page_from_freelist going through a zonelist. Moving from node 0 to >> 1, with zonelist containing nodes 1 and 0 in that order: >> >> - mempolicy mask is 0 >> - zonelist iteration checks node 1, it's not allowed, skip > > There is an allocation from node 1? Sorry, I missed to mention the full scenario. Let's say the allocation is on cpu local to node 1, so it gets zonelist from node 1, which contains nodes 1 and 0 in that order. > This is not allowed before the move. > So it should fail. Not skipping to another node. > >> - mempolicy mask is 0,1 (expand) >> - mempolicy mask is 1 (shrink) >> - zonelist iteration checks node 0, it's not allowed, skip >> - OOM > > Are you talking about a race here between zonelist scanning and the > moving? That has been there forever. As far as I can tell from my git archeology in [1] there was always some kind of protection against the race (generation counters, two-step protocol, seqlock...), which however had some corner cases. This patch is merely plugging the last known one. > And frankly there are gazillions of these races. I don't know about any other existing race that we don't handle after this patch. > The best thing to do is > to get the cpuset moving logic out of the kernel and into user space. > > Understand that this is a heuristic and maybe come up with a list of > restrictions that make an app safe. An safe app that can be moved must f.e > > 1. Not allocate new memory while its being moved > 2. Not change memory policies after its initialization and while its being > moved. As I explainer eariler in this mail, changing mempolicy by app itself is safe, the problem was always due to cpuset-triggered rebinding. > 3. Not save memory policy state in some variable (because the logic to > translate the memory policies for the new context cannot find it). > > ... > > Again cpuset process migration is a huge mess that you do not want to > have in the kernel and AFAICT this is a corner case with difficult > semantics. Better have that in user space... Moving this out of kernel etc is changing the current semantics and breaking existing userspace, this patch is a fix within the existing one. [1] https://marc.info/?l=linux-mm&m=148611344511408&w=2 > -- > 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] | [standalone]
Back to top | Article view | linux.kernel
csiph-web