blob: fe32a2210e73af249a4d07a3e4397be001c5ca6e [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Christoph Lameterf6ac2352006-06-30 01:55:32 -07002#ifndef _LINUX_VMSTAT_H
3#define _LINUX_VMSTAT_H
4
5#include <linux/types.h>
6#include <linux/percpu.h>
Christoph Lameter2244b952006-06-30 01:55:33 -07007#include <linux/mmzone.h>
Andrew Mortonf042e702011-05-26 16:25:24 -07008#include <linux/vm_event_item.h>
Arun Sharma600634972011-07-26 16:09:06 -07009#include <linux/atomic.h>
Kemi Wang45180852017-11-15 17:38:22 -080010#include <linux/static_key.h>
Roman Gushchinea426c22020-08-06 23:20:35 -070011#include <linux/mmdebug.h>
Christoph Lameterf6ac2352006-06-30 01:55:32 -070012
Adrian Bunkc748e132008-07-23 21:27:03 -070013extern int sysctl_stat_interval;
14
Kemi Wang45180852017-11-15 17:38:22 -080015#ifdef CONFIG_NUMA
16#define ENABLE_NUMA_STAT 1
17#define DISABLE_NUMA_STAT 0
18extern int sysctl_vm_numa_stat;
19DECLARE_STATIC_KEY_TRUE(vm_numa_stat_key);
Christoph Hellwig32927392020-04-24 08:43:38 +020020int sysctl_vm_numa_stat_handler(struct ctl_table *table, int write,
21 void *buffer, size_t *length, loff_t *ppos);
Kemi Wang45180852017-11-15 17:38:22 -080022#endif
23
Steven Rostedtd51d1e62018-04-10 16:28:07 -070024struct reclaim_stat {
25 unsigned nr_dirty;
26 unsigned nr_unqueued_dirty;
27 unsigned nr_congested;
28 unsigned nr_writeback;
29 unsigned nr_immediate;
Johannes Weiner96f8bf42020-06-03 16:03:09 -070030 unsigned nr_pageout;
Yu Zhaoed017372020-10-15 20:09:55 -070031 unsigned nr_activate[ANON_AND_FILE];
Steven Rostedtd51d1e62018-04-10 16:28:07 -070032 unsigned nr_ref_keep;
33 unsigned nr_unmap_fail;
Jaewon Kim1f318a9b2020-06-03 16:01:15 -070034 unsigned nr_lazyfree_fail;
Steven Rostedtd51d1e62018-04-10 16:28:07 -070035};
36
Konstantin Khlebnikov9d7ea9a2019-12-04 16:49:50 -080037enum writeback_stat_item {
38 NR_DIRTY_THRESHOLD,
39 NR_DIRTY_BG_THRESHOLD,
40 NR_VM_WRITEBACK_STAT_ITEMS,
41};
42
Andrew Morton780a0652007-02-10 01:44:41 -080043#ifdef CONFIG_VM_EVENT_COUNTERS
44/*
45 * Light weight per cpu counter implementation.
46 *
47 * Counters should only be incremented and no critical kernel component
48 * should rely on the counter values.
49 *
50 * Counters are handled completely inline. On many platforms the code
51 * generated will simply be the increment of a global address.
52 */
53
Christoph Lameterf8891e52006-06-30 01:55:45 -070054struct vm_event_state {
55 unsigned long event[NR_VM_EVENT_ITEMS];
56};
Christoph Lameterf6ac2352006-06-30 01:55:32 -070057
Christoph Lameterf8891e52006-06-30 01:55:45 -070058DECLARE_PER_CPU(struct vm_event_state, vm_event_states);
Christoph Lameterf6ac2352006-06-30 01:55:32 -070059
Christoph Lameter293b6a42014-04-07 15:39:43 -070060/*
61 * vm counters are allowed to be racy. Use raw_cpu_ops to avoid the
62 * local_irq_disable overhead.
63 */
Christoph Lameterf8891e52006-06-30 01:55:45 -070064static inline void __count_vm_event(enum vm_event_item item)
65{
Christoph Lameter293b6a42014-04-07 15:39:43 -070066 raw_cpu_inc(vm_event_states.event[item]);
Christoph Lameterf8891e52006-06-30 01:55:45 -070067}
Christoph Lameterf6ac2352006-06-30 01:55:32 -070068
Christoph Lameterf8891e52006-06-30 01:55:45 -070069static inline void count_vm_event(enum vm_event_item item)
70{
Rusty Russelldd17c8f2009-10-29 22:34:15 +090071 this_cpu_inc(vm_event_states.event[item]);
Christoph Lameterf8891e52006-06-30 01:55:45 -070072}
Christoph Lameterf6ac2352006-06-30 01:55:32 -070073
Christoph Lameterf8891e52006-06-30 01:55:45 -070074static inline void __count_vm_events(enum vm_event_item item, long delta)
75{
Christoph Lameter293b6a42014-04-07 15:39:43 -070076 raw_cpu_add(vm_event_states.event[item], delta);
Christoph Lameterf8891e52006-06-30 01:55:45 -070077}
Christoph Lameterf6ac2352006-06-30 01:55:32 -070078
Christoph Lameterf8891e52006-06-30 01:55:45 -070079static inline void count_vm_events(enum vm_event_item item, long delta)
80{
Rusty Russelldd17c8f2009-10-29 22:34:15 +090081 this_cpu_add(vm_event_states.event[item], delta);
Christoph Lameterf8891e52006-06-30 01:55:45 -070082}
Christoph Lameterf6ac2352006-06-30 01:55:32 -070083
Christoph Lameterf8891e52006-06-30 01:55:45 -070084extern void all_vm_events(unsigned long *);
Yijing Wangf1cb0872013-04-29 15:08:14 -070085
Christoph Lameterf8891e52006-06-30 01:55:45 -070086extern void vm_events_fold_cpu(int cpu);
Christoph Lameterf6ac2352006-06-30 01:55:32 -070087
Christoph Lameterf8891e52006-06-30 01:55:45 -070088#else
Christoph Lameterf6ac2352006-06-30 01:55:32 -070089
Christoph Lameterf8891e52006-06-30 01:55:45 -070090/* Disable counters */
Andrew Morton780a0652007-02-10 01:44:41 -080091static inline void count_vm_event(enum vm_event_item item)
92{
93}
94static inline void count_vm_events(enum vm_event_item item, long delta)
95{
96}
97static inline void __count_vm_event(enum vm_event_item item)
98{
99}
100static inline void __count_vm_events(enum vm_event_item item, long delta)
101{
102}
103static inline void all_vm_events(unsigned long *ret)
104{
105}
106static inline void vm_events_fold_cpu(int cpu)
107{
108}
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700109
Christoph Lameterf8891e52006-06-30 01:55:45 -0700110#endif /* CONFIG_VM_EVENT_COUNTERS */
111
Mel Gorman03c5a6e2012-11-02 14:52:48 +0000112#ifdef CONFIG_NUMA_BALANCING
113#define count_vm_numa_event(x) count_vm_event(x)
114#define count_vm_numa_events(x, y) count_vm_events(x, y)
115#else
116#define count_vm_numa_event(x) do {} while (0)
Mel Gorman3c0ff462013-02-22 16:34:29 -0800117#define count_vm_numa_events(x, y) do { (void)(y); } while (0)
Mel Gorman03c5a6e2012-11-02 14:52:48 +0000118#endif /* CONFIG_NUMA_BALANCING */
119
Mel Gormanec659932014-01-21 14:33:16 -0800120#ifdef CONFIG_DEBUG_TLBFLUSH
121#define count_vm_tlb_event(x) count_vm_event(x)
122#define count_vm_tlb_events(x, y) count_vm_events(x, y)
123#else
124#define count_vm_tlb_event(x) do {} while (0)
125#define count_vm_tlb_events(x, y) do { (void)(y); } while (0)
126#endif
127
Davidlohr Bueso4f115142014-06-04 16:06:46 -0700128#ifdef CONFIG_DEBUG_VM_VMACACHE
129#define count_vm_vmacache_event(x) count_vm_event(x)
130#else
131#define count_vm_vmacache_event(x) do {} while (0)
132#endif
133
Mel Gorman16709d12016-07-28 15:46:56 -0700134#define __count_zid_vm_events(item, zid, delta) \
135 __count_vm_events(item##_NORMAL - ZONE_NORMAL + zid, delta)
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700136
Christoph Lameter2244b952006-06-30 01:55:33 -0700137/*
Mel Gorman75ef7182016-07-28 15:45:24 -0700138 * Zone and node-based page accounting with per cpu differentials.
Christoph Lameter2244b952006-06-30 01:55:33 -0700139 */
Mel Gorman75ef7182016-07-28 15:45:24 -0700140extern atomic_long_t vm_zone_stat[NR_VM_ZONE_STAT_ITEMS];
Mel Gorman75ef7182016-07-28 15:45:24 -0700141extern atomic_long_t vm_node_stat[NR_VM_NODE_STAT_ITEMS];
Mel Gormanf19298b2021-06-28 19:41:44 -0700142extern atomic_long_t vm_numa_event[NR_VM_NUMA_EVENT_ITEMS];
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700143
Kemi Wang3a321d22017-09-08 16:12:48 -0700144#ifdef CONFIG_NUMA
Mel Gormanf19298b2021-06-28 19:41:44 -0700145static inline void zone_numa_event_add(long x, struct zone *zone,
146 enum numa_stat_item item)
Kemi Wang3a321d22017-09-08 16:12:48 -0700147{
Mel Gormanf19298b2021-06-28 19:41:44 -0700148 atomic_long_add(x, &zone->vm_numa_event[item]);
149 atomic_long_add(x, &vm_numa_event[item]);
Kemi Wang3a321d22017-09-08 16:12:48 -0700150}
151
Mel Gormanf19298b2021-06-28 19:41:44 -0700152static inline unsigned long zone_numa_event_state(struct zone *zone,
Kemi Wang3a321d22017-09-08 16:12:48 -0700153 enum numa_stat_item item)
154{
Mel Gormanf19298b2021-06-28 19:41:44 -0700155 return atomic_long_read(&zone->vm_numa_event[item]);
156}
Kemi Wang63803222017-09-08 16:12:55 -0700157
Mel Gormanf19298b2021-06-28 19:41:44 -0700158static inline unsigned long
159global_numa_event_state(enum numa_stat_item item)
160{
161 return atomic_long_read(&vm_numa_event[item]);
Kemi Wang3a321d22017-09-08 16:12:48 -0700162}
163#endif /* CONFIG_NUMA */
164
Christoph Lameter2244b952006-06-30 01:55:33 -0700165static inline void zone_page_state_add(long x, struct zone *zone,
166 enum zone_stat_item item)
167{
168 atomic_long_add(x, &zone->vm_stat[item]);
Mel Gorman75ef7182016-07-28 15:45:24 -0700169 atomic_long_add(x, &vm_zone_stat[item]);
170}
171
172static inline void node_page_state_add(long x, struct pglist_data *pgdat,
173 enum node_stat_item item)
174{
175 atomic_long_add(x, &pgdat->vm_stat[item]);
176 atomic_long_add(x, &vm_node_stat[item]);
Christoph Lameter2244b952006-06-30 01:55:33 -0700177}
178
Michal Hockoc41f0122017-09-06 16:23:36 -0700179static inline unsigned long global_zone_page_state(enum zone_stat_item item)
Christoph Lameter2244b952006-06-30 01:55:33 -0700180{
Mel Gorman75ef7182016-07-28 15:45:24 -0700181 long x = atomic_long_read(&vm_zone_stat[item]);
182#ifdef CONFIG_SMP
183 if (x < 0)
184 x = 0;
185#endif
186 return x;
187}
188
Roman Gushchinea426c22020-08-06 23:20:35 -0700189static inline
190unsigned long global_node_page_state_pages(enum node_stat_item item)
Mel Gorman75ef7182016-07-28 15:45:24 -0700191{
192 long x = atomic_long_read(&vm_node_stat[item]);
Christoph Lameter2244b952006-06-30 01:55:33 -0700193#ifdef CONFIG_SMP
194 if (x < 0)
195 x = 0;
196#endif
197 return x;
198}
199
Roman Gushchinea426c22020-08-06 23:20:35 -0700200static inline unsigned long global_node_page_state(enum node_stat_item item)
201{
202 VM_WARN_ON_ONCE(vmstat_item_in_bytes(item));
203
204 return global_node_page_state_pages(item);
205}
206
Christoph Lameter2244b952006-06-30 01:55:33 -0700207static inline unsigned long zone_page_state(struct zone *zone,
208 enum zone_stat_item item)
209{
210 long x = atomic_long_read(&zone->vm_stat[item]);
211#ifdef CONFIG_SMP
212 if (x < 0)
213 x = 0;
214#endif
215 return x;
216}
217
Christoph Lameteraa454842010-09-09 16:38:17 -0700218/*
219 * More accurate version that also considers the currently pending
220 * deltas. For that we need to loop over all cpus to find the current
221 * deltas. There is no synchronization so the result cannot be
222 * exactly accurate either.
223 */
224static inline unsigned long zone_page_state_snapshot(struct zone *zone,
225 enum zone_stat_item item)
226{
227 long x = atomic_long_read(&zone->vm_stat[item]);
228
229#ifdef CONFIG_SMP
230 int cpu;
231 for_each_online_cpu(cpu)
Mel Gorman28f836b2021-06-28 19:41:38 -0700232 x += per_cpu_ptr(zone->per_cpu_zonestats, cpu)->vm_stat_diff[item];
Christoph Lameteraa454842010-09-09 16:38:17 -0700233
234 if (x < 0)
235 x = 0;
236#endif
237 return x;
238}
239
Christoph Lameter2244b952006-06-30 01:55:33 -0700240#ifdef CONFIG_NUMA
Mel Gorman3ac44a32021-06-28 19:41:47 -0700241/* See __count_vm_event comment on why raw_cpu_inc is used. */
242static inline void
243__count_numa_event(struct zone *zone, enum numa_stat_item item)
244{
245 struct per_cpu_zonestat __percpu *pzstats = zone->per_cpu_zonestats;
246
247 raw_cpu_inc(pzstats->vm_numa_event[item]);
248}
249
Mel Gorman75ef7182016-07-28 15:45:24 -0700250extern unsigned long sum_zone_node_page_state(int node,
Kemi Wang3a321d22017-09-08 16:12:48 -0700251 enum zone_stat_item item);
Mel Gormanf19298b2021-06-28 19:41:44 -0700252extern unsigned long sum_zone_numa_event_state(int node, enum numa_stat_item item);
Mel Gorman75ef7182016-07-28 15:45:24 -0700253extern unsigned long node_page_state(struct pglist_data *pgdat,
254 enum node_stat_item item);
Roman Gushchinea426c22020-08-06 23:20:35 -0700255extern unsigned long node_page_state_pages(struct pglist_data *pgdat,
256 enum node_stat_item item);
Mel Gormanf19298b2021-06-28 19:41:44 -0700257extern void fold_vm_numa_events(void);
Christoph Lameter2244b952006-06-30 01:55:33 -0700258#else
Michal Hockoc41f0122017-09-06 16:23:36 -0700259#define sum_zone_node_page_state(node, item) global_zone_page_state(item)
Mel Gorman75ef7182016-07-28 15:45:24 -0700260#define node_page_state(node, item) global_node_page_state(item)
Roman Gushchinea426c22020-08-06 23:20:35 -0700261#define node_page_state_pages(node, item) global_node_page_state_pages(item)
Mel Gormanf19298b2021-06-28 19:41:44 -0700262static inline void fold_vm_numa_events(void)
263{
264}
Christoph Lameterca889e62006-06-30 01:55:44 -0700265#endif /* CONFIG_NUMA */
Christoph Lameter2244b952006-06-30 01:55:33 -0700266
Christoph Lameter2244b952006-06-30 01:55:33 -0700267#ifdef CONFIG_SMP
Heiko Carstens6cdb18a2015-12-29 14:54:32 -0800268void __mod_zone_page_state(struct zone *, enum zone_stat_item item, long);
Christoph Lameter2244b952006-06-30 01:55:33 -0700269void __inc_zone_page_state(struct page *, enum zone_stat_item);
270void __dec_zone_page_state(struct page *, enum zone_stat_item);
271
Mel Gorman75ef7182016-07-28 15:45:24 -0700272void __mod_node_page_state(struct pglist_data *, enum node_stat_item item, long);
273void __inc_node_page_state(struct page *, enum node_stat_item);
274void __dec_node_page_state(struct page *, enum node_stat_item);
275
Heiko Carstens6cdb18a2015-12-29 14:54:32 -0800276void mod_zone_page_state(struct zone *, enum zone_stat_item, long);
Christoph Lameter2244b952006-06-30 01:55:33 -0700277void inc_zone_page_state(struct page *, enum zone_stat_item);
278void dec_zone_page_state(struct page *, enum zone_stat_item);
279
Mel Gorman75ef7182016-07-28 15:45:24 -0700280void mod_node_page_state(struct pglist_data *, enum node_stat_item, long);
281void inc_node_page_state(struct page *, enum node_stat_item);
282void dec_node_page_state(struct page *, enum node_stat_item);
283
Mel Gorman75ef7182016-07-28 15:45:24 -0700284extern void inc_node_state(struct pglist_data *, enum node_stat_item);
Christoph Lameterc8785382007-02-10 01:43:01 -0800285extern void __inc_zone_state(struct zone *, enum zone_stat_item);
Mel Gorman75ef7182016-07-28 15:45:24 -0700286extern void __inc_node_state(struct pglist_data *, enum node_stat_item);
Christoph Lameterc8785382007-02-10 01:43:01 -0800287extern void dec_zone_state(struct zone *, enum zone_stat_item);
288extern void __dec_zone_state(struct zone *, enum zone_stat_item);
Mel Gorman75ef7182016-07-28 15:45:24 -0700289extern void __dec_node_state(struct pglist_data *, enum node_stat_item);
Christoph Lameter2244b952006-06-30 01:55:33 -0700290
Christoph Lameter0eb77e92016-01-14 15:21:40 -0800291void quiet_vmstat(void);
Christoph Lameter2bb921e2013-09-11 14:21:30 -0700292void cpu_vm_stats_fold(int cpu);
KOSAKI Motohiroa6cccdc2011-05-24 17:11:33 -0700293void refresh_zone_stat_thresholds(void);
Mel Gormanb44129b2011-01-13 15:45:43 -0800294
Hugh Dickins52b6f462016-05-19 17:12:50 -0700295struct ctl_table;
Christoph Hellwig32927392020-04-24 08:43:38 +0200296int vmstat_refresh(struct ctl_table *, int write, void *buffer, size_t *lenp,
297 loff_t *ppos);
Hugh Dickins52b6f462016-05-19 17:12:50 -0700298
Mel Gorman28f836b2021-06-28 19:41:38 -0700299void drain_zonestat(struct zone *zone, struct per_cpu_zonestat *);
Minchan Kim5a883812012-10-08 16:33:39 -0700300
Mel Gormanb44129b2011-01-13 15:45:43 -0800301int calculate_pressure_threshold(struct zone *zone);
302int calculate_normal_threshold(struct zone *zone);
303void set_pgdat_percpu_threshold(pg_data_t *pgdat,
304 int (*calculate_pressure)(struct zone *));
Christoph Lameter2244b952006-06-30 01:55:33 -0700305#else /* CONFIG_SMP */
306
307/*
308 * We do not maintain differentials in a single processor configuration.
309 * The functions directly modify the zone and global counters.
310 */
311static inline void __mod_zone_page_state(struct zone *zone,
Heiko Carstens6cdb18a2015-12-29 14:54:32 -0800312 enum zone_stat_item item, long delta)
Christoph Lameter2244b952006-06-30 01:55:33 -0700313{
314 zone_page_state_add(delta, zone, item);
315}
316
Mel Gorman75ef7182016-07-28 15:45:24 -0700317static inline void __mod_node_page_state(struct pglist_data *pgdat,
318 enum node_stat_item item, int delta)
319{
Roman Gushchinbe458312020-10-01 13:07:49 -0700320 if (vmstat_item_in_bytes(item)) {
Johannes Weiner629484a2021-02-25 17:16:51 -0800321 /*
322 * Only cgroups use subpage accounting right now; at
323 * the global level, these items still change in
324 * multiples of whole pages. Store them as pages
325 * internally to keep the per-cpu counters compact.
326 */
Roman Gushchinbe458312020-10-01 13:07:49 -0700327 VM_WARN_ON_ONCE(delta & (PAGE_SIZE - 1));
328 delta >>= PAGE_SHIFT;
329 }
330
Mel Gorman75ef7182016-07-28 15:45:24 -0700331 node_page_state_add(delta, pgdat, item);
332}
333
Christoph Lameter7f4599e2006-07-10 04:44:30 -0700334static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
335{
336 atomic_long_inc(&zone->vm_stat[item]);
Mel Gorman75ef7182016-07-28 15:45:24 -0700337 atomic_long_inc(&vm_zone_stat[item]);
338}
339
340static inline void __inc_node_state(struct pglist_data *pgdat, enum node_stat_item item)
341{
342 atomic_long_inc(&pgdat->vm_stat[item]);
343 atomic_long_inc(&vm_node_stat[item]);
Christoph Lameter7f4599e2006-07-10 04:44:30 -0700344}
345
Christoph Lameterc8785382007-02-10 01:43:01 -0800346static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
347{
348 atomic_long_dec(&zone->vm_stat[item]);
Mel Gorman75ef7182016-07-28 15:45:24 -0700349 atomic_long_dec(&vm_zone_stat[item]);
350}
351
352static inline void __dec_node_state(struct pglist_data *pgdat, enum node_stat_item item)
353{
354 atomic_long_dec(&pgdat->vm_stat[item]);
355 atomic_long_dec(&vm_node_stat[item]);
Christoph Lameterc8785382007-02-10 01:43:01 -0800356}
357
Johannes Weiner6a3ed212014-04-03 14:47:34 -0700358static inline void __inc_zone_page_state(struct page *page,
359 enum zone_stat_item item)
360{
361 __inc_zone_state(page_zone(page), item);
362}
363
Mel Gorman75ef7182016-07-28 15:45:24 -0700364static inline void __inc_node_page_state(struct page *page,
365 enum node_stat_item item)
366{
367 __inc_node_state(page_pgdat(page), item);
368}
369
370
Christoph Lameter2244b952006-06-30 01:55:33 -0700371static inline void __dec_zone_page_state(struct page *page,
372 enum zone_stat_item item)
373{
Uwe Kleine-König57ce36f2008-02-25 16:45:03 +0100374 __dec_zone_state(page_zone(page), item);
Christoph Lameter2244b952006-06-30 01:55:33 -0700375}
376
Mel Gorman75ef7182016-07-28 15:45:24 -0700377static inline void __dec_node_page_state(struct page *page,
378 enum node_stat_item item)
379{
380 __dec_node_state(page_pgdat(page), item);
381}
382
383
Christoph Lameter2244b952006-06-30 01:55:33 -0700384/*
385 * We only use atomic operations to update counters. So there is no need to
386 * disable interrupts.
387 */
388#define inc_zone_page_state __inc_zone_page_state
389#define dec_zone_page_state __dec_zone_page_state
390#define mod_zone_page_state __mod_zone_page_state
391
Mel Gorman75ef7182016-07-28 15:45:24 -0700392#define inc_node_page_state __inc_node_page_state
393#define dec_node_page_state __dec_node_page_state
394#define mod_node_page_state __mod_node_page_state
395
Johannes Weiner6a3ed212014-04-03 14:47:34 -0700396#define inc_zone_state __inc_zone_state
Mel Gorman75ef7182016-07-28 15:45:24 -0700397#define inc_node_state __inc_node_state
Johannes Weiner6a3ed212014-04-03 14:47:34 -0700398#define dec_zone_state __dec_zone_state
399
Mel Gormanb44129b2011-01-13 15:45:43 -0800400#define set_pgdat_percpu_threshold(pgdat, callback) { }
Mel Gorman88f5acf2011-01-13 15:45:41 -0800401
KOSAKI Motohiroa6cccdc2011-05-24 17:11:33 -0700402static inline void refresh_zone_stat_thresholds(void) { }
Christoph Lameter2bb921e2013-09-11 14:21:30 -0700403static inline void cpu_vm_stats_fold(int cpu) { }
Christoph Lameter0eb77e92016-01-14 15:21:40 -0800404static inline void quiet_vmstat(void) { }
KOSAKI Motohiroa6cccdc2011-05-24 17:11:33 -0700405
Minchan Kim5a883812012-10-08 16:33:39 -0700406static inline void drain_zonestat(struct zone *zone,
Mel Gorman28f836b2021-06-28 19:41:38 -0700407 struct per_cpu_zonestat *pzstats) { }
KOSAKI Motohirofa25c502011-05-24 17:11:28 -0700408#endif /* CONFIG_SMP */
409
Bartlomiej Zolnierkiewiczd1ce7492012-10-08 16:32:02 -0700410static inline void __mod_zone_freepage_state(struct zone *zone, int nr_pages,
411 int migratetype)
412{
413 __mod_zone_page_state(zone, NR_FREE_PAGES, nr_pages);
414 if (is_migrate_cma(migratetype))
415 __mod_zone_page_state(zone, NR_FREE_CMA_PAGES, nr_pages);
416}
417
KOSAKI Motohirofa25c502011-05-24 17:11:28 -0700418extern const char * const vmstat_text[];
Christoph Lameter2244b952006-06-30 01:55:33 -0700419
Konstantin Khlebnikov9d7ea9a2019-12-04 16:49:50 -0800420static inline const char *zone_stat_name(enum zone_stat_item item)
421{
422 return vmstat_text[item];
423}
424
425#ifdef CONFIG_NUMA
426static inline const char *numa_stat_name(enum numa_stat_item item)
427{
428 return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
429 item];
430}
431#endif /* CONFIG_NUMA */
432
433static inline const char *node_stat_name(enum node_stat_item item)
434{
435 return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
Mel Gormanf19298b2021-06-28 19:41:44 -0700436 NR_VM_NUMA_EVENT_ITEMS +
Konstantin Khlebnikov9d7ea9a2019-12-04 16:49:50 -0800437 item];
438}
439
440static inline const char *lru_list_name(enum lru_list lru)
441{
442 return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
443}
444
445static inline const char *writeback_stat_name(enum writeback_stat_item item)
446{
447 return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
Mel Gormanf19298b2021-06-28 19:41:44 -0700448 NR_VM_NUMA_EVENT_ITEMS +
Konstantin Khlebnikov9d7ea9a2019-12-04 16:49:50 -0800449 NR_VM_NODE_STAT_ITEMS +
450 item];
451}
452
Konstantin Khlebnikovebc5d83d2019-12-04 16:49:53 -0800453#if defined(CONFIG_VM_EVENT_COUNTERS) || defined(CONFIG_MEMCG)
Konstantin Khlebnikov9d7ea9a2019-12-04 16:49:50 -0800454static inline const char *vm_event_name(enum vm_event_item item)
455{
456 return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
Mel Gormanf19298b2021-06-28 19:41:44 -0700457 NR_VM_NUMA_EVENT_ITEMS +
Konstantin Khlebnikov9d7ea9a2019-12-04 16:49:50 -0800458 NR_VM_NODE_STAT_ITEMS +
459 NR_VM_WRITEBACK_STAT_ITEMS +
460 item];
461}
Konstantin Khlebnikovebc5d83d2019-12-04 16:49:53 -0800462#endif /* CONFIG_VM_EVENT_COUNTERS || CONFIG_MEMCG */
Konstantin Khlebnikov9d7ea9a2019-12-04 16:49:50 -0800463
Shakeel Buttc47d5032020-12-14 19:07:14 -0800464#ifdef CONFIG_MEMCG
465
466void __mod_lruvec_state(struct lruvec *lruvec, enum node_stat_item idx,
467 int val);
468
469static inline void mod_lruvec_state(struct lruvec *lruvec,
470 enum node_stat_item idx, int val)
471{
472 unsigned long flags;
473
474 local_irq_save(flags);
475 __mod_lruvec_state(lruvec, idx, val);
476 local_irq_restore(flags);
477}
478
479void __mod_lruvec_page_state(struct page *page,
480 enum node_stat_item idx, int val);
481
482static inline void mod_lruvec_page_state(struct page *page,
483 enum node_stat_item idx, int val)
484{
485 unsigned long flags;
486
487 local_irq_save(flags);
488 __mod_lruvec_page_state(page, idx, val);
489 local_irq_restore(flags);
490}
491
492#else
493
494static inline void __mod_lruvec_state(struct lruvec *lruvec,
495 enum node_stat_item idx, int val)
496{
497 __mod_node_page_state(lruvec_pgdat(lruvec), idx, val);
498}
499
500static inline void mod_lruvec_state(struct lruvec *lruvec,
501 enum node_stat_item idx, int val)
502{
503 mod_node_page_state(lruvec_pgdat(lruvec), idx, val);
504}
505
506static inline void __mod_lruvec_page_state(struct page *page,
507 enum node_stat_item idx, int val)
508{
509 __mod_node_page_state(page_pgdat(page), idx, val);
510}
511
512static inline void mod_lruvec_page_state(struct page *page,
513 enum node_stat_item idx, int val)
514{
515 mod_node_page_state(page_pgdat(page), idx, val);
516}
517
518#endif /* CONFIG_MEMCG */
519
Johannes Weiner1c824a62021-04-29 22:55:32 -0700520static inline void inc_lruvec_state(struct lruvec *lruvec,
521 enum node_stat_item idx)
Shakeel Buttc47d5032020-12-14 19:07:14 -0800522{
Johannes Weiner1c824a62021-04-29 22:55:32 -0700523 mod_lruvec_state(lruvec, idx, 1);
Shakeel Buttc47d5032020-12-14 19:07:14 -0800524}
525
526static inline void __inc_lruvec_page_state(struct page *page,
527 enum node_stat_item idx)
528{
529 __mod_lruvec_page_state(page, idx, 1);
530}
531
532static inline void __dec_lruvec_page_state(struct page *page,
533 enum node_stat_item idx)
534{
535 __mod_lruvec_page_state(page, idx, -1);
536}
537
Shakeel Buttc47d5032020-12-14 19:07:14 -0800538static inline void inc_lruvec_page_state(struct page *page,
539 enum node_stat_item idx)
540{
541 mod_lruvec_page_state(page, idx, 1);
542}
543
544static inline void dec_lruvec_page_state(struct page *page,
545 enum node_stat_item idx)
546{
547 mod_lruvec_page_state(page, idx, -1);
548}
549
Christoph Lameter2244b952006-06-30 01:55:33 -0700550#endif /* _LINUX_VMSTAT_H */