Skip to content

Commit 5344b7e

Browse files
Nick Piggintorvalds
authored andcommitted
vmstat: mlocked pages statistics
Add NR_MLOCK zone page state, which provides a (conservative) count of mlocked pages (actually, the number of mlocked pages moved off the LRU). Reworked by lts to fit in with the modified mlock page support in the Reclaim Scalability series. [kosaki.motohiro@jp.fujitsu.com: fix incorrect Mlocked field of /proc/meminfo] [lee.schermerhorn@hp.com: mlocked-pages: add event counting with statistics] Signed-off-by: Nick Piggin <npiggin@suse.de> Signed-off-by: Lee Schermerhorn <lee.schermerhorn@hp.com> Signed-off-by: Rik van Riel <riel@redhat.com> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ba470de commit 5344b7e

7 files changed

Lines changed: 65 additions & 9 deletions

File tree

‎drivers/base/node.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ static ssize_t node_read_meminfo(struct sys_device * dev,
7171
"Node %d Active(file): %8lu kB\n"
7272
"Node %d Inactive(file): %8lu kB\n"
7373
#ifdef CONFIG_UNEVICTABLE_LRU
74-
"Node %d Noreclaim: %8lu kB\n"
74+
"Node %d Unevictable: %8lu kB\n"
75+
"Node %d Mlocked: %8lu kB\n"
7576
#endif
7677
#ifdef CONFIG_HIGHMEM
7778
"Node %d HighTotal: %8lu kB\n"
@@ -104,6 +105,7 @@ static ssize_t node_read_meminfo(struct sys_device * dev,
104105
nid, K(node_page_state(nid, NR_INACTIVE_FILE)),
105106
#ifdef CONFIG_UNEVICTABLE_LRU
106107
nid, K(node_page_state(nid, NR_UNEVICTABLE)),
108+
nid, K(node_page_state(nid, NR_MLOCK)),
107109
#endif
108110
#ifdef CONFIG_HIGHMEM
109111
nid, K(i.totalhigh),

‎fs/proc/proc_misc.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ static int meminfo_read_proc(char *page, char **start, off_t off,
176176
"Inactive(file): %8lu kB\n"
177177
#ifdef CONFIG_UNEVICTABLE_LRU
178178
"Unevictable: %8lu kB\n"
179+
"Mlocked: %8lu kB\n"
179180
#endif
180181
#ifdef CONFIG_HIGHMEM
181182
"HighTotal: %8lu kB\n"
@@ -217,6 +218,7 @@ static int meminfo_read_proc(char *page, char **start, off_t off,
217218
K(pages[LRU_INACTIVE_FILE]),
218219
#ifdef CONFIG_UNEVICTABLE_LRU
219220
K(pages[LRU_UNEVICTABLE]),
221+
K(global_page_state(NR_MLOCK)),
220222
#endif
221223
#ifdef CONFIG_HIGHMEM
222224
K(i.totalhigh),

‎include/linux/mmzone.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ enum zone_stat_item {
8888
NR_ACTIVE_FILE, /* " " " " " */
8989
#ifdef CONFIG_UNEVICTABLE_LRU
9090
NR_UNEVICTABLE, /* " " " " " */
91+
NR_MLOCK, /* mlock()ed pages found and moved off LRU */
9192
#else
9293
NR_UNEVICTABLE = NR_ACTIVE_FILE, /* avoid compiler errors in dead code */
94+
NR_MLOCK = NR_ACTIVE_FILE,
9395
#endif
9496
NR_ANON_PAGES, /* Mapped anonymous pages */
9597
NR_FILE_MAPPED, /* pagecache pages mapped into pagetables.

‎include/linux/vmstat.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
4545
UNEVICTABLE_PGCULLED, /* culled to noreclaim list */
4646
UNEVICTABLE_PGSCANNED, /* scanned for reclaimability */
4747
UNEVICTABLE_PGRESCUED, /* rescued from noreclaim list */
48+
UNEVICTABLE_PGMLOCKED,
49+
UNEVICTABLE_PGMUNLOCKED,
50+
UNEVICTABLE_PGCLEARED, /* on COW, page truncate */
51+
UNEVICTABLE_PGSTRANDED, /* unable to isolate on unlock */
4852
#endif
4953
NR_VM_EVENT_ITEMS
5054
};

‎mm/internal.h‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ static inline int is_mlocked_vma(struct vm_area_struct *vma, struct page *page)
101101
if (likely((vma->vm_flags & (VM_LOCKED | VM_SPECIAL)) != VM_LOCKED))
102102
return 0;
103103

104-
SetPageMlocked(page);
104+
if (!TestSetPageMlocked(page)) {
105+
inc_zone_page_state(page, NR_MLOCK);
106+
count_vm_event(UNEVICTABLE_PGMLOCKED);
107+
}
105108
return 1;
106109
}
107110

@@ -128,12 +131,19 @@ static inline void clear_page_mlock(struct page *page)
128131

129132
/*
130133
* mlock_migrate_page - called only from migrate_page_copy() to
131-
* migrate the Mlocked page flag
134+
* migrate the Mlocked page flag; update statistics.
132135
*/
133136
static inline void mlock_migrate_page(struct page *newpage, struct page *page)
134137
{
135-
if (TestClearPageMlocked(page))
138+
if (TestClearPageMlocked(page)) {
139+
unsigned long flags;
140+
141+
local_irq_save(flags);
142+
__dec_zone_page_state(page, NR_MLOCK);
136143
SetPageMlocked(newpage);
144+
__inc_zone_page_state(newpage, NR_MLOCK);
145+
local_irq_restore(flags);
146+
}
137147
}
138148

139149

‎mm/mlock.c‎

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ void __clear_page_mlock(struct page *page)
6060
return;
6161
}
6262

63+
dec_zone_page_state(page, NR_MLOCK);
64+
count_vm_event(UNEVICTABLE_PGCLEARED);
6365
if (!isolate_lru_page(page)) {
6466
putback_lru_page(page);
6567
} else {
@@ -69,6 +71,9 @@ void __clear_page_mlock(struct page *page)
6971
lru_add_drain_all();
7072
if (!isolate_lru_page(page))
7173
putback_lru_page(page);
74+
else if (PageUnevictable(page))
75+
count_vm_event(UNEVICTABLE_PGSTRANDED);
76+
7277
}
7378
}
7479

@@ -80,8 +85,12 @@ void mlock_vma_page(struct page *page)
8085
{
8186
BUG_ON(!PageLocked(page));
8287

83-
if (!TestSetPageMlocked(page) && !isolate_lru_page(page))
84-
putback_lru_page(page);
88+
if (!TestSetPageMlocked(page)) {
89+
inc_zone_page_state(page, NR_MLOCK);
90+
count_vm_event(UNEVICTABLE_PGMLOCKED);
91+
if (!isolate_lru_page(page))
92+
putback_lru_page(page);
93+
}
8594
}
8695

8796
/*
@@ -106,9 +115,31 @@ static void munlock_vma_page(struct page *page)
106115
{
107116
BUG_ON(!PageLocked(page));
108117

109-
if (TestClearPageMlocked(page) && !isolate_lru_page(page)) {
110-
try_to_munlock(page);
111-
putback_lru_page(page);
118+
if (TestClearPageMlocked(page)) {
119+
dec_zone_page_state(page, NR_MLOCK);
120+
if (!isolate_lru_page(page)) {
121+
int ret = try_to_munlock(page);
122+
/*
123+
* did try_to_unlock() succeed or punt?
124+
*/
125+
if (ret == SWAP_SUCCESS || ret == SWAP_AGAIN)
126+
count_vm_event(UNEVICTABLE_PGMUNLOCKED);
127+
128+
putback_lru_page(page);
129+
} else {
130+
/*
131+
* We lost the race. let try_to_unmap() deal
132+
* with it. At least we get the page state and
133+
* mlock stats right. However, page is still on
134+
* the noreclaim list. We'll fix that up when
135+
* the page is eventually freed or we scan the
136+
* noreclaim list.
137+
*/
138+
if (PageUnevictable(page))
139+
count_vm_event(UNEVICTABLE_PGSTRANDED);
140+
else
141+
count_vm_event(UNEVICTABLE_PGMUNLOCKED);
142+
}
112143
}
113144
}
114145

‎mm/vmstat.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ static const char * const vmstat_text[] = {
625625
"nr_active_file",
626626
#ifdef CONFIG_UNEVICTABLE_LRU
627627
"nr_unevictable",
628+
"nr_mlock",
628629
#endif
629630
"nr_anon_pages",
630631
"nr_mapped",
@@ -684,6 +685,10 @@ static const char * const vmstat_text[] = {
684685
"unevictable_pgs_culled",
685686
"unevictable_pgs_scanned",
686687
"unevictable_pgs_rescued",
688+
"unevictable_pgs_mlocked",
689+
"unevictable_pgs_munlocked",
690+
"unevictable_pgs_cleared",
691+
"unevictable_pgs_stranded",
687692
#endif
688693
#endif
689694
};

0 commit comments

Comments
 (0)