linux/include/linux/page_ref.h

/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _LINUX_PAGE_REF_H
#define _LINUX_PAGE_REF_H

#include <linux/atomic.h>
#include <linux/mm_types.h>
#include <linux/page-flags.h>
#include <linux/tracepoint-defs.h>

DECLARE_TRACEPOINT();
DECLARE_TRACEPOINT();
DECLARE_TRACEPOINT();
DECLARE_TRACEPOINT();
DECLARE_TRACEPOINT();
DECLARE_TRACEPOINT();
DECLARE_TRACEPOINT();

#ifdef CONFIG_DEBUG_PAGE_REF

/*
 * Ideally we would want to use the trace_<tracepoint>_enabled() helper
 * functions. But due to include header file issues, that is not
 * feasible. Instead we have to open code the static key functions.
 *
 * See trace_##name##_enabled(void) in include/linux/tracepoint.h
 */
#define page_ref_tracepoint_active(t)

extern void __page_ref_set(struct page *page, int v);
extern void __page_ref_mod(struct page *page, int v);
extern void __page_ref_mod_and_test(struct page *page, int v, int ret);
extern void __page_ref_mod_and_return(struct page *page, int v, int ret);
extern void __page_ref_mod_unless(struct page *page, int v, int u);
extern void __page_ref_freeze(struct page *page, int v, int ret);
extern void __page_ref_unfreeze(struct page *page, int v);

#else

#define page_ref_tracepoint_active

static inline void __page_ref_set(struct page *page, int v)
{
}
static inline void __page_ref_mod(struct page *page, int v)
{
}
static inline void __page_ref_mod_and_test(struct page *page, int v, int ret)
{
}
static inline void __page_ref_mod_and_return(struct page *page, int v, int ret)
{
}
static inline void __page_ref_mod_unless(struct page *page, int v, int u)
{
}
static inline void __page_ref_freeze(struct page *page, int v, int ret)
{
}
static inline void __page_ref_unfreeze(struct page *page, int v)
{
}

#endif

static inline int page_ref_count(const struct page *page)
{}

/**
 * folio_ref_count - The reference count on this folio.
 * @folio: The folio.
 *
 * The refcount is usually incremented by calls to folio_get() and
 * decremented by calls to folio_put().  Some typical users of the
 * folio refcount:
 *
 * - Each reference from a page table
 * - The page cache
 * - Filesystem private data
 * - The LRU list
 * - Pipes
 * - Direct IO which references this page in the process address space
 *
 * Return: The number of references to this folio.
 */
static inline int folio_ref_count(const struct folio *folio)
{}

static inline int page_count(const struct page *page)
{}

static inline void set_page_count(struct page *page, int v)
{}

static inline void folio_set_count(struct folio *folio, int v)
{}

/*
 * Setup the page count before being freed into the page allocator for
 * the first time (boot or memory hotplug)
 */
static inline void init_page_count(struct page *page)
{}

static inline void page_ref_add(struct page *page, int nr)
{}

static inline void folio_ref_add(struct folio *folio, int nr)
{}

static inline void page_ref_sub(struct page *page, int nr)
{}

static inline void folio_ref_sub(struct folio *folio, int nr)
{}

static inline int folio_ref_sub_return(struct folio *folio, int nr)
{}

static inline void page_ref_inc(struct page *page)
{}

static inline void folio_ref_inc(struct folio *folio)
{}

static inline void page_ref_dec(struct page *page)
{}

static inline void folio_ref_dec(struct folio *folio)
{}

static inline int page_ref_sub_and_test(struct page *page, int nr)
{}

static inline int folio_ref_sub_and_test(struct folio *folio, int nr)
{}

static inline int page_ref_inc_return(struct page *page)
{}

static inline int folio_ref_inc_return(struct folio *folio)
{}

static inline int page_ref_dec_and_test(struct page *page)
{}

static inline int folio_ref_dec_and_test(struct folio *folio)
{}

static inline int page_ref_dec_return(struct page *page)
{}

static inline int folio_ref_dec_return(struct folio *folio)
{}

static inline bool page_ref_add_unless(struct page *page, int nr, int u)
{}

static inline bool folio_ref_add_unless(struct folio *folio, int nr, int u)
{}

/**
 * folio_try_get - Attempt to increase the refcount on a folio.
 * @folio: The folio.
 *
 * If you do not already have a reference to a folio, you can attempt to
 * get one using this function.  It may fail if, for example, the folio
 * has been freed since you found a pointer to it, or it is frozen for
 * the purposes of splitting or migration.
 *
 * Return: True if the reference count was successfully incremented.
 */
static inline bool folio_try_get(struct folio *folio)
{}

static inline bool folio_ref_try_add(struct folio *folio, int count)
{}

static inline int page_ref_freeze(struct page *page, int count)
{}

static inline int folio_ref_freeze(struct folio *folio, int count)
{}

static inline void page_ref_unfreeze(struct page *page, int count)
{}

static inline void folio_ref_unfreeze(struct folio *folio, int count)
{}
#endif