From: Lijun Fang fanglijun3@huawei.com
ascend inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I4JMLR CVE: NA -------------------
If it enable COHERENT_DEVICE and config HBM for device, the tmpfs will statistics all memory including HBM, which couldn't be used by system. When the system runs out of memory, statistical residual memory but also left a lot, so this will cause many problems.
Signed-off-by: Lijun Fang fanglijun3@huawei.com Reviewed-by: Weilong Chen chenweilong@huawei.com Signed-off-by: Zheng Zengkai zhengzengkai@huawei.com --- mm/shmem.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/mm/shmem.c b/mm/shmem.c index 07e3f0d0ba12..b488b6373454 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -124,9 +124,37 @@ struct shmem_options { };
#ifdef CONFIG_TMPFS +#ifdef CONFIG_COHERENT_DEVICE +static unsigned long ddr_totalram_pages(void) +{ + int nid; + int zone_type; + unsigned long managed_pages = 0; + pg_data_t *pgdat; + + if (nodes_empty(cdmmask)) + return totalram_pages(); + + for_each_online_node(nid) { + if (is_cdm_node(nid)) + continue; + pgdat = NODE_DATA(nid); + for (zone_type = 0; zone_type < MAX_NR_ZONES; zone_type++) + managed_pages += zone_managed_pages(&pgdat->node_zones[zone_type]); + } + + return managed_pages; +} +#else +static unsigned long ddr_totalram_pages(void) +{ + return totalram_pages(); +} +#endif + static unsigned long shmem_default_max_blocks(void) { - return totalram_pages() / 2; + return ddr_totalram_pages() / 2; }
static unsigned long shmem_default_max_inodes(void)