Skip to content

Commit 8644772

Browse files
Alexander Duyckdavem330
authored andcommitted
mm: Use fixed constant in page_frag_alloc instead of size + 1
This patch replaces the size + 1 value introduced with the recent fix for 1 byte allocs with a constant value. The idea here is to reduce code overhead as the previous logic would have to read size into a register, then increment it, and write it back to whatever field was being used. By using a constant we can avoid those memory reads and arithmetic operations in favor of just encoding the maximum value into the operation itself. Fixes: 2c2ade8 ("mm: page_alloc: fix ref bias in page_frag_alloc() for 1-byte allocs") Signed-off-by: Alexander Duyck <alexander.h.duyck@linux.intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e09c6a4 commit 8644772

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

mm/page_alloc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4675,11 +4675,11 @@ void *page_frag_alloc(struct page_frag_cache *nc,
46754675
/* Even if we own the page, we do not use atomic_set().
46764676
* This would break get_page_unless_zero() users.
46774677
*/
4678-
page_ref_add(page, size);
4678+
page_ref_add(page, PAGE_FRAG_CACHE_MAX_SIZE);
46794679

46804680
/* reset page count bias and offset to start of new frag */
46814681
nc->pfmemalloc = page_is_pfmemalloc(page);
4682-
nc->pagecnt_bias = size + 1;
4682+
nc->pagecnt_bias = PAGE_FRAG_CACHE_MAX_SIZE + 1;
46834683
nc->offset = size;
46844684
}
46854685

@@ -4695,10 +4695,10 @@ void *page_frag_alloc(struct page_frag_cache *nc,
46954695
size = nc->size;
46964696
#endif
46974697
/* OK, page count is 0, we can safely set it */
4698-
set_page_count(page, size + 1);
4698+
set_page_count(page, PAGE_FRAG_CACHE_MAX_SIZE + 1);
46994699

47004700
/* reset page count bias and offset to start of new frag */
4701-
nc->pagecnt_bias = size + 1;
4701+
nc->pagecnt_bias = PAGE_FRAG_CACHE_MAX_SIZE + 1;
47024702
offset = size - fragsz;
47034703
}
47044704

0 commit comments

Comments
 (0)