2022-04-22 07:11:23

by Matthew Wilcox

[permalink] [raw]
Subject: Re: [RFC 1/3] mm: change vma_is_anonymous to vma_is_private_anon

On Thu, Apr 21, 2022 at 03:05:31PM -0400, Nico Pache wrote:
> The vma_is_anonymous function isn't fully indicative of what it checks.
>
> Without having full knowledge of the mmap process, one may incorrectly
> assume this covers all types of anonymous memory; which is not the case.

Is your complaint that anonymous memory can also be found in file VMAs
that were mapped with MAP_PRIVATE? ie COWed pages?

I don't think renaming this function is appropriate. It's whether
the VMA is anonymous, not whether the VMA can contain anonymous
pages.


2022-04-22 22:12:16

by Nico Pache

[permalink] [raw]
Subject: Re: [RFC 1/3] mm: change vma_is_anonymous to vma_is_private_anon



On 4/21/22 15:28, Matthew Wilcox wrote:
> On Thu, Apr 21, 2022 at 03:05:31PM -0400, Nico Pache wrote:
>> The vma_is_anonymous function isn't fully indicative of what it checks.
>>
>> Without having full knowledge of the mmap process, one may incorrectly
>> assume this covers all types of anonymous memory; which is not the case.
>
> Is your complaint that anonymous memory can also be found in file VMAs
> that were mapped with MAP_PRIVATE? ie COWed pages?
I should have been more descriptive in my commit msg about how I came to this
conclusion.

From my understanding of the mmap process, a vma->vm_ops field is only NULL when
mmapped as !file and !shared:

if (file){
...
} else if (vm_flags & VM_SHARED) { //ANON SHARED
error = shmem_zero_setup(vma);
if (error)
goto free_vma;
} else { //ANON PRIVATE
vma_set_anonymous(vma); //set vma->vm_ops= NULL
}

To me this means that the VMA is PRIVATE ANON memory. The vma_is_anonymous
function returns true when vm_ops == NULL. So my intentions were to more
accurately describe what we are checking for. I could be wrong though thats why
I started with an RFC :)

There could be some aspect of COW that I dont fully understand. It is not
something I've looked into much.

Cheers,
-- Nico

2022-04-29 16:07:38

by David Hildenbrand

[permalink] [raw]
Subject: Re: [RFC 1/3] mm: change vma_is_anonymous to vma_is_private_anon

On 22.04.22 16:00, Nico Pache wrote:
>
>
> On 4/21/22 15:28, Matthew Wilcox wrote:
>> On Thu, Apr 21, 2022 at 03:05:31PM -0400, Nico Pache wrote:
>>> The vma_is_anonymous function isn't fully indicative of what it checks.
>>>
>>> Without having full knowledge of the mmap process, one may incorrectly
>>> assume this covers all types of anonymous memory; which is not the case.
>>
>> Is your complaint that anonymous memory can also be found in file VMAs
>> that were mapped with MAP_PRIVATE? ie COWed pages?
> I should have been more descriptive in my commit msg about how I came to this
> conclusion.
>
> From my understanding of the mmap process, a vma->vm_ops field is only NULL when
> mmapped as !file and !shared:
>
> if (file){
> ...
> } else if (vm_flags & VM_SHARED) { //ANON SHARED
> error = shmem_zero_setup(vma);
> if (error)
> goto free_vma;
> } else { //ANON PRIVATE
> vma_set_anonymous(vma); //set vma->vm_ops= NULL
> }
>
> To me this means that the VMA is PRIVATE ANON memory. The vma_is_anonymous
> function returns true when vm_ops == NULL. So my intentions were to more
> accurately describe what we are checking for. I could be wrong though thats why
> I started with an RFC :)

Shared anon in the kernel is really just shmem. The user space notion
is MAP_ANON|MAP_SHARED, but that really just maps to shmem and the
kernel doesn't really call that thing anonymous memory.

So I agree, renaming this is not appropriate.

--
Thanks,

David / dhildenb