[Devel] [PATCH RHEL8 COMMIT] shmem/ve: virtualize tmpfs default size

Konstantin Khorenko khorenko at virtuozzo.com
Wed Jun 2 14:02:43 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.34
------>
commit b563045c1998e088935dade4ad0bdea0234a9daf
Author: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
Date:   Wed Jun 2 14:02:43 2021 +0300

    shmem/ve: virtualize tmpfs default size
    
    Set default size to half of physpages from ve memory cgroup. User in ct
    would get -ENOSPC on 1/2 memory limit reached like we do on host.
    
    https://jira.sw.ru/browse/PCLIN-26841
    https://jira.sw.ru/browse/PSBM-127785
    
    (extracted from vz7 commit dce154c32257 ("ub/memcg: introduce
    ub_total_pages"))
    Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 mm/shmem.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index 0852032cc1da..377a038ff24f 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -35,6 +35,7 @@
 #include <linux/uio.h>
 #include <linux/khugepaged.h>
 #include <linux/hugetlb.h>
+#include <linux/ve.h>
 
 #include <asm/tlbflush.h> /* for arch/microblaze update_mmu_cache() */
 
@@ -106,14 +107,30 @@ struct shmem_falloc {
 };
 
 #ifdef CONFIG_TMPFS
+static unsigned long tmpfs_ram_pages(void)
+{
+	struct ve_struct *ve = get_exec_env();
+	struct cgroup_subsys_state *css;
+
+	if (ve_is_super(ve))
+		return totalram_pages;
+
+	css = ve_get_init_css(ve, memory_cgrp_id);
+	totalram_pages = min(totalram_pages,
+			mem_cgroup_total_pages(mem_cgroup_from_css(css)));
+	css_put(css);
+
+	return totalram_pages;
+}
+
 static unsigned long shmem_default_max_blocks(void)
 {
-	return totalram_pages / 2;
+	return tmpfs_ram_pages() / 2;
 }
 
 static unsigned long shmem_default_max_inodes(void)
 {
-	return min(totalram_pages - totalhigh_pages, totalram_pages / 2);
+	return min(totalram_pages - totalhigh_pages, tmpfs_ram_pages() / 2);
 }
 #endif
 


More information about the Devel mailing list