workingset.c (1136fa0c07de570dc17858745af8be169d1440ba) workingset.c (8927f6473e56e32e328ae8ed43736412f7f76a4e)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Workingset detection
4 *
5 * Copyright (C) 2013 Red Hat, Inc., Johannes Weiner
6 */
7
8#include <linux/memcontrol.h>

--- 231 unchanged lines hidden (view full) ---

240 * the root cgroup's, age as well.
241 */
242 do {
243 atomic_long_add(nr_pages, &lruvec->nonresident_age);
244 } while ((lruvec = parent_lruvec(lruvec)));
245}
246
247/**
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Workingset detection
4 *
5 * Copyright (C) 2013 Red Hat, Inc., Johannes Weiner
6 */
7
8#include <linux/memcontrol.h>

--- 231 unchanged lines hidden (view full) ---

240 * the root cgroup's, age as well.
241 */
242 do {
243 atomic_long_add(nr_pages, &lruvec->nonresident_age);
244 } while ((lruvec = parent_lruvec(lruvec)));
245}
246
247/**
248 * workingset_eviction - note the eviction of a page from memory
248 * workingset_eviction - note the eviction of a folio from memory
249 * @target_memcg: the cgroup that is causing the reclaim
249 * @target_memcg: the cgroup that is causing the reclaim
250 * @page: the page being evicted
250 * @folio: the folio being evicted
251 *
251 *
252 * Return: a shadow entry to be stored in @page->mapping->i_pages in place
253 * of the evicted @page so that a later refault can be detected.
252 * Return: a shadow entry to be stored in @folio->mapping->i_pages in place
253 * of the evicted @folio so that a later refault can be detected.
254 */
254 */
255void *workingset_eviction(struct page *page, struct mem_cgroup *target_memcg)
255void *workingset_eviction(struct folio *folio, struct mem_cgroup *target_memcg)
256{
256{
257 struct pglist_data *pgdat = page_pgdat(page);
257 struct pglist_data *pgdat = folio_pgdat(folio);
258 unsigned long eviction;
259 struct lruvec *lruvec;
260 int memcgid;
261
258 unsigned long eviction;
259 struct lruvec *lruvec;
260 int memcgid;
261
262 /* Page is fully exclusive and pins page's memory cgroup pointer */
263 VM_BUG_ON_PAGE(PageLRU(page), page);
264 VM_BUG_ON_PAGE(page_count(page), page);
265 VM_BUG_ON_PAGE(!PageLocked(page), page);
262 /* Folio is fully exclusive and pins folio's memory cgroup pointer */
263 VM_BUG_ON_FOLIO(folio_test_lru(folio), folio);
264 VM_BUG_ON_FOLIO(folio_ref_count(folio), folio);
265 VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
266
267 lruvec = mem_cgroup_lruvec(target_memcg, pgdat);
268 /* XXX: target_memcg can be NULL, go through lruvec */
269 memcgid = mem_cgroup_id(lruvec_memcg(lruvec));
270 eviction = atomic_long_read(&lruvec->nonresident_age);
266
267 lruvec = mem_cgroup_lruvec(target_memcg, pgdat);
268 /* XXX: target_memcg can be NULL, go through lruvec */
269 memcgid = mem_cgroup_id(lruvec_memcg(lruvec));
270 eviction = atomic_long_read(&lruvec->nonresident_age);
271 workingset_age_nonresident(lruvec, thp_nr_pages(page));
272 return pack_shadow(memcgid, pgdat, eviction, PageWorkingset(page));
271 workingset_age_nonresident(lruvec, folio_nr_pages(folio));
272 return pack_shadow(memcgid, pgdat, eviction,
273 folio_test_workingset(folio));
273}
274
275/**
276 * workingset_refault - Evaluate the refault of a previously evicted folio.
277 * @folio: The freshly allocated replacement folio.
278 * @shadow: Shadow entry of the evicted folio.
279 *
280 * Calculates and evaluates the refault distance of the previously

--- 358 unchanged lines hidden ---
274}
275
276/**
277 * workingset_refault - Evaluate the refault of a previously evicted folio.
278 * @folio: The freshly allocated replacement folio.
279 * @shadow: Shadow entry of the evicted folio.
280 *
281 * Calculates and evaluates the refault distance of the previously

--- 358 unchanged lines hidden ---