Thread (17 messages) 17 messages, 4 authors, 2022-11-22

Re: [External] Re: [PATCH v2] mm: add new syscall pidfd_set_mempolicy().

From: Michal Hocko <mhocko@suse.com>
Date: 2022-11-14 18:13:43
Also in: linux-doc, linux-mm, lkml

On Mon 14-11-22 23:12:00, Zhongkun He wrote:
Sorry,michal. I dont know if my expression is accurate.
quoted
We shouldn't really rely on mmap_sem for this IMO.
 Yes, We should rely on mmap_sem for vma->vm_policy,but not for
 process context policy(task->mempolicy).
But the caller has no way to know which kind of policy is returned so
the locking cannot be conditional on the policy type.
quoted
There is alloc_lock
(aka task lock) that makes sure the policy is stable so that caller can
atomically take a reference and hold on the policy. And we do not do
that consistently and this should be fixed.
I saw some explanations in the doc("numa_memory_policy.rst") and
comments(mempolcy.h) why not use locks and reference in page
allocation:

In process context there is no locking because only the process accesses
its own state.

During run-time "usage" of the policy, we attempt to minimize atomic
operations on the reference count, as this can lead to cache lines
bouncing between cpus and NUMA nodes.
Yes this is all understood but the level of the overhead is not really
clear. So the question is whether this will induce a visible overhead.
Because from the maintainability point of view it is much less costly to
have a clear life time model. Right now we have a mix of reference
counting and per-task requirements which is rather subtle and easy to
get wrong. In an ideal world we would have get_vma_policy always
returning a reference counted policy or NULL. If we really need to
optimize for cache line bouncing we can go with per cpu reference
counters (something that was not available at the time the mempolicy
code has been introduced).

So I am not saying that the task_work based solution is not possible I
just think that this looks like a good opportunity to get from the
existing subtle model.
-- 
Michal Hocko
SUSE Labs
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help