On Thu, Jan 26, 2023 at 9:27 AM Mel Gorman <mgorman@xxxxxxxxxxxxxxxxxxx> wrote: > > On Thu, Jan 26, 2023 at 08:10:26AM -0800, Suren Baghdasaryan wrote: > > On Thu, Jan 26, 2023 at 7:10 AM Mel Gorman <mgorman@xxxxxxxxxxxxxxxxxxx> wrote: > > > > > > On Wed, Jan 25, 2023 at 03:35:51PM -0800, Suren Baghdasaryan wrote: > > > > Replace direct modifications to vma->vm_flags with calls to modifier > > > > functions to be able to track flag changes and to keep vma locking > > > > correctness. > > > > > > > > Signed-off-by: Suren Baghdasaryan <surenb@xxxxxxxxxx> > > > > Acked-by: Michal Hocko <mhocko@xxxxxxxx> > > > > > > Acked-by: Mel Gorman <mgorman@xxxxxxxxxxxxxxxxxxx> > > > > > > Minor comments that are safe to ignore. > > > > > > I think a better name for mod_vm_flags is set_clear_vm_flags to hint that > > > the first flags are to be set and the second flags are to be cleared. > > > For this patch, it doesn't matter, but it might avoid accidental swapping > > > in the future. > > > > > > reset_vm_flags might also be better named as reinit_vma_flags (or > > > vma_flags_reinit). Maybe also encourage the use of [set|clear_mod]_vm_flags > > > where possible in the comment to track exactly what is changing and > > > why. Some cases like userfaultfd just want to clear __VM_UFFD_FLAGS but > > > altering the flow in this patch is inappropriate and error prone. Others > > > such as the infiniband changes and madvise are a lot more complex. > > > > That's a good point, but I don't want people to use mod_vm_flags() for > > the cases when the order of set/clear really matters. In such cases > > set_vm_flags() and clear_vm_flags() should be explicitly used. Maybe > > to make that clear I should add a comment and rewrite the functions > > as: > > > > void mod_vm_flags(vma, set, clear) { > > vma.vm_flags = vma.vm_flags | set & clear; > > } > > > > Offhand, I'm not thinking of a case where that really matters and as they > are not necessarily ordered, it's raising a read flag so yes, it definitely > it needs a comment if the ordering matters. > > > In this patchset it's not that obvious but mod_vm_flags() was really > > introduced in the original per-VMA lock patchset for efficiency to > > avoid taking extra per-VMA locks. A combo of > > set_vm_flags()+clear_vm_flags() would try to retake the same per-VMA > > lock in the second call while mod_vm_flags() takes the lock only once > > and does both operations. > > Ok, that seems fair but still needs a comment on why a mod_vm_flags is > not necessarily equivalent to a set_vm_flags + clear_vm_flags in terms of > correctness if that is indeed the case. > > > Not a huge overhead because we check if the > > lock is already taken and bail out early but still... > > So, would the above modification to mod_vm_flags() address your concern? > > > > My concerns are entirely with the callers, not the implementation. If > someone is modifying a call site using mod_vm_flags, they have to read > through all the preceding logic to ensure the final combination of flags > is valid. It's a code maintenance issue, not a correctness issue. Got it. I'll modify the implementation to make a single assignment and will add a comment to use only when order doesn't matter. Thanks! > > -- > Mel Gorman > SUSE Labs