[Devel] [PATCH RHEL7 COMMIT] shmem: fix tmpfs_ram_pages
Konstantin Khorenko
khorenko at virtuozzo.com
Fri May 29 01:35:55 PDT 2015
The commit is pushed to "branch-rh7-3.10.0-123.1.2-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-123.1.2.vz7.5.7
------>
commit 2d3d5fbf8c45b0e297ff429f0fbaa15f8e35d647
Author: Vladimir Davydov <vdavydov at parallels.com>
Date: Fri May 29 12:35:55 2015 +0400
shmem: fix tmpfs_ram_pages
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>
Reviewed-by: Kirill Tkhai <ktkhai at odin.com>
---
mm/shmem.c | 24 +++++-------------------
1 file changed, 5 insertions(+), 19 deletions(-)
diff --git a/mm/shmem.c b/mm/shmem.c
index d35bd1c..e13ab4c 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)
More information about the Devel
mailing list