2016-03-28 06:30:20

by Joonsoo Kim

[permalink] [raw]
Subject: [PATCH v2 1/2] mm/page_ref: use page_ref helper instead of direct modification of _count

From: Joonsoo Kim <[email protected]>

page_reference manipulation functions are introduced to track down
reference count change of the page. Use it instead of direct modification
of _count.

Signed-off-by: Joonsoo Kim <[email protected]>
---
drivers/net/ethernet/cavium/thunder/nicvf_queues.c | 2 +-
drivers/net/ethernet/qlogic/qede/qede_main.c | 2 +-
mm/filemap.c | 2 +-
net/wireless/util.c | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_queues.c b/drivers/net/ethernet/cavium/thunder/nicvf_queues.c
index fa05e34..8acd7c0 100644
--- a/drivers/net/ethernet/cavium/thunder/nicvf_queues.c
+++ b/drivers/net/ethernet/cavium/thunder/nicvf_queues.c
@@ -23,7 +23,7 @@ static void nicvf_get_page(struct nicvf *nic)
if (!nic->rb_pageref || !nic->rb_page)
return;

- atomic_add(nic->rb_pageref, &nic->rb_page->_count);
+ page_ref_add(nic->rb_page, nic->rb_pageref);
nic->rb_pageref = 0;
}

diff --git a/drivers/net/ethernet/qlogic/qede/qede_main.c b/drivers/net/ethernet/qlogic/qede/qede_main.c
index 518af32..394c97ff 100644
--- a/drivers/net/ethernet/qlogic/qede/qede_main.c
+++ b/drivers/net/ethernet/qlogic/qede/qede_main.c
@@ -791,7 +791,7 @@ static inline int qede_realloc_rx_buffer(struct qede_dev *edev,
* network stack to take the ownership of the page
* which can be recycled multiple times by the driver.
*/
- atomic_inc(&curr_cons->data->_count);
+ page_ref_inc(curr_cons->data);
qede_reuse_page(edev, rxq, curr_cons);
}

diff --git a/mm/filemap.c b/mm/filemap.c
index a8c69c8..0ebd326 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -213,7 +213,7 @@ void __delete_from_page_cache(struct page *page, void *shadow)
* some other bad page check should catch it later.
*/
page_mapcount_reset(page);
- atomic_sub(mapcount, &page->_count);
+ page_ref_sub(page, mapcount);
}
}

diff --git a/net/wireless/util.c b/net/wireless/util.c
index 9f440a9..e22432a 100644
--- a/net/wireless/util.c
+++ b/net/wireless/util.c
@@ -651,7 +651,7 @@ __frame_add_frag(struct sk_buff *skb, struct page *page,
struct skb_shared_info *sh = skb_shinfo(skb);
int page_offset;

- atomic_inc(&page->_count);
+ page_ref_inc(page);
page_offset = ptr - page_address(page);
skb_add_rx_frag(skb, sh->nr_frags, page, page_offset, len, size);
}
--
1.9.1


2016-03-28 06:30:46

by Joonsoo Kim

[permalink] [raw]
Subject: [PATCH v2 2/2] mm: rename _count, field of the struct page, to _refcount

From: Joonsoo Kim <[email protected]>

Many developer 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.

v2: change more _count usages to _refcount

Signed-off-by: Joonsoo Kim <[email protected]>
---
arch/tile/mm/init.c | 2 +-
include/linux/mm_types.h | 8 ++++++--
include/linux/page_ref.h | 26 +++++++++++++-------------
kernel/kexec_core.c | 2 +-
4 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/arch/tile/mm/init.c b/arch/tile/mm/init.c
index a0582b7..adce254 100644
--- a/arch/tile/mm/init.c
+++ b/arch/tile/mm/init.c
@@ -679,7 +679,7 @@ static void __init init_free_pfn_range(unsigned long start, unsigned long end)
* Hacky direct set to avoid unnecessary
* lock take/release for EVERY page here.
*/
- p->_count.counter = 0;
+ p->_refcount.counter = 0;
p->_mapcount.counter = -1;
}
init_page_count(page);
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 944b2b3..9e8eb5a 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -97,7 +97,11 @@ struct page {
};
int units; /* SLOB */
};
- atomic_t _count; /* Usage count, see below. */
+ /*
+ * Usage count, *USE WRAPPER FUNCTION*
+ * when manual accounting. See page_ref.h
+ */
+ atomic_t _refcount;
};
unsigned int active; /* SLAB */
};
@@ -248,7 +252,7 @@ struct page_frag_cache {
__u32 offset;
#endif
/* we maintain a pagecount bias, so that we dont dirty cache line
- * containing page->_count every time we allocate a fragment.
+ * containing page->_refcount every time we allocate a fragment.
*/
unsigned int pagecnt_bias;
bool pfmemalloc;
diff --git a/include/linux/page_ref.h b/include/linux/page_ref.h
index e596d5d9..8b5e0a9 100644
--- a/include/linux/page_ref.h
+++ b/include/linux/page_ref.h
@@ -63,17 +63,17 @@ static inline void __page_ref_unfreeze(struct page *page, int v)

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

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

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

static inline void page_ref_add(struct page *page, int nr)
{
- atomic_add(nr, &page->_count);
+ atomic_add(nr, &page->_refcount);
if (page_ref_tracepoint_active(__tracepoint_page_ref_mod))
__page_ref_mod(page, nr);
}

static inline void page_ref_sub(struct page *page, int nr)
{
- atomic_sub(nr, &page->_count);
+ atomic_sub(nr, &page->_refcount);
if (page_ref_tracepoint_active(__tracepoint_page_ref_mod))
__page_ref_mod(page, -nr);
}

static inline void page_ref_inc(struct page *page)
{
- atomic_inc(&page->_count);
+ atomic_inc(&page->_refcount);
if (page_ref_tracepoint_active(__tracepoint_page_ref_mod))
__page_ref_mod(page, 1);
}

static inline void page_ref_dec(struct page *page)
{
- atomic_dec(&page->_count);
+ atomic_dec(&page->_refcount);
if (page_ref_tracepoint_active(__tracepoint_page_ref_mod))
__page_ref_mod(page, -1);
}

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

if (page_ref_tracepoint_active(__tracepoint_page_ref_mod_and_test))
__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)

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

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

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

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

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

if (page_ref_tracepoint_active(__tracepoint_page_ref_mod_unless))
__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)

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

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

- atomic_set(&page->_count, count);
+ atomic_set(&page->_refcount, count);
if (page_ref_tracepoint_active(__tracepoint_page_ref_unfreeze))
__page_ref_unfreeze(page, count);
}
diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
index f826e11..e0e95b0 100644
--- a/kernel/kexec_core.c
+++ b/kernel/kexec_core.c
@@ -1410,7 +1410,7 @@ static int __init crash_save_vmcoreinfo_init(void)
VMCOREINFO_STRUCT_SIZE(list_head);
VMCOREINFO_SIZE(nodemask_t);
VMCOREINFO_OFFSET(page, flags);
- VMCOREINFO_OFFSET(page, _count);
+ VMCOREINFO_OFFSET(page, _refcount);
VMCOREINFO_OFFSET(page, mapping);
VMCOREINFO_OFFSET(page, lru);
VMCOREINFO_OFFSET(page, _mapcount);
--
1.9.1

2016-03-29 09:12:12

by Vlastimil Babka

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] mm/page_ref: use page_ref helper instead of direct modification of _count

On 03/28/2016 08:30 AM, [email protected] wrote:
> From: Joonsoo Kim <[email protected]>
>
> page_reference manipulation functions are introduced to track down
> reference count change of the page. Use it instead of direct modification
> of _count.
>
> Signed-off-by: Joonsoo Kim <[email protected]>

Acked-by: Vlastimil Babka <[email protected]>

2016-03-29 09:27:53

by Vlastimil Babka

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] mm: rename _count, field of the struct page, to _refcount

On 03/28/2016 08:30 AM, [email protected] wrote:
> From: Joonsoo Kim <[email protected]>
>
> Many developer 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.
>
> v2: change more _count usages to _refcount

There's also
Documentation/vm/transhuge.txt talking about ->_count
include/linux/mm.h: * requires to already have an elevated page->_count.
include/linux/mm_types.h: * Keep _count separate from slub cmpxchg_double data.
include/linux/mm_types.h: * slab_lock but _count is not.
include/linux/pagemap.h: * If the page is free (_count == 0), then _count is untouched, and 0
include/linux/pagemap.h: * is returned. Otherwise, _count is incremented by 1 and 1 is returned.
include/linux/pagemap.h: * this allows allocators to use a synchronize_rcu() to stabilize _count.
include/linux/pagemap.h: * Remove-side that cares about stability of _count (eg. reclaim) has the
mm/huge_memory.c: * tail_page->_count is zero and not changing from under us. But
mm/huge_memory.c: /* Prevent deferred_split_scan() touching ->_count */
mm/internal.h: * Turn a non-refcounted page (->_count == 0) into refcounted with
mm/page_alloc.c: bad_reason = "nonzero _count";
mm/page_alloc.c: bad_reason = "nonzero _count";
mm/page_alloc.c: * because their page->_count is zero at all time.
mm/slub.c: * as page->_count. If we assign to ->counters directly
mm/slub.c: * we run the risk of losing updates to page->_count, so
mm/vmscan.c: * load is not satisfied before that of page->_count.
mm/vmscan.c: * The downside is that we have to touch page->_count against each page.

I've arrived at the following command to find this:
git grep "[^a-zA-Z0-9_]_count[^_]"

Not that many false positives in the output :)

> Signed-off-by: Joonsoo Kim <[email protected]>
> ---
> arch/tile/mm/init.c | 2 +-
> include/linux/mm_types.h | 8 ++++++--
> include/linux/page_ref.h | 26 +++++++++++++-------------
> kernel/kexec_core.c | 2 +-
> 4 files changed, 21 insertions(+), 17 deletions(-)
>
> diff --git a/arch/tile/mm/init.c b/arch/tile/mm/init.c
> index a0582b7..adce254 100644
> --- a/arch/tile/mm/init.c
> +++ b/arch/tile/mm/init.c
> @@ -679,7 +679,7 @@ static void __init init_free_pfn_range(unsigned long start, unsigned long end)
> * Hacky direct set to avoid unnecessary
> * lock take/release for EVERY page here.
> */
> - p->_count.counter = 0;
> + p->_refcount.counter = 0;
> p->_mapcount.counter = -1;
> }
> init_page_count(page);
> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
> index 944b2b3..9e8eb5a 100644
> --- a/include/linux/mm_types.h
> +++ b/include/linux/mm_types.h
> @@ -97,7 +97,11 @@ struct page {
> };
> int units; /* SLOB */
> };
> - atomic_t _count; /* Usage count, see below. */
> + /*
> + * Usage count, *USE WRAPPER FUNCTION*
> + * when manual accounting. See page_ref.h
> + */
> + atomic_t _refcount;
> };
> unsigned int active; /* SLAB */
> };
> @@ -248,7 +252,7 @@ struct page_frag_cache {
> __u32 offset;
> #endif
> /* we maintain a pagecount bias, so that we dont dirty cache line
> - * containing page->_count every time we allocate a fragment.
> + * containing page->_refcount every time we allocate a fragment.
> */
> unsigned int pagecnt_bias;
> bool pfmemalloc;
> diff --git a/include/linux/page_ref.h b/include/linux/page_ref.h
> index e596d5d9..8b5e0a9 100644
> --- a/include/linux/page_ref.h
> +++ b/include/linux/page_ref.h
> @@ -63,17 +63,17 @@ static inline void __page_ref_unfreeze(struct page *page, int v)
>
> static inline int page_ref_count(struct page *page)
> {
> - return atomic_read(&page->_count);
> + return atomic_read(&page->_refcount);
> }
>
> static inline int page_count(struct page *page)
> {
> - return atomic_read(&compound_head(page)->_count);
> + return atomic_read(&compound_head(page)->_refcount);
> }
>
> static inline void set_page_count(struct page *page, int v)
> {
> - atomic_set(&page->_count, v);
> + atomic_set(&page->_refcount, v);
> if (page_ref_tracepoint_active(__tracepoint_page_ref_set))
> __page_ref_set(page, v);
> }
> @@ -89,35 +89,35 @@ static inline void init_page_count(struct page *page)
>
> static inline void page_ref_add(struct page *page, int nr)
> {
> - atomic_add(nr, &page->_count);
> + atomic_add(nr, &page->_refcount);
> if (page_ref_tracepoint_active(__tracepoint_page_ref_mod))
> __page_ref_mod(page, nr);
> }
>
> static inline void page_ref_sub(struct page *page, int nr)
> {
> - atomic_sub(nr, &page->_count);
> + atomic_sub(nr, &page->_refcount);
> if (page_ref_tracepoint_active(__tracepoint_page_ref_mod))
> __page_ref_mod(page, -nr);
> }
>
> static inline void page_ref_inc(struct page *page)
> {
> - atomic_inc(&page->_count);
> + atomic_inc(&page->_refcount);
> if (page_ref_tracepoint_active(__tracepoint_page_ref_mod))
> __page_ref_mod(page, 1);
> }
>
> static inline void page_ref_dec(struct page *page)
> {
> - atomic_dec(&page->_count);
> + atomic_dec(&page->_refcount);
> if (page_ref_tracepoint_active(__tracepoint_page_ref_mod))
> __page_ref_mod(page, -1);
> }
>
> static inline int page_ref_sub_and_test(struct page *page, int nr)
> {
> - int ret = atomic_sub_and_test(nr, &page->_count);
> + int ret = atomic_sub_and_test(nr, &page->_refcount);
>
> if (page_ref_tracepoint_active(__tracepoint_page_ref_mod_and_test))
> __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)
>
> static inline int page_ref_dec_and_test(struct page *page)
> {
> - int ret = atomic_dec_and_test(&page->_count);
> + int ret = atomic_dec_and_test(&page->_refcount);
>
> if (page_ref_tracepoint_active(__tracepoint_page_ref_mod_and_test))
> __page_ref_mod_and_test(page, -1, ret);
> @@ -135,7 +135,7 @@ static inline int page_ref_dec_and_test(struct page *page)
>
> static inline int page_ref_dec_return(struct page *page)
> {
> - int ret = atomic_dec_return(&page->_count);
> + int ret = atomic_dec_return(&page->_refcount);
>
> if (page_ref_tracepoint_active(__tracepoint_page_ref_mod_and_return))
> __page_ref_mod_and_return(page, -1, ret);
> @@ -144,7 +144,7 @@ static inline int page_ref_dec_return(struct page *page)
>
> static inline int page_ref_add_unless(struct page *page, int nr, int u)
> {
> - int ret = atomic_add_unless(&page->_count, nr, u);
> + int ret = atomic_add_unless(&page->_refcount, nr, u);
>
> if (page_ref_tracepoint_active(__tracepoint_page_ref_mod_unless))
> __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)
>
> static inline int page_ref_freeze(struct page *page, int count)
> {
> - int ret = likely(atomic_cmpxchg(&page->_count, count, 0) == count);
> + int ret = likely(atomic_cmpxchg(&page->_refcount, count, 0) == count);
>
> if (page_ref_tracepoint_active(__tracepoint_page_ref_freeze))
> __page_ref_freeze(page, count, ret);
> @@ -165,7 +165,7 @@ static inline void page_ref_unfreeze(struct page *page, int count)
> VM_BUG_ON_PAGE(page_count(page) != 0, page);
> VM_BUG_ON(count == 0);
>
> - atomic_set(&page->_count, count);
> + atomic_set(&page->_refcount, count);
> if (page_ref_tracepoint_active(__tracepoint_page_ref_unfreeze))
> __page_ref_unfreeze(page, count);
> }
> diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
> index f826e11..e0e95b0 100644
> --- a/kernel/kexec_core.c
> +++ b/kernel/kexec_core.c
> @@ -1410,7 +1410,7 @@ static int __init crash_save_vmcoreinfo_init(void)
> VMCOREINFO_STRUCT_SIZE(list_head);
> VMCOREINFO_SIZE(nodemask_t);
> VMCOREINFO_OFFSET(page, flags);
> - VMCOREINFO_OFFSET(page, _count);
> + VMCOREINFO_OFFSET(page, _refcount);
> VMCOREINFO_OFFSET(page, mapping);
> VMCOREINFO_OFFSET(page, lru);
> VMCOREINFO_OFFSET(page, _mapcount);
>

2016-03-29 19:23:19

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] mm: rename _count, field of the struct page, to _refcount

On Tue, 29 Mar 2016 11:27:47 +0200 Vlastimil Babka <[email protected]> wrote:

> > v2: change more _count usages to _refcount
>
> There's also
> Documentation/vm/transhuge.txt talking about ->_count
> include/linux/mm.h: * requires to already have an elevated page->_count.
> include/linux/mm_types.h: * Keep _count separate from slub cmpxchg_double data.
> include/linux/mm_types.h: * slab_lock but _count is not.
> include/linux/pagemap.h: * If the page is free (_count == 0), then _count is untouched, and 0
> include/linux/pagemap.h: * is returned. Otherwise, _count is incremented by 1 and 1 is returned.
> include/linux/pagemap.h: * this allows allocators to use a synchronize_rcu() to stabilize _count.
> include/linux/pagemap.h: * Remove-side that cares about stability of _count (eg. reclaim) has the
> mm/huge_memory.c: * tail_page->_count is zero and not changing from under us. But
> mm/huge_memory.c: /* Prevent deferred_split_scan() touching ->_count */
> mm/internal.h: * Turn a non-refcounted page (->_count == 0) into refcounted with
> mm/page_alloc.c: bad_reason = "nonzero _count";
> mm/page_alloc.c: bad_reason = "nonzero _count";
> mm/page_alloc.c: * because their page->_count is zero at all time.
> mm/slub.c: * as page->_count. If we assign to ->counters directly
> mm/slub.c: * we run the risk of losing updates to page->_count, so
> mm/vmscan.c: * load is not satisfied before that of page->_count.
> mm/vmscan.c: * The downside is that we have to touch page->_count against each page.
>
> I've arrived at the following command to find this:
> git grep "[^a-zA-Z0-9_]_count[^_]"
>
> Not that many false positives in the output :)


From: Andrew Morton <[email protected]>
Subject: mm-rename-_count-field-of-the-struct-page-to-_refcount-fix

fix comments, per Vlastimil

Cc: Vlastimil Babka <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Chris Metcalf <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Johannes Berg <[email protected]>
Cc: Joonsoo Kim <[email protected]>
Cc: Sunil Goutham <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
---

drivers/block/aoe/aoecmd.c | 2 +-
drivers/hwtracing/intel_th/msu.c | 2 +-
fs/proc/page.c | 2 +-
include/linux/mm.h | 2 +-
include/linux/mm_types.h | 6 +++---
include/linux/pagemap.h | 8 ++++----
mm/huge_memory.c | 4 ++--
mm/internal.h | 2 +-
mm/page_alloc.c | 2 +-
mm/slub.c | 4 ++--
mm/vmscan.c | 4 ++--
11 files changed, 19 insertions(+), 19 deletions(-)

diff -puN drivers/block/aoe/aoecmd.c~mm-rename-_count-field-of-the-struct-page-to-_refcount-fix drivers/block/aoe/aoecmd.c
--- a/drivers/block/aoe/aoecmd.c~mm-rename-_count-field-of-the-struct-page-to-_refcount-fix
+++ a/drivers/block/aoe/aoecmd.c
@@ -861,7 +861,7 @@ rqbiocnt(struct request *r)
* discussion.
*
* We cannot use get_page in the workaround, because it insists on a
- * positive page count as a precondition. So we use _count directly.
+ * positive page count as a precondition. So we use _refcount directly.
*/
static void
bio_pageinc(struct bio *bio)
diff -puN drivers/hwtracing/intel_th/msu.c~mm-rename-_count-field-of-the-struct-page-to-_refcount-fix drivers/hwtracing/intel_th/msu.c
--- a/drivers/hwtracing/intel_th/msu.c~mm-rename-_count-field-of-the-struct-page-to-_refcount-fix
+++ a/drivers/hwtracing/intel_th/msu.c
@@ -1164,7 +1164,7 @@ static void msc_mmap_close(struct vm_are
if (!atomic_dec_and_mutex_lock(&msc->mmap_count, &msc->buf_mutex))
return;

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

diff -puN fs/proc/page.c~mm-rename-_count-field-of-the-struct-page-to-_refcount-fix fs/proc/page.c
--- a/fs/proc/page.c~mm-rename-_count-field-of-the-struct-page-to-_refcount-fix
+++ a/fs/proc/page.c
@@ -142,7 +142,7 @@ u64 stable_page_flags(struct page *page)


/*
- * Caveats on high order pages: page->_count will only be set
+ * Caveats on high order pages: page->_refcount will only be set
* -1 on the head page; SLUB/SLQB do the same for PG_slab;
* SLOB won't set PG_slab at all on compound pages.
*/
diff -puN include/linux/mm.h~mm-rename-_count-field-of-the-struct-page-to-_refcount-fix include/linux/mm.h
--- a/include/linux/mm.h~mm-rename-_count-field-of-the-struct-page-to-_refcount-fix
+++ a/include/linux/mm.h
@@ -721,7 +721,7 @@ static inline void get_page(struct page
page = compound_head(page);
/*
* Getting a normal page or the head of a compound page
- * requires to already have an elevated page->_count.
+ * requires to already have an elevated page->_refcount.
*/
VM_BUG_ON_PAGE(page_ref_count(page) <= 0, page);
page_ref_inc(page);
diff -puN include/linux/mm_types.h~mm-rename-_count-field-of-the-struct-page-to-_refcount-fix include/linux/mm_types.h
--- a/include/linux/mm_types.h~mm-rename-_count-field-of-the-struct-page-to-_refcount-fix
+++ a/include/linux/mm_types.h
@@ -73,9 +73,9 @@ struct page {
unsigned long counters;
#else
/*
- * Keep _count separate from slub cmpxchg_double data.
- * As the rest of the double word is protected by
- * slab_lock but _count is not.
+ * Keep _refcount separate from slub cmpxchg_double
+ * data. As the rest of the double word is protected by
+ * slab_lock but _refcount is not.
*/
unsigned counters;
#endif
diff -puN include/linux/pagemap.h~mm-rename-_count-field-of-the-struct-page-to-_refcount-fix include/linux/pagemap.h
--- a/include/linux/pagemap.h~mm-rename-_count-field-of-the-struct-page-to-_refcount-fix
+++ a/include/linux/pagemap.h
@@ -105,12 +105,12 @@ void release_pages(struct page **pages,

/*
* speculatively take a reference to a page.
- * If the page is free (_count == 0), then _count is untouched, and 0
- * is returned. Otherwise, _count is incremented by 1 and 1 is returned.
+ * If the page is free (_refcount == 0), then _refcount is untouched, and 0
+ * is returned. Otherwise, _refcount is incremented by 1 and 1 is returned.
*
* This function must be called inside the same rcu_read_lock() section as has
* been used to lookup the page in the pagecache radix-tree (or page table):
- * this allows allocators to use a synchronize_rcu() to stabilize _count.
+ * this allows allocators to use a synchronize_rcu() to stabilize _refcount.
*
* Unless an RCU grace period has passed, the count of all pages coming out
* of the allocator must be considered unstable. page_count may return higher
@@ -126,7 +126,7 @@ void release_pages(struct page **pages,
* 2. conditionally increment refcount
* 3. check the page is still in pagecache (if no, goto 1)
*
- * Remove-side that cares about stability of _count (eg. reclaim) has the
+ * Remove-side that cares about stability of _refcount (eg. reclaim) has the
* following (with tree_lock held for write):
* A. atomically check refcount is correct and set it to 0 (atomic_cmpxchg)
* B. remove page from pagecache
diff -puN mm/huge_memory.c~mm-rename-_count-field-of-the-struct-page-to-_refcount-fix mm/huge_memory.c
--- a/mm/huge_memory.c~mm-rename-_count-field-of-the-struct-page-to-_refcount-fix
+++ a/mm/huge_memory.c
@@ -3120,7 +3120,7 @@ static void __split_huge_page_tail(struc
VM_BUG_ON_PAGE(page_ref_count(page_tail) != 0, page_tail);

/*
- * tail_page->_count is zero and not changing from under us. But
+ * tail_page->_refcount is zero and not changing from under us. But
* get_page_unless_zero() may be running from under us on the
* tail_page. If we used atomic_set() below instead of atomic_inc(), we
* would then run atomic_set() concurrently with
@@ -3289,7 +3289,7 @@ int split_huge_page_to_list(struct page
if (mlocked)
lru_add_drain();

- /* Prevent deferred_split_scan() touching ->_count */
+ /* Prevent deferred_split_scan() touching ->_refcount */
spin_lock_irqsave(&pgdata->split_queue_lock, flags);
count = page_count(head);
mapcount = total_mapcount(head);
diff -puN mm/internal.h~mm-rename-_count-field-of-the-struct-page-to-_refcount-fix mm/internal.h
--- a/mm/internal.h~mm-rename-_count-field-of-the-struct-page-to-_refcount-fix
+++ a/mm/internal.h
@@ -58,7 +58,7 @@ static inline unsigned long ra_submit(st
}

/*
- * Turn a non-refcounted page (->_count == 0) into refcounted with
+ * Turn a non-refcounted page (->_refcount == 0) into refcounted with
* a count of one.
*/
static inline void set_page_refcounted(struct page *page)
diff -puN mm/page_alloc.c~mm-rename-_count-field-of-the-struct-page-to-_refcount-fix mm/page_alloc.c
--- a/mm/page_alloc.c~mm-rename-_count-field-of-the-struct-page-to-_refcount-fix
+++ a/mm/page_alloc.c
@@ -6864,7 +6864,7 @@ bool has_unmovable_pages(struct zone *zo
* We can't use page_count without pin a page
* because another CPU can free compound page.
* This check already skips compound tails of THP
- * because their page->_count is zero at all time.
+ * because their page->_refcount is zero at all time.
*/
if (!page_ref_count(page)) {
if (PageBuddy(page))
diff -puN mm/slub.c~mm-rename-_count-field-of-the-struct-page-to-_refcount-fix mm/slub.c
--- a/mm/slub.c~mm-rename-_count-field-of-the-struct-page-to-_refcount-fix
+++ a/mm/slub.c
@@ -329,8 +329,8 @@ static inline void set_page_slub_counter
tmp.counters = counters_new;
/*
* page->counters can cover frozen/inuse/objects as well
- * as page->_count. If we assign to ->counters directly
- * we run the risk of losing updates to page->_count, so
+ * as page->_refcount. If we assign to ->counters directly
+ * we run the risk of losing updates to page->_refcount, so
* be careful and only assign to the fields we need.
*/
page->frozen = tmp.frozen;
diff -puN mm/vmscan.c~mm-rename-_count-field-of-the-struct-page-to-_refcount-fix mm/vmscan.c
--- a/mm/vmscan.c~mm-rename-_count-field-of-the-struct-page-to-_refcount-fix
+++ a/mm/vmscan.c
@@ -633,7 +633,7 @@ static int __remove_mapping(struct addre
*
* Reversing the order of the tests ensures such a situation cannot
* escape unnoticed. The smp_rmb is needed to ensure the page->flags
- * load is not satisfied before that of page->_count.
+ * load is not satisfied before that of page->_refcount.
*
* Note that if SetPageDirty is always performed via set_page_dirty,
* and thus under tree_lock, then this ordering is not required.
@@ -1720,7 +1720,7 @@ shrink_inactive_list(unsigned long nr_to
* It is safe to rely on PG_active against the non-LRU pages in here because
* nobody will play with that bit on a non-LRU page.
*
- * The downside is that we have to touch page->_count against each page.
+ * The downside is that we have to touch page->_refcount against each page.
* But we had to alter page->flags anyway.
*/

_

2016-03-30 08:25:09

by Joonsoo Kim

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] mm: rename _count, field of the struct page, to _refcount

On Tue, Mar 29, 2016 at 12:23:13PM -0700, Andrew Morton wrote:
> On Tue, 29 Mar 2016 11:27:47 +0200 Vlastimil Babka <[email protected]> wrote:
>
> > > v2: change more _count usages to _refcount
> >
> > There's also
> > Documentation/vm/transhuge.txt talking about ->_count
> > include/linux/mm.h: * requires to already have an elevated page->_count.
> > include/linux/mm_types.h: * Keep _count separate from slub cmpxchg_double data.
> > include/linux/mm_types.h: * slab_lock but _count is not.
> > include/linux/pagemap.h: * If the page is free (_count == 0), then _count is untouched, and 0
> > include/linux/pagemap.h: * is returned. Otherwise, _count is incremented by 1 and 1 is returned.
> > include/linux/pagemap.h: * this allows allocators to use a synchronize_rcu() to stabilize _count.
> > include/linux/pagemap.h: * Remove-side that cares about stability of _count (eg. reclaim) has the
> > mm/huge_memory.c: * tail_page->_count is zero and not changing from under us. But
> > mm/huge_memory.c: /* Prevent deferred_split_scan() touching ->_count */
> > mm/internal.h: * Turn a non-refcounted page (->_count == 0) into refcounted with
> > mm/page_alloc.c: bad_reason = "nonzero _count";
> > mm/page_alloc.c: bad_reason = "nonzero _count";
> > mm/page_alloc.c: * because their page->_count is zero at all time.
> > mm/slub.c: * as page->_count. If we assign to ->counters directly
> > mm/slub.c: * we run the risk of losing updates to page->_count, so
> > mm/vmscan.c: * load is not satisfied before that of page->_count.
> > mm/vmscan.c: * The downside is that we have to touch page->_count against each page.
> >
> > I've arrived at the following command to find this:
> > git grep "[^a-zA-Z0-9_]_count[^_]"
> >
> > Not that many false positives in the output :)
>
>
> From: Andrew Morton <[email protected]>
> Subject: mm-rename-_count-field-of-the-struct-page-to-_refcount-fix
>
> fix comments, per Vlastimil

Andrew and Vlastimil, great thanks!

Thanks.

2016-03-30 08:29:47

by Vlastimil Babka

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] mm: rename _count, field of the struct page, to _refcount

On 03/30/2016 10:27 AM, Joonsoo Kim wrote:
> On Tue, Mar 29, 2016 at 12:23:13PM -0700, Andrew Morton wrote:
>> On Tue, 29 Mar 2016 11:27:47 +0200 Vlastimil Babka <[email protected]> wrote:
>>
>>>> v2: change more _count usages to _refcount
>>>
>>> There's also
>>> Documentation/vm/transhuge.txt talking about ->_count
>>> include/linux/mm.h: * requires to already have an elevated page->_count.
>>> include/linux/mm_types.h: * Keep _count separate from slub cmpxchg_double data.
>>> include/linux/mm_types.h: * slab_lock but _count is not.
>>> include/linux/pagemap.h: * If the page is free (_count == 0), then _count is untouched, and 0
>>> include/linux/pagemap.h: * is returned. Otherwise, _count is incremented by 1 and 1 is returned.
>>> include/linux/pagemap.h: * this allows allocators to use a synchronize_rcu() to stabilize _count.
>>> include/linux/pagemap.h: * Remove-side that cares about stability of _count (eg. reclaim) has the
>>> mm/huge_memory.c: * tail_page->_count is zero and not changing from under us. But
>>> mm/huge_memory.c: /* Prevent deferred_split_scan() touching ->_count */
>>> mm/internal.h: * Turn a non-refcounted page (->_count == 0) into refcounted with
>>> mm/page_alloc.c: bad_reason = "nonzero _count";
>>> mm/page_alloc.c: bad_reason = "nonzero _count";
>>> mm/page_alloc.c: * because their page->_count is zero at all time.
>>> mm/slub.c: * as page->_count. If we assign to ->counters directly
>>> mm/slub.c: * we run the risk of losing updates to page->_count, so
>>> mm/vmscan.c: * load is not satisfied before that of page->_count.
>>> mm/vmscan.c: * The downside is that we have to touch page->_count against each page.
>>>
>>> I've arrived at the following command to find this:
>>> git grep "[^a-zA-Z0-9_]_count[^_]"
>>>
>>> Not that many false positives in the output :)
>>
>>
>> From: Andrew Morton <[email protected]>
>> Subject: mm-rename-_count-field-of-the-struct-page-to-_refcount-fix
>>
>> fix comments, per Vlastimil
>
> Andrew and Vlastimil, great thanks!

Thanks, Andrew.

That leaves just Documentation/vm/transhuge.txt to you, Joonsoo :)

> Thanks.
>