video: tegra: nvmap: Account NvMap memory for OOM Decisions

Account NvMap allocated memory into both RSS and CG tracking to make
efficient OOM kill decisions during memory pressure.

NvMap allocates memory via kernel APIs like alloc_pages, the kernel
memory is not accounted on behalf of process who requests the
allocation. Hence in case OOM, the OOM killer never kills the process
who has allocated memory via NvMap even though this process might be
holding most of the memory.

Solve this issue using following approach:
- Use __GFP_ACCOUNT and __GFP_NORETRY flag
-  __GFP_NORETRY will not let the current allocation flow to go into OOM
path, so that it will never trigger OOM.
- __GFP_ACCOUNT causes the allocation to be accounted to kmemcg. So any
allocation done by NvMap will be definitely accounted to kmemcg and
cgroups can be used to define memory limits.
- Add RSS counting for the process which allocates by NvMap, so that OOM
score for that process will get updated and OOM killer can pick this
process based upon the OOM score.
- Every process that has a reference to NvMap Handle would have the
memory size accounted into its RSS. On releasing the reference to
handle, the RSS would be reduced.

Bug 5222690

Change-Id: I3fa9b76ec9fc8d7f805111cb96e11e2ab1db42ce
Signed-off-by: Ketan Patil <ketanp@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3447072
GVS: buildbot_gerritrpt <buildbot_gerritrpt@nvidia.com>
Reviewed-by: Krishna Reddy <vdumpa@nvidia.com>
Reviewed-by: Jon Hunter <jonathanh@nvidia.com>
Reviewed-by: Ajay Nandakumar Mannargudi <anandakumarm@nvidia.com>
This commit is contained in:
Ketan Patil
2025-07-31 09:30:36 +00:00
committed by mobile promotions
parent 6b6d1e009a
commit 858d73775a
7 changed files with 127 additions and 7 deletions

View File

@@ -171,6 +171,7 @@ NV_CONFTEST_FUNCTION_COMPILE_TESTS += kthread_complete_and_exit
NV_CONFTEST_FUNCTION_COMPILE_TESTS += mii_bus_struct_has_read_c45
NV_CONFTEST_FUNCTION_COMPILE_TESTS += mii_bus_struct_has_write_c45
NV_CONFTEST_FUNCTION_COMPILE_TESTS += media_entity_remote_pad
NV_CONFTEST_FUNCTION_COMPILE_TESTS += mm_struct_struct_has_percpu_counter_rss_stat
NV_CONFTEST_FUNCTION_COMPILE_TESTS += module_import_ns_calls_stringify
NV_CONFTEST_FUNCTION_COMPILE_TESTS += mrq_pcie_request_struct_present
NV_CONFTEST_FUNCTION_COMPILE_TESTS += msi_get_virq

View File

@@ -7933,6 +7933,23 @@ compile_test() {
compile_check_conftest "$CODE" "NV_MII_BUS_STRUCT_HAS_WRITE_C45" "" "types"
;;
mm_struct_struct_has_percpu_counter_rss_stat)
#
# Determine if the 'rss_stat' member of the 'mm_struct' structure is
# defined with 'percpu_counter'.
#
# This change was made in Linux v6.2 by commit f1a7941243c1 ("mm:
# convert mm's rss stats into percpu_counter2").
#
CODE="
#include <linux/mm_types.h>
void conftest_mm_struct_struct_has_percpu_counter_rss_stat(struct mm_struct *mm) {
percpu_counter_add(&mm->rss_stat[0], 0);
}"
compile_check_conftest "$CODE" "NV_MM_STRUCT_STRUCT_HAS_PERCPU_COUNTER_RSS_STAT" "" "types"
;;
module_import_ns_calls_stringify)
#
# Determine if the MODULE_IMPORT_NS macro takes a string literal as