Re: [PATCH v4 1/2] mm: factor commit limit calculation
From: Andrew Morton
Date: Tue Nov 05 2013 - 18:51:13 EST
On Fri, 18 Oct 2013 14:56:58 +0200 Jerome Marchand <jmarchan@xxxxxxxxxx> wrote:
> Change since v3:
> - rebase on 3.12-rc5
>
> The same calculation is currently done in three differents places.
> Factor that code so future changes has to be made at only one place.
>
lgtm.
> --- a/include/linux/mman.h
> +++ b/include/linux/mman.h
> @@ -7,6 +7,9 @@
> #include <linux/atomic.h>
> #include <uapi/linux/mman.h>
>
> +#include <linux/hugetlb.h>
> +#include <linux/swap.h>
> +
> extern int sysctl_overcommit_memory;
> extern int sysctl_overcommit_ratio;
> extern struct percpu_counter vm_committed_as;
> @@ -87,4 +90,13 @@ calc_vm_flag_bits(unsigned long flags)
> _calc_vm_trans(flags, MAP_DENYWRITE, VM_DENYWRITE ) |
> _calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED );
> }
> +
> +/*
> + * Commited memory limit enforced when OVERCOMMIT_NEVER policy is used
> + */
> +static inline unsigned long vm_commit_limit()
> +{
> + return ((totalram_pages - hugetlb_total_pages())
> + * sysctl_overcommit_ratio / 100) + total_swap_pages;
> +}
Not sure I like this part much. This function is large and slow and
doesn't merit inlining, plus it requires worsening our nested-include
mess. This?
Also, it should be vm_commit_limit(void).
From: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Subject: mm-factor-commit-limit-calculation-fix
Cc: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
Cc: Jerome Marchand <jmarchan@xxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---
include/linux/mman.h | 12 +-----------
mm/mmap.c | 9 +++++++++
2 files changed, 10 insertions(+), 11 deletions(-)
diff -puN fs/proc/meminfo.c~mm-factor-commit-limit-calculation-fix fs/proc/meminfo.c
diff -puN include/linux/mman.h~mm-factor-commit-limit-calculation-fix include/linux/mman.h
--- a/include/linux/mman.h~mm-factor-commit-limit-calculation-fix
+++ a/include/linux/mman.h
@@ -7,9 +7,6 @@
#include <linux/atomic.h>
#include <uapi/linux/mman.h>
-#include <linux/hugetlb.h>
-#include <linux/swap.h>
-
extern int sysctl_overcommit_memory;
extern int sysctl_overcommit_ratio;
extern struct percpu_counter vm_committed_as;
@@ -91,12 +88,5 @@ calc_vm_flag_bits(unsigned long flags)
_calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED );
}
-/*
- * Commited memory limit enforced when OVERCOMMIT_NEVER policy is used
- */
-static inline unsigned long vm_commit_limit()
-{
- return ((totalram_pages - hugetlb_total_pages())
- * sysctl_overcommit_ratio / 100) + total_swap_pages;
-}
+unsigned long vm_commit_limit(void);
#endif /* _LINUX_MMAN_H */
diff -puN mm/mmap.c~mm-factor-commit-limit-calculation-fix mm/mmap.c
--- a/mm/mmap.c~mm-factor-commit-limit-calculation-fix
+++ a/mm/mmap.c
@@ -110,6 +110,15 @@ unsigned long vm_memory_committed(void)
EXPORT_SYMBOL_GPL(vm_memory_committed);
/*
+ * Commited memory limit enforced when OVERCOMMIT_NEVER policy is used
+ */
+unsigned long vm_commit_limit(void)
+{
+ return ((totalram_pages - hugetlb_total_pages())
+ * sysctl_overcommit_ratio / 100) + total_swap_pages;
+}
+
+/*
* Check that a process has enough memory to allocate a new virtual
* mapping. 0 means there is enough memory for the allocation to
* succeed and -ENOMEM implies there is not.
diff -puN mm/nommu.c~mm-factor-commit-limit-calculation-fix mm/nommu.c
diff -puN mm/util.c~mm-factor-commit-limit-calculation-fix mm/util.c
diff -puN include/linux/mm.h~mm-factor-commit-limit-calculation-fix include/linux/mm.h
_
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/