[Devel] [PATCH rh7 2/3] shmem: fix tmpfs_ram_pages

Vladimir Davydov vdavydov at parallels.com
Thu May 21 08:27:16 PDT 2015


tmpfs_ram_pages is used to calculate default limits on shmem fs blocks
and inodes. It is also used to scale 'size=N%' mount parameter.
Therefore it must be virtualized and it currently is. The virtualization
is inherited from RH6 where all memory accounting is up to beancounters.
Since in RH7 it is up to memcg it must be reworked.

This patch fixes this function. In short, it changes UB_PHYSPAGES.limit
to mem_cgroup_ram_pages(). However, there are a couple of things to be
noted.

First, we don't want this virtualization to work inside all memory
cgroups (e.g. in /system.slice), only in containers. Hence the
ve_is_super check.

Second, in RH6 we fallback to UB_PRIVVMPAGES.limit if UB_PHYSPAGES is
unlimited, while in RH7 we only use the analogue of UB_PHYSPAGES.limit.
This is intentional, because setups with UB_PRIVVMPAGES limit set and
UB_PHYSPAGES limit unset are deprecated - we automatically set
UB_PRIVVMPAGES.limit to overcommit_ratio * UB_PHYSPAGES.limit and
discourage setting UB_PRIVVMPAGES manually (at least lower it).
Moreover, it contradicts the system behavior which does not consider
vm.overcommit_memory/ratio while calculating default shmem limits.

Signed-off-by: Vladimir Davydov <vdavydov at parallels.com>
---
 mm/shmem.c |   24 +++++-------------------
 1 file changed, 5 insertions(+), 19 deletions(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index 97dbd4dcf348..de8f0c3e5b4b 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -104,29 +104,15 @@ enum sgp_type {
 };
 
 #ifdef CONFIG_TMPFS
-
-#include <linux/virtinfo.h>
-
 static unsigned long tmpfs_ram_pages(void)
 {
-	unsigned long ub_rampages = ULONG_MAX;
-	struct user_beancounter *ub;
+	unsigned long memcg_rampages;
 
-	/*
-	 * tmpfs can be mounted by a kthread
-	 * (e.g. by init during devtmpfs intialization)
-	 */
-	if (unlikely(!current->mm))
-		goto out;
+	if (ve_is_super(get_exec_env()))
+		return totalram_pages;
 
-	ub = mm_ub(current->mm);
-	if (ub != get_ub0()) {
-		ub_rampages = ub->ub_parms[UB_PHYSPAGES].limit;
-		if (ub_rampages == UB_MAXVALUE)
-			ub_rampages = ub->ub_parms[UB_PRIVVMPAGES].limit;
-	}
-out:
-	return min(totalram_pages, ub_rampages);
+	memcg_rampages = mem_cgroup_ram_pages();
+	return min(totalram_pages, memcg_rampages);
 }
 
 static unsigned long shmem_default_max_blocks(void)
-- 
1.7.10.4




More information about the Devel mailing list