18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _MM_PAGE_REPORTING_H
38c2ecf20Sopenharmony_ci#define _MM_PAGE_REPORTING_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/mmzone.h>
68c2ecf20Sopenharmony_ci#include <linux/pageblock-flags.h>
78c2ecf20Sopenharmony_ci#include <linux/page-isolation.h>
88c2ecf20Sopenharmony_ci#include <linux/jump_label.h>
98c2ecf20Sopenharmony_ci#include <linux/slab.h>
108c2ecf20Sopenharmony_ci#include <linux/pgtable.h>
118c2ecf20Sopenharmony_ci#include <linux/scatterlist.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#define PAGE_REPORTING_MIN_ORDER	pageblock_order
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#ifdef CONFIG_PAGE_REPORTING
168c2ecf20Sopenharmony_ciDECLARE_STATIC_KEY_FALSE(page_reporting_enabled);
178c2ecf20Sopenharmony_civoid __page_reporting_notify(void);
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cistatic inline bool page_reported(struct page *page)
208c2ecf20Sopenharmony_ci{
218c2ecf20Sopenharmony_ci	return static_branch_unlikely(&page_reporting_enabled) &&
228c2ecf20Sopenharmony_ci	       PageReported(page);
238c2ecf20Sopenharmony_ci}
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/**
268c2ecf20Sopenharmony_ci * page_reporting_notify_free - Free page notification to start page processing
278c2ecf20Sopenharmony_ci *
288c2ecf20Sopenharmony_ci * This function is meant to act as a screener for __page_reporting_notify
298c2ecf20Sopenharmony_ci * which will determine if a give zone has crossed over the high-water mark
308c2ecf20Sopenharmony_ci * that will justify us beginning page treatment. If we have crossed that
318c2ecf20Sopenharmony_ci * threshold then it will start the process of pulling some pages and
328c2ecf20Sopenharmony_ci * placing them in the batch list for treatment.
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_cistatic inline void page_reporting_notify_free(unsigned int order)
358c2ecf20Sopenharmony_ci{
368c2ecf20Sopenharmony_ci	/* Called from hot path in __free_one_page() */
378c2ecf20Sopenharmony_ci	if (!static_branch_unlikely(&page_reporting_enabled))
388c2ecf20Sopenharmony_ci		return;
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci	/* Determine if we have crossed reporting threshold */
418c2ecf20Sopenharmony_ci	if (order < PAGE_REPORTING_MIN_ORDER)
428c2ecf20Sopenharmony_ci		return;
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	/* This will add a few cycles, but should be called infrequently */
458c2ecf20Sopenharmony_ci	__page_reporting_notify();
468c2ecf20Sopenharmony_ci}
478c2ecf20Sopenharmony_ci#else /* CONFIG_PAGE_REPORTING */
488c2ecf20Sopenharmony_ci#define page_reported(_page)	false
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cistatic inline void page_reporting_notify_free(unsigned int order)
518c2ecf20Sopenharmony_ci{
528c2ecf20Sopenharmony_ci}
538c2ecf20Sopenharmony_ci#endif /* CONFIG_PAGE_REPORTING */
548c2ecf20Sopenharmony_ci#endif /*_MM_PAGE_REPORTING_H */
55