From dd3973fb21dce4ba56e7401284915467c6b93643 Mon Sep 17 00:00:00 2001 From: Lijun Fang Date: Tue, 12 Nov 2019 17:18:48 +0800 Subject: [PATCH] mm: Change tmpfs size base on ddr size. ascend inclusion category: bugfix bugzilla: NA 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 Reviewed-by: Kefeng Wang Signed-off-by: Yang Yingliang --- mm/shmem.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 3c8742655756..e9342c370d06 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -107,9 +107,34 @@ struct shmem_falloc { }; #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; + + 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 += pgdat->node_zones[zone_type].managed_pages; + } + + 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) -- GitLab