linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Huang Ying <ying.huang@intel.com>, linux-mm@kvack.org
Subject: page_mapping vs page_file_mapping for swap cache pages
Date: Thu, 18 Mar 2021 21:01:47 +0000	[thread overview]
Message-ID: <20210318210147.GV3420@casper.infradead.org> (raw)

If we call page_mapping(page) and PageSwapCache is true, we do this:

        if (unlikely(PageSwapCache(page))) {
                swp_entry_t entry;

                entry.val = page_private(page);
                return swap_address_space(entry);
        }

#define swap_address_space(entry)                           \
        (&swapper_spaces[swp_type(entry)][swp_offset(entry) \
                >> SWAP_ADDRESS_SPACE_SHIFT])

(i think we could make that more readable by adding
#define swp_as(entry)	(swp_offset(entry) >> SWAP_ADDRESS_SPACE_SHIFT)
but i digress)

If, instead, we call page_file_mapping(page) and PageSwapCache is true,
we do this:

        return page_swap_info(page)->swap_file->f_mapping;

struct swap_info_struct *page_swap_info(struct page *page)
{
        swp_entry_t entry = { .val = page_private(page) };
        return swp_swap_info(entry);
}

struct swap_info_struct *swp_swap_info(swp_entry_t entry)
{
        return swap_type_to_swap_info(swp_type(entry));
}

static struct swap_info_struct *swap_type_to_swap_info(int type)
{
        if (type >= READ_ONCE(nr_swapfiles))
                return NULL;

        smp_rmb();      /* Pairs with smp_wmb in alloc_swap_info. */
        return READ_ONCE(swap_info[type]);
}

So ... are these different address spaces from each other?  If not,
why do we have such a complicated way of finding the address space
for page_file_mapping()?


             reply	other threads:[~2021-03-18 21:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-18 21:01 Matthew Wilcox [this message]
2021-03-19  6:24 ` Huang, Ying

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210318210147.GV3420@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=ying.huang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox