lkml.org 
[lkml]   [2021]   [Jan]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH v2 09/27] mm: Add folio_index, folio_page and folio_contains
    Date
    folio_index() is the equivalent of page_index() for folios.  folio_page()
    finds the page in a folio for a page cache index. folio_contains()
    tells you whether a folio contains a particular page cache index.

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

    diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
    index a739ada01d27..c27b74c63b5e 100644
    --- a/include/linux/pagemap.h
    +++ b/include/linux/pagemap.h
    @@ -447,6 +447,29 @@ static inline bool thp_contains(struct page *head, pgoff_t index)
    return page_index(head) == (index & ~(thp_nr_pages(head) - 1UL));
    }

    +static inline pgoff_t folio_index(struct folio *folio)
    +{
    + if (unlikely(FolioSwapCache(folio)))
    + return __page_file_index(&folio->page);
    + return folio->page.index;
    +}
    +
    +static inline struct page *folio_page(struct folio *folio, pgoff_t index)
    +{
    + index -= folio_index(folio);
    + VM_BUG_ON_FOLIO(index >= folio_nr_pages(folio), folio);
    + return &folio->page + index;
    +}
    +
    +/* Does this folio contain this index? */
    +static inline bool folio_contains(struct folio *folio, pgoff_t index)
    +{
    + /* HugeTLBfs indexes the page cache in units of hpage_size */
    + if (PageHuge(&folio->page))
    + return folio->page.index == index;
    + return index - folio_index(folio) < folio_nr_pages(folio);
    +}
    +
    /*
    * Given the page we found in the page cache, return the page corresponding
    * to this index in the file
    --
    2.29.2
    \
     
     \ /
      Last update: 2021-01-18 18:26    [W:2.845 / U:0.012 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site