Skip to content

Commit

Permalink
mm/rmap: calculate page offset when needed
Browse files Browse the repository at this point in the history
Call page_to_pgoff() to get the page offset once we are sure we actually
need it, and any very obvious initial function checks have passed.
Trivial micro-optimization, and potentially save some cycles.

Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Davidlohr Bueso authored and Linus Torvalds committed Dec 13, 2014
1 parent 2847cf9 commit b258d86
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mm/rmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1635,14 +1635,15 @@ static struct anon_vma *rmap_walk_anon_lock(struct page *page,
static int rmap_walk_anon(struct page *page, struct rmap_walk_control *rwc)
{
struct anon_vma *anon_vma;
pgoff_t pgoff = page_to_pgoff(page);
pgoff_t pgoff;
struct anon_vma_chain *avc;
int ret = SWAP_AGAIN;

anon_vma = rmap_walk_anon_lock(page, rwc);
if (!anon_vma)
return ret;

pgoff = page_to_pgoff(page);
anon_vma_interval_tree_foreach(avc, &anon_vma->rb_root, pgoff, pgoff) {
struct vm_area_struct *vma = avc->vma;
unsigned long address = vma_address(page, vma);
Expand Down Expand Up @@ -1676,7 +1677,7 @@ static int rmap_walk_anon(struct page *page, struct rmap_walk_control *rwc)
static int rmap_walk_file(struct page *page, struct rmap_walk_control *rwc)
{
struct address_space *mapping = page->mapping;
pgoff_t pgoff = page_to_pgoff(page);
pgoff_t pgoff;
struct vm_area_struct *vma;
int ret = SWAP_AGAIN;

Expand All @@ -1691,6 +1692,7 @@ static int rmap_walk_file(struct page *page, struct rmap_walk_control *rwc)
if (!mapping)
return ret;

pgoff = page_to_pgoff(page);
i_mmap_lock_read(mapping);
vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff) {
unsigned long address = vma_address(page, vma);
Expand Down

0 comments on commit b258d86

Please sign in to comment.