lkml.org 
[lkml]   [2023]   [Mar]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH v4 03/36] mm: Add folio_flush_mapping()
    Date
    This is the folio equivalent of page_mapping_file(), but rename it
    to make it clear that it's very different from page_file_mapping().
    Theoretically, there's nothing flush-only about it, but there are no
    other users today, and I doubt there will be; it's almost always more
    useful to know the swapfile's mapping or the swapcache's mapping.

    Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
    ---
    include/linux/pagemap.h | 26 +++++++++++++++++++++-----
    1 file changed, 21 insertions(+), 5 deletions(-)

    diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
    index a56308a9d1a4..e56c2023aa0e 100644
    --- a/include/linux/pagemap.h
    +++ b/include/linux/pagemap.h
    @@ -369,6 +369,26 @@ static inline struct address_space *folio_file_mapping(struct folio *folio)
    return folio->mapping;
    }

    +/**
    + * folio_flush_mapping - Find the file mapping this folio belongs to.
    + * @folio: The folio.
    + *
    + * For folios which are in the page cache, return the mapping that this
    + * page belongs to. Anonymous folios return NULL, even if they're in
    + * the swap cache. Other kinds of folio also return NULL.
    + *
    + * This is ONLY used by architecture cache flushing code. If you aren't
    + * writing cache flushing code, you want either folio_mapping() or
    + * folio_file_mapping().
    + */
    +static inline struct address_space *folio_flush_mapping(struct folio *folio)
    +{
    + if (unlikely(folio_test_swapcache(folio)))
    + return NULL;
    +
    + return folio_mapping(folio);
    +}
    +
    static inline struct address_space *page_file_mapping(struct page *page)
    {
    return folio_file_mapping(page_folio(page));
    @@ -379,11 +399,7 @@ static inline struct address_space *page_file_mapping(struct page *page)
    */
    static inline struct address_space *page_mapping_file(struct page *page)
    {
    - struct folio *folio = page_folio(page);
    -
    - if (unlikely(folio_test_swapcache(folio)))
    - return NULL;
    - return folio_mapping(folio);
    + return folio_flush_mapping(page_folio(page));
    }

    /**
    --
    2.39.2
    \
     
     \ /
      Last update: 2023-03-27 01:00    [W:4.751 / U:0.020 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site