Re: mm/rmap.c: anon_vma

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Rodrigo Baroni wrote:
Hi all.

 Does anybody knows why this instruction ? - in mm/rmap.c:

anon_vma = (struct anon_vma *) (anon_mapping - PAGE_MAPPING_ANON);

This is because the mapping pointer is normally word aligned,
but is "marked" with PAGE_MAPPING_ANON, simply by adding this
amount to the pointer.

static struct anon_vma *page_lock_anon_vma(struct page *page)
{
    struct anon_vma *anon_vma = NULL;
    unsigned long anon_mapping;

    rcu_read_lock();
    anon_mapping = (unsigned long) page->mapping;
    if (!(anon_mapping & PAGE_MAPPING_ANON))
        goto out;

Which means that we can recognize whether a pointer is pointing
to an anon_vma or an address_space by looking at the last bit
of the pointer.

A struct is always 32 bit aligned on a 32 bit architecture
(unless packed), so this dirty trick works.

    if (!page_mapped(page))
        goto out;

    anon_vma = (struct anon_vma *) (anon_mapping - PAGE_MAPPING_ANON);
    spin_lock(&anon_vma->lock);

However, to find the real pointer to the anon_vma, we have to
substract the magic marker again.

--
What is important?  What you want to be true, or what is true?

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux