Skip to content

Commit 0139aa7

Browse files
JoonsooKimtorvalds
authored andcommitted
mm: rename _count, field of the struct page, to _refcount
Many developers already know that field for reference count of the struct page is _count and atomic type. They would try to handle it directly and this could break the purpose of page reference count tracepoint. To prevent direct _count modification, this patch rename it to _refcount and add warning message on the code. After that, developer who need to handle reference count will find that field should not be accessed directly. [akpm@linux-foundation.org: fix comments, per Vlastimil] [akpm@linux-foundation.org: Documentation/vm/transhuge.txt too] [sfr@canb.auug.org.au: sync ethernet driver changes] Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com> Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Hugh Dickins <hughd@google.com> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: "David S. Miller" <davem@davemloft.net> Cc: Sunil Goutham <sgoutham@cavium.com> Cc: Chris Metcalf <cmetcalf@mellanox.com> Cc: Manish Chopra <manish.chopra@qlogic.com> Cc: Yuval Mintz <yuval.mintz@qlogic.com> Cc: Tariq Toukan <tariqt@mellanox.com> Cc: Saeed Mahameed <saeedm@mellanox.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 6d061f9 commit 0139aa7

17 files changed

Lines changed: 58 additions & 54 deletions

File tree

‎Documentation/vm/transhuge.txt‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,9 @@ hugepage natively. Once finished you can drop the page table lock.
394394
Refcounting on THP is mostly consistent with refcounting on other compound
395395
pages:
396396

397-
- get_page()/put_page() and GUP operate in head page's ->_count.
397+
- get_page()/put_page() and GUP operate in head page's ->_refcount.
398398

399-
- ->_count in tail pages is always zero: get_page_unless_zero() never
399+
- ->_refcount in tail pages is always zero: get_page_unless_zero() never
400400
succeed on tail pages.
401401

402402
- map/unmap of the pages with PTE entry increment/decrement ->_mapcount
@@ -426,15 +426,15 @@ requests to split pinned huge page: it expects page count to be equal to
426426
sum of mapcount of all sub-pages plus one (split_huge_page caller must
427427
have reference for head page).
428428

429-
split_huge_page uses migration entries to stabilize page->_count and
429+
split_huge_page uses migration entries to stabilize page->_refcount and
430430
page->_mapcount.
431431

432432
We safe against physical memory scanners too: the only legitimate way
433433
scanner can get reference to a page is get_page_unless_zero().
434434

435-
All tail pages has zero ->_count until atomic_add(). It prevent scanner
435+
All tail pages has zero ->_refcount until atomic_add(). It prevent scanner
436436
from geting reference to tail page up to the point. After the atomic_add()
437-
we don't care about ->_count value. We already known how many references
437+
we don't care about ->_refcount value. We already known how many references
438438
with should uncharge from head page.
439439

440440
For head page get_page_unless_zero() will succeed and we don't mind. It's

‎arch/tile/mm/init.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ static void __init init_free_pfn_range(unsigned long start, unsigned long end)
679679
* Hacky direct set to avoid unnecessary
680680
* lock take/release for EVERY page here.
681681
*/
682-
p->_count.counter = 0;
682+
p->_refcount.counter = 0;
683683
p->_mapcount.counter = -1;
684684
}
685685
init_page_count(page);

‎drivers/block/aoe/aoecmd.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ rqbiocnt(struct request *r)
861861
* discussion.
862862
*
863863
* We cannot use get_page in the workaround, because it insists on a
864-
* positive page count as a precondition. So we use _count directly.
864+
* positive page count as a precondition. So we use _refcount directly.
865865
*/
866866
static void
867867
bio_pageinc(struct bio *bio)

‎drivers/hwtracing/intel_th/msu.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,7 @@ static void msc_mmap_close(struct vm_area_struct *vma)
11641164
if (!atomic_dec_and_mutex_lock(&msc->mmap_count, &msc->buf_mutex))
11651165
return;
11661166

1167-
/* drop page _counts */
1167+
/* drop page _refcounts */
11681168
for (pg = 0; pg < msc->nr_pages; pg++) {
11691169
struct page *page = msc_buffer_get_page(msc, pg);
11701170

‎drivers/net/ethernet/mellanox/mlx5/core/en_rx.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ static int mlx5e_alloc_rx_fragmented_mpwqe(struct mlx5e_rq *rq,
433433
for (i = 0; i < MLX5_MPWRQ_PAGES_PER_WQE; i++) {
434434
if (unlikely(mlx5e_alloc_and_map_page(rq, wi, i)))
435435
goto err_unmap;
436-
atomic_add(mlx5e_mpwqe_strides_per_page(rq),
437-
&wi->umr.dma_info[i].page->_count);
436+
page_ref_add(wi->umr.dma_info[i].page,
437+
mlx5e_mpwqe_strides_per_page(rq));
438438
wi->skbs_frags[i] = 0;
439439
}
440440

@@ -452,8 +452,8 @@ static int mlx5e_alloc_rx_fragmented_mpwqe(struct mlx5e_rq *rq,
452452
while (--i >= 0) {
453453
dma_unmap_page(rq->pdev, wi->umr.dma_info[i].addr, PAGE_SIZE,
454454
PCI_DMA_FROMDEVICE);
455-
atomic_sub(mlx5e_mpwqe_strides_per_page(rq),
456-
&wi->umr.dma_info[i].page->_count);
455+
page_ref_sub(wi->umr.dma_info[i].page,
456+
mlx5e_mpwqe_strides_per_page(rq));
457457
put_page(wi->umr.dma_info[i].page);
458458
}
459459
dma_unmap_single(rq->pdev, wi->umr.mtt_addr, mtt_sz, PCI_DMA_TODEVICE);
@@ -477,8 +477,8 @@ void mlx5e_free_rx_fragmented_mpwqe(struct mlx5e_rq *rq,
477477
for (i = 0; i < MLX5_MPWRQ_PAGES_PER_WQE; i++) {
478478
dma_unmap_page(rq->pdev, wi->umr.dma_info[i].addr, PAGE_SIZE,
479479
PCI_DMA_FROMDEVICE);
480-
atomic_sub(mlx5e_mpwqe_strides_per_page(rq) - wi->skbs_frags[i],
481-
&wi->umr.dma_info[i].page->_count);
480+
page_ref_sub(wi->umr.dma_info[i].page,
481+
mlx5e_mpwqe_strides_per_page(rq) - wi->skbs_frags[i]);
482482
put_page(wi->umr.dma_info[i].page);
483483
}
484484
dma_unmap_single(rq->pdev, wi->umr.mtt_addr, mtt_sz, PCI_DMA_TODEVICE);
@@ -527,8 +527,8 @@ static int mlx5e_alloc_rx_linear_mpwqe(struct mlx5e_rq *rq,
527527
*/
528528
split_page(wi->dma_info.page, MLX5_MPWRQ_WQE_PAGE_ORDER);
529529
for (i = 0; i < MLX5_MPWRQ_PAGES_PER_WQE; i++) {
530-
atomic_add(mlx5e_mpwqe_strides_per_page(rq),
531-
&wi->dma_info.page[i]._count);
530+
page_ref_add(&wi->dma_info.page[i],
531+
mlx5e_mpwqe_strides_per_page(rq));
532532
wi->skbs_frags[i] = 0;
533533
}
534534

@@ -551,8 +551,8 @@ void mlx5e_free_rx_linear_mpwqe(struct mlx5e_rq *rq,
551551
dma_unmap_page(rq->pdev, wi->dma_info.addr, rq->wqe_sz,
552552
PCI_DMA_FROMDEVICE);
553553
for (i = 0; i < MLX5_MPWRQ_PAGES_PER_WQE; i++) {
554-
atomic_sub(mlx5e_mpwqe_strides_per_page(rq) - wi->skbs_frags[i],
555-
&wi->dma_info.page[i]._count);
554+
page_ref_sub(&wi->dma_info.page[i],
555+
mlx5e_mpwqe_strides_per_page(rq) - wi->skbs_frags[i]);
556556
put_page(&wi->dma_info.page[i]);
557557
}
558558
}

‎drivers/net/ethernet/qlogic/qede/qede_main.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ static int qede_fill_frag_skb(struct qede_dev *edev,
10361036
/* Incr page ref count to reuse on allocation failure
10371037
* so that it doesn't get freed while freeing SKB.
10381038
*/
1039-
atomic_inc(&current_bd->data->_count);
1039+
page_ref_inc(current_bd->data);
10401040
goto out;
10411041
}
10421042

@@ -1487,7 +1487,7 @@ static int qede_rx_int(struct qede_fastpath *fp, int budget)
14871487
* freeing SKB.
14881488
*/
14891489

1490-
atomic_inc(&sw_rx_data->data->_count);
1490+
page_ref_inc(sw_rx_data->data);
14911491
rxq->rx_alloc_errors++;
14921492
qede_recycle_rx_bd_ring(rxq, edev,
14931493
fp_cqe->bd_num);

‎fs/proc/page.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ u64 stable_page_flags(struct page *page)
142142

143143

144144
/*
145-
* Caveats on high order pages: page->_count will only be set
145+
* Caveats on high order pages: page->_refcount will only be set
146146
* -1 on the head page; SLUB/SLQB do the same for PG_slab;
147147
* SLOB won't set PG_slab at all on compound pages.
148148
*/

‎include/linux/mm.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ static inline void get_page(struct page *page)
734734
page = compound_head(page);
735735
/*
736736
* Getting a normal page or the head of a compound page
737-
* requires to already have an elevated page->_count.
737+
* requires to already have an elevated page->_refcount.
738738
*/
739739
VM_BUG_ON_PAGE(page_ref_count(page) <= 0, page);
740740
page_ref_inc(page);

‎include/linux/mm_types.h‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ struct page {
7373
unsigned long counters;
7474
#else
7575
/*
76-
* Keep _count separate from slub cmpxchg_double data.
77-
* As the rest of the double word is protected by
78-
* slab_lock but _count is not.
76+
* Keep _refcount separate from slub cmpxchg_double
77+
* data. As the rest of the double word is protected by
78+
* slab_lock but _refcount is not.
7979
*/
8080
unsigned counters;
8181
#endif
@@ -97,7 +97,11 @@ struct page {
9797
};
9898
int units; /* SLOB */
9999
};
100-
atomic_t _count; /* Usage count, see below. */
100+
/*
101+
* Usage count, *USE WRAPPER FUNCTION*
102+
* when manual accounting. See page_ref.h
103+
*/
104+
atomic_t _refcount;
101105
};
102106
unsigned int active; /* SLAB */
103107
};
@@ -248,7 +252,7 @@ struct page_frag_cache {
248252
__u32 offset;
249253
#endif
250254
/* we maintain a pagecount bias, so that we dont dirty cache line
251-
* containing page->_count every time we allocate a fragment.
255+
* containing page->_refcount every time we allocate a fragment.
252256
*/
253257
unsigned int pagecnt_bias;
254258
bool pfmemalloc;

‎include/linux/page_ref.h‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ static inline void __page_ref_unfreeze(struct page *page, int v)
6363

6464
static inline int page_ref_count(struct page *page)
6565
{
66-
return atomic_read(&page->_count);
66+
return atomic_read(&page->_refcount);
6767
}
6868

6969
static inline int page_count(struct page *page)
7070
{
71-
return atomic_read(&compound_head(page)->_count);
71+
return atomic_read(&compound_head(page)->_refcount);
7272
}
7373

7474
static inline void set_page_count(struct page *page, int v)
7575
{
76-
atomic_set(&page->_count, v);
76+
atomic_set(&page->_refcount, v);
7777
if (page_ref_tracepoint_active(__tracepoint_page_ref_set))
7878
__page_ref_set(page, v);
7979
}
@@ -89,35 +89,35 @@ static inline void init_page_count(struct page *page)
8989

9090
static inline void page_ref_add(struct page *page, int nr)
9191
{
92-
atomic_add(nr, &page->_count);
92+
atomic_add(nr, &page->_refcount);
9393
if (page_ref_tracepoint_active(__tracepoint_page_ref_mod))
9494
__page_ref_mod(page, nr);
9595
}
9696

9797
static inline void page_ref_sub(struct page *page, int nr)
9898
{
99-
atomic_sub(nr, &page->_count);
99+
atomic_sub(nr, &page->_refcount);
100100
if (page_ref_tracepoint_active(__tracepoint_page_ref_mod))
101101
__page_ref_mod(page, -nr);
102102
}
103103

104104
static inline void page_ref_inc(struct page *page)
105105
{
106-
atomic_inc(&page->_count);
106+
atomic_inc(&page->_refcount);
107107
if (page_ref_tracepoint_active(__tracepoint_page_ref_mod))
108108
__page_ref_mod(page, 1);
109109
}
110110

111111
static inline void page_ref_dec(struct page *page)
112112
{
113-
atomic_dec(&page->_count);
113+
atomic_dec(&page->_refcount);
114114
if (page_ref_tracepoint_active(__tracepoint_page_ref_mod))
115115
__page_ref_mod(page, -1);
116116
}
117117

118118
static inline int page_ref_sub_and_test(struct page *page, int nr)
119119
{
120-
int ret = atomic_sub_and_test(nr, &page->_count);
120+
int ret = atomic_sub_and_test(nr, &page->_refcount);
121121

122122
if (page_ref_tracepoint_active(__tracepoint_page_ref_mod_and_test))
123123
__page_ref_mod_and_test(page, -nr, ret);
@@ -126,7 +126,7 @@ static inline int page_ref_sub_and_test(struct page *page, int nr)
126126

127127
static inline int page_ref_dec_and_test(struct page *page)
128128
{
129-
int ret = atomic_dec_and_test(&page->_count);
129+
int ret = atomic_dec_and_test(&page->_refcount);
130130

131131
if (page_ref_tracepoint_active(__tracepoint_page_ref_mod_and_test))
132132
__page_ref_mod_and_test(page, -1, ret);
@@ -135,7 +135,7 @@ static inline int page_ref_dec_and_test(struct page *page)
135135

136136
static inline int page_ref_dec_return(struct page *page)
137137
{
138-
int ret = atomic_dec_return(&page->_count);
138+
int ret = atomic_dec_return(&page->_refcount);
139139

140140
if (page_ref_tracepoint_active(__tracepoint_page_ref_mod_and_return))
141141
__page_ref_mod_and_return(page, -1, ret);
@@ -144,7 +144,7 @@ static inline int page_ref_dec_return(struct page *page)
144144

145145
static inline int page_ref_add_unless(struct page *page, int nr, int u)
146146
{
147-
int ret = atomic_add_unless(&page->_count, nr, u);
147+
int ret = atomic_add_unless(&page->_refcount, nr, u);
148148

149149
if (page_ref_tracepoint_active(__tracepoint_page_ref_mod_unless))
150150
__page_ref_mod_unless(page, nr, ret);
@@ -153,7 +153,7 @@ static inline int page_ref_add_unless(struct page *page, int nr, int u)
153153

154154
static inline int page_ref_freeze(struct page *page, int count)
155155
{
156-
int ret = likely(atomic_cmpxchg(&page->_count, count, 0) == count);
156+
int ret = likely(atomic_cmpxchg(&page->_refcount, count, 0) == count);
157157

158158
if (page_ref_tracepoint_active(__tracepoint_page_ref_freeze))
159159
__page_ref_freeze(page, count, ret);
@@ -165,7 +165,7 @@ static inline void page_ref_unfreeze(struct page *page, int count)
165165
VM_BUG_ON_PAGE(page_count(page) != 0, page);
166166
VM_BUG_ON(count == 0);
167167

168-
atomic_set(&page->_count, count);
168+
atomic_set(&page->_refcount, count);
169169
if (page_ref_tracepoint_active(__tracepoint_page_ref_unfreeze))
170170
__page_ref_unfreeze(page, count);
171171
}

0 commit comments

Comments
 (0)