android_kernel_samsung_sm8650/mm/damon/ops-common.c
Greg Kroah-Hartman a01e106f08 Merge branch 'android14-6.1' into branch 'android14-6.1-lts'
This catches the android14-6.1-lts branch up with the latest changes and
abi updates.  Included in here are the following commits:

07775f9683 ANDROID: GKI: Add symbols for rockchip sata
f44d373b32 ANDROID: sched: Add trace_android_rvh_setscheduler
efa8f34b5a ANDROID: Update the ABI symbol list
cee8ebf7c5 ANDROID: GKI: build damon for monitoring virtual address spaces
31c59d59c7 UPSTREAM: mm/damon/sysfs-schemes: handle tried region directory allocation failure
1cedfc05e9 UPSTREAM: mm/damon/sysfs-schemes: handle tried regions sysfs directory allocation failure
7fbeab3c65 UPSTREAM: mm/damon/sysfs: check error from damon_sysfs_update_target()
606444fd06 UPSTREAM: mm/damon/sysfs: eliminate potential uninitialized variable warning
c132d077eb UPSTREAM: mm/damon/sysfs: update monitoring target regions for online input commit
6b7c4cc262 UPSTREAM: mm/damon/sysfs: remove requested targets when online-commit inputs
1e19db10e7 UPSTREAM: mm/damon/sysfs: avoid empty scheme tried regions for large apply interval
c194e597cb UPSTREAM: mm/damon/sysfs-schemes: do not update tried regions more than one DAMON snapshot
f5a0a8bc43 UPSTREAM: mm/damon/sysfs: check DAMOS regions update progress from before_terminate()
b46391e092 UPSTREAM: mm/damon/sysfs: implement a command for updating only schemes tried total bytes
7d48e19f74 UPSTREAM: mm/damon/sysfs-schemes: implement DAMOS tried total bytes file
a548d90994 UPSTREAM: mm/damon/ops-common: refactor to use {pte|pmd}p_clear_young_notify()
ea215c9a10 UPSTREAM: mm/damon/core: skip apply schemes if empty
3ca21ef5fa UPSTREAM: mm/damon: use kstrtobool() instead of strtobool()
5bf7b56860 UPSTREAM: mm/damon/sysfs-schemes: implement DAMOS-tried regions clear command
80ccab9b0e UPSTREAM: mm/damon/sysfs: implement DAMOS tried regions update command
3421250b35 UPSTREAM: mm/damon/sysfs-schemes: implement scheme region directory
b4c34cc168 UPSTREAM: mm/damon/sysfs-schemes: implement schemes/tried_regions directory
b5d1f3576b UPSTREAM: mm/damon/core: add a callback for scheme target regions check
6547a97f32 UPSTREAM: mm/damon/lru_sort: enable and disable synchronously
540e9b850d UPSTREAM: mm/damon/reclaim: enable and disable synchronously
4e2d3f8e31 UPSTREAM: mm/damon/{reclaim,lru_sort}: remove unnecessarily included headers
3c0bc73f6e UPSTREAM: mm/damon/modules: deduplicate init steps for DAMON context setup
67ef7b0f42 UPSTREAM: mm/damon/sysfs: split out schemes directory implementation to separate file
0b17df8a4f UPSTREAM: mm/damon/sysfs: split out kdamond-independent schemes stats update logic into a new function
a45dff567c UPSTREAM: mm/damon/sysfs: move unsigned long range directory to common module
c5038d80ce UPSTREAM: mm/damon/sysfs: move sysfs_lock to common module
b7fc8d59a5 UPSTREAM: mm/damon/sysfs: remove parameters of damon_sysfs_region_alloc()
19364f11a4 UPSTREAM: mm/damon/sysfs: use damon_addr_range for region's start and end values
b6e6b1dbf8 UPSTREAM: mm/damon/core: split out scheme quota adjustment logic into a new function
43475d9708 UPSTREAM: mm/damon/core: split out scheme stat update logic into a new function
0b0a43029e UPSTREAM: mm/damon/core: split damos application logic into a new function
6c7495f04a UPSTREAM: mm/damon/core: split out DAMOS-charged region skip logic into a new function
ac1031618a ANDROID: Snapshot Mainline's version of checkpatch.pl
4fa87d4d8f ANDROID: KVM: arm64: Skip prefaulting ptes which will be modified later
fbc707442c ANDROID: KVM: arm64: Introduce module_change_host_prot_range
fd720ebc6a ANDROID: KVM: arm64: Relax checks in module_change_host_page_prot
f082d22541 ANDROID: KVM: arm64: Optimise module_change_host_page_prot
01dd8c280b ANDROID: KVM: arm64: Prefault entries when splitting a block mapping
cc653d701f ANDROID: virt: gunyah: Zero state_data after vcpu_run
cc294d9503 ANDROID: Update the ABI symbol list
956a0d3998 ANDROID: fs: Add vendor hooks for ep_create_wakeup_source & timerfd_create
d8d2b95fd0 ANDROID: ABI: update symbol list for galaxy
bcc758eed7 Reapply "binder: fix UAF caused by faulty buffer cleanup"
b2b3a1e6d1 UPSTREAM: x86/sev: Check for user-space IOIO pointing to kernel space
62b97630d4 UPSTREAM: x86/sev: Check IOBM for IOIO exceptions from user-space
071c14698c FROMGIT: usb: typec: tcpm: skip checking port->send_discover in PD3.0
a9567a35d0 ANDROID: arm64: Disable workaround for CPU errata 2441007 and 2441009

Change-Id: Icbda2fae389ea4c2e7230821c59ac0380a35d756
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-12-19 19:05:29 +00:00

118 lines
2.8 KiB
C

// SPDX-License-Identifier: GPL-2.0
/*
* Common Primitives for Data Access Monitoring
*
* Author: SeongJae Park <sj@kernel.org>
*/
#include <linux/mmu_notifier.h>
#include <linux/page_idle.h>
#include <linux/pagemap.h>
#include <linux/rmap.h>
#include "ops-common.h"
/*
* Get an online page for a pfn if it's in the LRU list. Otherwise, returns
* NULL.
*
* The body of this function is stolen from the 'page_idle_get_page()'. We
* steal rather than reuse it because the code is quite simple.
*/
struct page *damon_get_page(unsigned long pfn)
{
struct page *page = pfn_to_online_page(pfn);
if (!page || !PageLRU(page) || !get_page_unless_zero(page))
return NULL;
if (unlikely(!PageLRU(page))) {
put_page(page);
page = NULL;
}
return page;
}
void damon_ptep_mkold(pte_t *pte, struct vm_area_struct *vma, unsigned long addr)
{
struct page *page = damon_get_page(pte_pfn(*pte));
if (!page)
return;
if (ptep_clear_young_notify(vma, addr, pte))
set_page_young(page);
set_page_idle(page);
put_page(page);
}
void damon_pmdp_mkold(pmd_t *pmd, struct vm_area_struct *vma, unsigned long addr)
{
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
struct page *page = damon_get_page(pmd_pfn(*pmd));
if (!page)
return;
if (pmdp_clear_young_notify(vma, addr, pmd))
set_page_young(page);
set_page_idle(page);
put_page(page);
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
}
#define DAMON_MAX_SUBSCORE (100)
#define DAMON_MAX_AGE_IN_LOG (32)
int damon_hot_score(struct damon_ctx *c, struct damon_region *r,
struct damos *s)
{
int freq_subscore;
unsigned int age_in_sec;
int age_in_log, age_subscore;
unsigned int freq_weight = s->quota.weight_nr_accesses;
unsigned int age_weight = s->quota.weight_age;
int hotness;
freq_subscore = r->nr_accesses * DAMON_MAX_SUBSCORE /
damon_max_nr_accesses(&c->attrs);
age_in_sec = (unsigned long)r->age * c->attrs.aggr_interval / 1000000;
for (age_in_log = 0; age_in_log < DAMON_MAX_AGE_IN_LOG && age_in_sec;
age_in_log++, age_in_sec >>= 1)
;
/* If frequency is 0, higher age means it's colder */
if (freq_subscore == 0)
age_in_log *= -1;
/*
* Now age_in_log is in [-DAMON_MAX_AGE_IN_LOG, DAMON_MAX_AGE_IN_LOG].
* Scale it to be in [0, 100] and set it as age subscore.
*/
age_in_log += DAMON_MAX_AGE_IN_LOG;
age_subscore = age_in_log * DAMON_MAX_SUBSCORE /
DAMON_MAX_AGE_IN_LOG / 2;
hotness = (freq_weight * freq_subscore + age_weight * age_subscore);
if (freq_weight + age_weight)
hotness /= freq_weight + age_weight;
/*
* Transform it to fit in [0, DAMOS_MAX_SCORE]
*/
hotness = hotness * DAMOS_MAX_SCORE / DAMON_MAX_SUBSCORE;
return hotness;
}
int damon_cold_score(struct damon_ctx *c, struct damon_region *r,
struct damos *s)
{
int hotness = damon_hot_score(c, r, s);
/* Return coldness of the region */
return DAMOS_MAX_SCORE - hotness;
}