mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-30 21:39:35 -04:00
mm: introduce and use linear_page_delta()
It's often useful to obtain the number of pages a given address lies at within a VMA. Add linear_page_delta() to determine this and update linear_page_index() to make use of it. Add comments to describe both linear_page_delta() and linear_page_index(). We refer the reader to the comment for vma_start_pgoff() so we don't duplicate information about the meaning of a VMA's page offset, which is also less likely to result in bitrot. No functional change intended. Link: https://lore.kernel.org/20260710-b4-pre-scalable-cow-v2-17-2a5aa403d977@kernel.org Signed-off-by: Lorenzo Stoakes <ljs@kernel.org> Reviewed-by: Ackerley Tng <ackerleytng@google.com> Reviewed-by: Gregory Price <gourry@gourry.net> Reviewed-by: Pedro Falcato <pfalcato@suse.de> Reviewed-by: Vlastimil Babka (SUSE) <vbabka@kernel.org> Cc: David Hildenbrand (Arm) <david@kernel.org> Cc: Kai Huang <kai.huang@intel.com> Cc: Marek Szyprowski <m.szyprowski@samsung.com> Cc: SJ Park <sj@kernel.org> Cc: Thomas Zimmermann <tzimmermann@suse.de> Cc: Liam R. Howlett (Oracle) <liam@infradead.org> Cc: Zi Yan <ziy@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
committed by
Andrew Morton
parent
68d307442b
commit
1268e1572b
@@ -1063,11 +1063,40 @@ static inline pgoff_t folio_pgoff(const struct folio *folio)
|
||||
return folio->index;
|
||||
}
|
||||
|
||||
/**
|
||||
* linear_page_delta() - Determine the relative page offset of @address within
|
||||
* @vma.
|
||||
* @vma: The VMA in which @address resides.
|
||||
* @address: The address whose relative page offset is required.
|
||||
*
|
||||
* The result is identical for both file-backed and anonymous mappings and
|
||||
* simply determines how many pages @address lies from @vma->vm_start.
|
||||
*
|
||||
* Returns: The number of pages @address is offset by within @vma.
|
||||
*/
|
||||
static inline pgoff_t linear_page_delta(const struct vm_area_struct *vma,
|
||||
const unsigned long address)
|
||||
{
|
||||
return (address - vma->vm_start) >> PAGE_SHIFT;
|
||||
}
|
||||
|
||||
/**
|
||||
* linear_page_index() - Determine the absolute page offset of @address within
|
||||
* @vma.
|
||||
* @vma: The VMA in which @address resides.
|
||||
* @address: The address whose absolute page offset is required.
|
||||
*
|
||||
* See the comment for vma_start_pgoff() for a description of what the page
|
||||
* offset signifies.
|
||||
*
|
||||
* Returns: The absolute page offset of @address within @vma.
|
||||
*/
|
||||
static inline pgoff_t linear_page_index(const struct vm_area_struct *vma,
|
||||
const unsigned long address)
|
||||
{
|
||||
pgoff_t pgoff;
|
||||
pgoff = (address - vma->vm_start) >> PAGE_SHIFT;
|
||||
|
||||
pgoff = linear_page_delta(vma, address);
|
||||
pgoff += vma->vm_pgoff;
|
||||
return pgoff;
|
||||
}
|
||||
@@ -1219,7 +1248,7 @@ static inline vm_fault_t folio_lock_or_retry(struct folio *folio,
|
||||
void folio_wait_bit(struct folio *folio, int bit_nr);
|
||||
int folio_wait_bit_killable(struct folio *folio, int bit_nr);
|
||||
|
||||
/*
|
||||
/*
|
||||
* Wait for a folio to be unlocked.
|
||||
*
|
||||
* This must be called with the caller "holding" the folio,
|
||||
|
||||
Reference in New Issue
Block a user