* [PATCH v3 01/13] x86/mm/hotplug: Don't remove PGD entries in remove_pagetable()
[not found] <cover.1466466093.git.luto@kernel.org>
@ 2016-06-20 23:43 ` Andy Lutomirski
2016-06-20 23:43 ` [PATCH v3 04/13] mm: Track NR_KERNEL_STACK in KiB instead of number of stacks Andy Lutomirski
2016-06-20 23:43 ` [PATCH v3 05/13] mm: Fix memcg stack accounting for sub-page stacks Andy Lutomirski
2 siblings, 0 replies; 7+ messages in thread
From: Andy Lutomirski @ 2016-06-20 23:43 UTC (permalink / raw)
To: x86, linux-kernel
Cc: linux-arch, Borislav Petkov, Nadav Amit, Kees Cook, Brian Gerst,
kernel-hardening@lists.openwall.com, Linus Torvalds,
Josh Poimboeuf, Jann Horn, Heiko Carstens, Ingo Molnar,
Andrew Morton, Andy Lutomirski, Denys Vlasenko, H. Peter Anvin,
Oleg Nesterov, Peter Zijlstra, Rik van Riel, Thomas Gleixner,
Waiman Long, linux-mm
From: Ingo Molnar <mingo@kernel.org>
So when memory hotplug removes a piece of physical memory from pagetable
mappings, it also frees the underlying PGD entry.
This complicates PGD management, so don't do this. We can keep the
PGD mapped and the PUD table all clear - it's only a single 4K page
per 512 GB of memory hotplugged.
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Waiman Long <Waiman.Long@hp.com>
Cc: linux-mm@kvack.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Message-Id: <1442903021-3893-4-git-send-email-mingo@kernel.org>
---
arch/x86/mm/init_64.c | 27 ---------------------------
1 file changed, 27 deletions(-)
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index bce2e5d9edd4..c7465453d64e 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -702,27 +702,6 @@ static void __meminit free_pmd_table(pmd_t *pmd_start, pud_t *pud)
spin_unlock(&init_mm.page_table_lock);
}
-/* Return true if pgd is changed, otherwise return false. */
-static bool __meminit free_pud_table(pud_t *pud_start, pgd_t *pgd)
-{
- pud_t *pud;
- int i;
-
- for (i = 0; i < PTRS_PER_PUD; i++) {
- pud = pud_start + i;
- if (pud_val(*pud))
- return false;
- }
-
- /* free a pud table */
- free_pagetable(pgd_page(*pgd), 0);
- spin_lock(&init_mm.page_table_lock);
- pgd_clear(pgd);
- spin_unlock(&init_mm.page_table_lock);
-
- return true;
-}
-
static void __meminit
remove_pte_table(pte_t *pte_start, unsigned long addr, unsigned long end,
bool direct)
@@ -913,7 +892,6 @@ remove_pagetable(unsigned long start, unsigned long end, bool direct)
unsigned long addr;
pgd_t *pgd;
pud_t *pud;
- bool pgd_changed = false;
for (addr = start; addr < end; addr = next) {
next = pgd_addr_end(addr, end);
@@ -924,13 +902,8 @@ remove_pagetable(unsigned long start, unsigned long end, bool direct)
pud = (pud_t *)pgd_page_vaddr(*pgd);
remove_pud_table(pud, addr, next, direct);
- if (free_pud_table(pud, pgd))
- pgd_changed = true;
}
- if (pgd_changed)
- sync_global_pgds(start, end - 1, 1);
-
flush_tlb_all();
}
--
2.5.5
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 04/13] mm: Track NR_KERNEL_STACK in KiB instead of number of stacks
[not found] <cover.1466466093.git.luto@kernel.org>
2016-06-20 23:43 ` [PATCH v3 01/13] x86/mm/hotplug: Don't remove PGD entries in remove_pagetable() Andy Lutomirski
@ 2016-06-20 23:43 ` Andy Lutomirski
2016-06-21 9:46 ` Vladimir Davydov
2016-06-22 7:35 ` Michal Hocko
2016-06-20 23:43 ` [PATCH v3 05/13] mm: Fix memcg stack accounting for sub-page stacks Andy Lutomirski
2 siblings, 2 replies; 7+ messages in thread
From: Andy Lutomirski @ 2016-06-20 23:43 UTC (permalink / raw)
To: x86, linux-kernel
Cc: linux-arch, Borislav Petkov, Nadav Amit, Kees Cook, Brian Gerst,
kernel-hardening@lists.openwall.com, Linus Torvalds,
Josh Poimboeuf, Jann Horn, Heiko Carstens, Andy Lutomirski,
Vladimir Davydov, Johannes Weiner, Michal Hocko, linux-mm
Currently, NR_KERNEL_STACK tracks the number of kernel stacks in a
zone. This only makes sense if each kernel stack exists entirely in
one zone, and allowing vmapped stacks could break this assumption.
Since frv has THREAD_SIZE < PAGE_SIZE, we need to track kernel stack
allocations in a unit that divides both THREAD_SIZE and PAGE_SIZE on
all architectures. Keep it simple and use KiB.
Cc: Vladimir Davydov <vdavydov@virtuozzo.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: linux-mm@kvack.org
Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
drivers/base/node.c | 3 +--
fs/proc/meminfo.c | 2 +-
include/linux/mmzone.h | 2 +-
kernel/fork.c | 3 ++-
mm/page_alloc.c | 3 +--
5 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 560751bad294..27dc68a0ed2d 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -121,8 +121,7 @@ static ssize_t node_read_meminfo(struct device *dev,
nid, K(node_page_state(nid, NR_FILE_MAPPED)),
nid, K(node_page_state(nid, NR_ANON_PAGES)),
nid, K(i.sharedram),
- nid, node_page_state(nid, NR_KERNEL_STACK) *
- THREAD_SIZE / 1024,
+ nid, node_page_state(nid, NR_KERNEL_STACK_KB),
nid, K(node_page_state(nid, NR_PAGETABLE)),
nid, K(node_page_state(nid, NR_UNSTABLE_NFS)),
nid, K(node_page_state(nid, NR_BOUNCE)),
diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
index 83720460c5bc..239b5a06cee0 100644
--- a/fs/proc/meminfo.c
+++ b/fs/proc/meminfo.c
@@ -145,7 +145,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
global_page_state(NR_SLAB_UNRECLAIMABLE)),
K(global_page_state(NR_SLAB_RECLAIMABLE)),
K(global_page_state(NR_SLAB_UNRECLAIMABLE)),
- global_page_state(NR_KERNEL_STACK) * THREAD_SIZE / 1024,
+ global_page_state(NR_KERNEL_STACK_KB),
K(global_page_state(NR_PAGETABLE)),
#ifdef CONFIG_QUICKLIST
K(quicklist_total_size()),
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 02069c23486d..63f05a7efb54 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -127,7 +127,7 @@ enum zone_stat_item {
NR_SLAB_RECLAIMABLE,
NR_SLAB_UNRECLAIMABLE,
NR_PAGETABLE, /* used for pagetables */
- NR_KERNEL_STACK,
+ NR_KERNEL_STACK_KB, /* measured in KiB */
/* Second 128 byte cacheline */
NR_UNSTABLE_NFS, /* NFS unstable pages */
NR_BOUNCE,
diff --git a/kernel/fork.c b/kernel/fork.c
index 5c2c355aa97f..be7f006af727 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -225,7 +225,8 @@ static void account_kernel_stack(struct thread_info *ti, int account)
{
struct zone *zone = page_zone(virt_to_page(ti));
- mod_zone_page_state(zone, NR_KERNEL_STACK, account);
+ mod_zone_page_state(zone, NR_KERNEL_STACK_KB,
+ THREAD_SIZE / 1024 * account);
}
void free_task(struct task_struct *tsk)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 6903b695ebae..a277dea926c9 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -4457,8 +4457,7 @@ void show_free_areas(unsigned int filter)
K(zone_page_state(zone, NR_SHMEM)),
K(zone_page_state(zone, NR_SLAB_RECLAIMABLE)),
K(zone_page_state(zone, NR_SLAB_UNRECLAIMABLE)),
- zone_page_state(zone, NR_KERNEL_STACK) *
- THREAD_SIZE / 1024,
+ zone_page_state(zone, NR_KERNEL_STACK_KB),
K(zone_page_state(zone, NR_PAGETABLE)),
K(zone_page_state(zone, NR_UNSTABLE_NFS)),
K(zone_page_state(zone, NR_BOUNCE)),
--
2.5.5
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 05/13] mm: Fix memcg stack accounting for sub-page stacks
[not found] <cover.1466466093.git.luto@kernel.org>
2016-06-20 23:43 ` [PATCH v3 01/13] x86/mm/hotplug: Don't remove PGD entries in remove_pagetable() Andy Lutomirski
2016-06-20 23:43 ` [PATCH v3 04/13] mm: Track NR_KERNEL_STACK in KiB instead of number of stacks Andy Lutomirski
@ 2016-06-20 23:43 ` Andy Lutomirski
2016-06-21 9:54 ` Vladimir Davydov
2016-06-22 7:38 ` Michal Hocko
2 siblings, 2 replies; 7+ messages in thread
From: Andy Lutomirski @ 2016-06-20 23:43 UTC (permalink / raw)
To: x86, linux-kernel
Cc: linux-arch, Borislav Petkov, Nadav Amit, Kees Cook, Brian Gerst,
kernel-hardening@lists.openwall.com, Linus Torvalds,
Josh Poimboeuf, Jann Horn, Heiko Carstens, Andy Lutomirski,
Vladimir Davydov, Johannes Weiner, Michal Hocko, linux-mm
We should account for stacks regardless of stack size, and we need
to account in sub-page units if THREAD_SIZE < PAGE_SIZE. Change the
units to kilobytes and Move it into account_kernel_stack().
Fixes: 12580e4b54ba8 ("mm: memcontrol: report kernel stack usage in cgroup2 memory.stat")
Cc: Vladimir Davydov <vdavydov@virtuozzo.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: linux-mm@kvack.org
Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
include/linux/memcontrol.h | 2 +-
kernel/fork.c | 15 ++++++---------
mm/memcontrol.c | 2 +-
3 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index a805474df4ab..3b653b86bb8f 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -52,7 +52,7 @@ enum mem_cgroup_stat_index {
MEM_CGROUP_STAT_SWAP, /* # of pages, swapped out */
MEM_CGROUP_STAT_NSTATS,
/* default hierarchy stats */
- MEMCG_KERNEL_STACK = MEM_CGROUP_STAT_NSTATS,
+ MEMCG_KERNEL_STACK_KB = MEM_CGROUP_STAT_NSTATS,
MEMCG_SLAB_RECLAIMABLE,
MEMCG_SLAB_UNRECLAIMABLE,
MEMCG_SOCK,
diff --git a/kernel/fork.c b/kernel/fork.c
index be7f006af727..ff3c41c2ba96 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -165,20 +165,12 @@ static struct thread_info *alloc_thread_info_node(struct task_struct *tsk,
struct page *page = alloc_kmem_pages_node(node, THREADINFO_GFP,
THREAD_SIZE_ORDER);
- if (page)
- memcg_kmem_update_page_stat(page, MEMCG_KERNEL_STACK,
- 1 << THREAD_SIZE_ORDER);
-
return page ? page_address(page) : NULL;
}
static inline void free_thread_info(struct thread_info *ti)
{
- struct page *page = virt_to_page(ti);
-
- memcg_kmem_update_page_stat(page, MEMCG_KERNEL_STACK,
- -(1 << THREAD_SIZE_ORDER));
- __free_kmem_pages(page, THREAD_SIZE_ORDER);
+ free_kmem_pages((unsigned long)ti, THREAD_SIZE_ORDER);
}
# else
static struct kmem_cache *thread_info_cache;
@@ -227,6 +219,11 @@ static void account_kernel_stack(struct thread_info *ti, int account)
mod_zone_page_state(zone, NR_KERNEL_STACK_KB,
THREAD_SIZE / 1024 * account);
+
+ /* All stack pages belong to the same memcg. */
+ memcg_kmem_update_page_stat(
+ virt_to_page(ti), MEMCG_KERNEL_STACK_KB,
+ account * (THREAD_SIZE / 1024));
}
void free_task(struct task_struct *tsk)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 75e74408cc8f..8e13a2419dad 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5133,7 +5133,7 @@ static int memory_stat_show(struct seq_file *m, void *v)
seq_printf(m, "file %llu\n",
(u64)stat[MEM_CGROUP_STAT_CACHE] * PAGE_SIZE);
seq_printf(m, "kernel_stack %llu\n",
- (u64)stat[MEMCG_KERNEL_STACK] * PAGE_SIZE);
+ (u64)stat[MEMCG_KERNEL_STACK_KB] * 1024);
seq_printf(m, "slab %llu\n",
(u64)(stat[MEMCG_SLAB_RECLAIMABLE] +
stat[MEMCG_SLAB_UNRECLAIMABLE]) * PAGE_SIZE);
--
2.5.5
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3 04/13] mm: Track NR_KERNEL_STACK in KiB instead of number of stacks
2016-06-20 23:43 ` [PATCH v3 04/13] mm: Track NR_KERNEL_STACK in KiB instead of number of stacks Andy Lutomirski
@ 2016-06-21 9:46 ` Vladimir Davydov
2016-06-22 7:35 ` Michal Hocko
1 sibling, 0 replies; 7+ messages in thread
From: Vladimir Davydov @ 2016-06-21 9:46 UTC (permalink / raw)
To: Andy Lutomirski
Cc: x86, linux-kernel, linux-arch, Borislav Petkov, Nadav Amit,
Kees Cook, Brian Gerst, kernel-hardening@lists.openwall.com,
Linus Torvalds, Josh Poimboeuf, Jann Horn, Heiko Carstens,
Johannes Weiner, Michal Hocko, linux-mm
On Mon, Jun 20, 2016 at 04:43:34PM -0700, Andy Lutomirski wrote:
> Currently, NR_KERNEL_STACK tracks the number of kernel stacks in a
> zone. This only makes sense if each kernel stack exists entirely in
> one zone, and allowing vmapped stacks could break this assumption.
>
> Since frv has THREAD_SIZE < PAGE_SIZE, we need to track kernel stack
> allocations in a unit that divides both THREAD_SIZE and PAGE_SIZE on
> all architectures. Keep it simple and use KiB.
>
> Cc: Vladimir Davydov <vdavydov@virtuozzo.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Michal Hocko <mhocko@kernel.org>
> Cc: linux-mm@kvack.org
> Signed-off-by: Andy Lutomirski <luto@kernel.org>
Reviewed-by: Vladimir Davydov <vdavydov@virtuozzo.com>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 05/13] mm: Fix memcg stack accounting for sub-page stacks
2016-06-20 23:43 ` [PATCH v3 05/13] mm: Fix memcg stack accounting for sub-page stacks Andy Lutomirski
@ 2016-06-21 9:54 ` Vladimir Davydov
2016-06-22 7:38 ` Michal Hocko
1 sibling, 0 replies; 7+ messages in thread
From: Vladimir Davydov @ 2016-06-21 9:54 UTC (permalink / raw)
To: Andy Lutomirski
Cc: x86, linux-kernel, linux-arch, Borislav Petkov, Nadav Amit,
Kees Cook, Brian Gerst, kernel-hardening@lists.openwall.com,
Linus Torvalds, Josh Poimboeuf, Jann Horn, Heiko Carstens,
Johannes Weiner, Michal Hocko, linux-mm, Andrew Morton
On Mon, Jun 20, 2016 at 04:43:35PM -0700, Andy Lutomirski wrote:
> We should account for stacks regardless of stack size, and we need
> to account in sub-page units if THREAD_SIZE < PAGE_SIZE. Change the
> units to kilobytes and Move it into account_kernel_stack().
>
> Fixes: 12580e4b54ba8 ("mm: memcontrol: report kernel stack usage in cgroup2 memory.stat")
> Cc: Vladimir Davydov <vdavydov@virtuozzo.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Michal Hocko <mhocko@kernel.org>
> Cc: linux-mm@kvack.org
> Signed-off-by: Andy Lutomirski <luto@kernel.org>
Reviewed-by: Vladimir Davydov <vdavydov@virtuozzo.com>
This patch is going to have a minor conflict with recent changes in
mmotm, where {alloc,free}_kmem_pages were dropped, The conflict should
be trivial to resolve - we only need to replace {alloc,free}_kmem_pages
with {alloc,free}_pages in this patch.
> ---
> include/linux/memcontrol.h | 2 +-
> kernel/fork.c | 15 ++++++---------
> mm/memcontrol.c | 2 +-
> 3 files changed, 8 insertions(+), 11 deletions(-)
>
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index a805474df4ab..3b653b86bb8f 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -52,7 +52,7 @@ enum mem_cgroup_stat_index {
> MEM_CGROUP_STAT_SWAP, /* # of pages, swapped out */
> MEM_CGROUP_STAT_NSTATS,
> /* default hierarchy stats */
> - MEMCG_KERNEL_STACK = MEM_CGROUP_STAT_NSTATS,
> + MEMCG_KERNEL_STACK_KB = MEM_CGROUP_STAT_NSTATS,
> MEMCG_SLAB_RECLAIMABLE,
> MEMCG_SLAB_UNRECLAIMABLE,
> MEMCG_SOCK,
> diff --git a/kernel/fork.c b/kernel/fork.c
> index be7f006af727..ff3c41c2ba96 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -165,20 +165,12 @@ static struct thread_info *alloc_thread_info_node(struct task_struct *tsk,
> struct page *page = alloc_kmem_pages_node(node, THREADINFO_GFP,
> THREAD_SIZE_ORDER);
>
> - if (page)
> - memcg_kmem_update_page_stat(page, MEMCG_KERNEL_STACK,
> - 1 << THREAD_SIZE_ORDER);
> -
> return page ? page_address(page) : NULL;
> }
>
> static inline void free_thread_info(struct thread_info *ti)
> {
> - struct page *page = virt_to_page(ti);
> -
> - memcg_kmem_update_page_stat(page, MEMCG_KERNEL_STACK,
> - -(1 << THREAD_SIZE_ORDER));
> - __free_kmem_pages(page, THREAD_SIZE_ORDER);
> + free_kmem_pages((unsigned long)ti, THREAD_SIZE_ORDER);
> }
> # else
> static struct kmem_cache *thread_info_cache;
> @@ -227,6 +219,11 @@ static void account_kernel_stack(struct thread_info *ti, int account)
>
> mod_zone_page_state(zone, NR_KERNEL_STACK_KB,
> THREAD_SIZE / 1024 * account);
> +
> + /* All stack pages belong to the same memcg. */
> + memcg_kmem_update_page_stat(
> + virt_to_page(ti), MEMCG_KERNEL_STACK_KB,
> + account * (THREAD_SIZE / 1024));
> }
>
> void free_task(struct task_struct *tsk)
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 75e74408cc8f..8e13a2419dad 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -5133,7 +5133,7 @@ static int memory_stat_show(struct seq_file *m, void *v)
> seq_printf(m, "file %llu\n",
> (u64)stat[MEM_CGROUP_STAT_CACHE] * PAGE_SIZE);
> seq_printf(m, "kernel_stack %llu\n",
> - (u64)stat[MEMCG_KERNEL_STACK] * PAGE_SIZE);
> + (u64)stat[MEMCG_KERNEL_STACK_KB] * 1024);
> seq_printf(m, "slab %llu\n",
> (u64)(stat[MEMCG_SLAB_RECLAIMABLE] +
> stat[MEMCG_SLAB_UNRECLAIMABLE]) * PAGE_SIZE);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 04/13] mm: Track NR_KERNEL_STACK in KiB instead of number of stacks
2016-06-20 23:43 ` [PATCH v3 04/13] mm: Track NR_KERNEL_STACK in KiB instead of number of stacks Andy Lutomirski
2016-06-21 9:46 ` Vladimir Davydov
@ 2016-06-22 7:35 ` Michal Hocko
1 sibling, 0 replies; 7+ messages in thread
From: Michal Hocko @ 2016-06-22 7:35 UTC (permalink / raw)
To: Andy Lutomirski
Cc: x86, linux-kernel, linux-arch, Borislav Petkov, Nadav Amit,
Kees Cook, Brian Gerst, kernel-hardening@lists.openwall.com,
Linus Torvalds, Josh Poimboeuf, Jann Horn, Heiko Carstens,
Vladimir Davydov, Johannes Weiner, linux-mm
On Mon 20-06-16 16:43:34, Andy Lutomirski wrote:
> Currently, NR_KERNEL_STACK tracks the number of kernel stacks in a
> zone. This only makes sense if each kernel stack exists entirely in
> one zone, and allowing vmapped stacks could break this assumption.
>
> Since frv has THREAD_SIZE < PAGE_SIZE, we need to track kernel stack
> allocations in a unit that divides both THREAD_SIZE and PAGE_SIZE on
> all architectures. Keep it simple and use KiB.
>
> Cc: Vladimir Davydov <vdavydov@virtuozzo.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Michal Hocko <mhocko@kernel.org>
> Cc: linux-mm@kvack.org
> Signed-off-by: Andy Lutomirski <luto@kernel.org>
Acked-by: Michal Hocko <mhocko@suse.com>
> ---
> drivers/base/node.c | 3 +--
> fs/proc/meminfo.c | 2 +-
> include/linux/mmzone.h | 2 +-
> kernel/fork.c | 3 ++-
> mm/page_alloc.c | 3 +--
> 5 files changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/base/node.c b/drivers/base/node.c
> index 560751bad294..27dc68a0ed2d 100644
> --- a/drivers/base/node.c
> +++ b/drivers/base/node.c
> @@ -121,8 +121,7 @@ static ssize_t node_read_meminfo(struct device *dev,
> nid, K(node_page_state(nid, NR_FILE_MAPPED)),
> nid, K(node_page_state(nid, NR_ANON_PAGES)),
> nid, K(i.sharedram),
> - nid, node_page_state(nid, NR_KERNEL_STACK) *
> - THREAD_SIZE / 1024,
> + nid, node_page_state(nid, NR_KERNEL_STACK_KB),
> nid, K(node_page_state(nid, NR_PAGETABLE)),
> nid, K(node_page_state(nid, NR_UNSTABLE_NFS)),
> nid, K(node_page_state(nid, NR_BOUNCE)),
> diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
> index 83720460c5bc..239b5a06cee0 100644
> --- a/fs/proc/meminfo.c
> +++ b/fs/proc/meminfo.c
> @@ -145,7 +145,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
> global_page_state(NR_SLAB_UNRECLAIMABLE)),
> K(global_page_state(NR_SLAB_RECLAIMABLE)),
> K(global_page_state(NR_SLAB_UNRECLAIMABLE)),
> - global_page_state(NR_KERNEL_STACK) * THREAD_SIZE / 1024,
> + global_page_state(NR_KERNEL_STACK_KB),
> K(global_page_state(NR_PAGETABLE)),
> #ifdef CONFIG_QUICKLIST
> K(quicklist_total_size()),
> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index 02069c23486d..63f05a7efb54 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -127,7 +127,7 @@ enum zone_stat_item {
> NR_SLAB_RECLAIMABLE,
> NR_SLAB_UNRECLAIMABLE,
> NR_PAGETABLE, /* used for pagetables */
> - NR_KERNEL_STACK,
> + NR_KERNEL_STACK_KB, /* measured in KiB */
> /* Second 128 byte cacheline */
> NR_UNSTABLE_NFS, /* NFS unstable pages */
> NR_BOUNCE,
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 5c2c355aa97f..be7f006af727 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -225,7 +225,8 @@ static void account_kernel_stack(struct thread_info *ti, int account)
> {
> struct zone *zone = page_zone(virt_to_page(ti));
>
> - mod_zone_page_state(zone, NR_KERNEL_STACK, account);
> + mod_zone_page_state(zone, NR_KERNEL_STACK_KB,
> + THREAD_SIZE / 1024 * account);
> }
>
> void free_task(struct task_struct *tsk)
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 6903b695ebae..a277dea926c9 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -4457,8 +4457,7 @@ void show_free_areas(unsigned int filter)
> K(zone_page_state(zone, NR_SHMEM)),
> K(zone_page_state(zone, NR_SLAB_RECLAIMABLE)),
> K(zone_page_state(zone, NR_SLAB_UNRECLAIMABLE)),
> - zone_page_state(zone, NR_KERNEL_STACK) *
> - THREAD_SIZE / 1024,
> + zone_page_state(zone, NR_KERNEL_STACK_KB),
> K(zone_page_state(zone, NR_PAGETABLE)),
> K(zone_page_state(zone, NR_UNSTABLE_NFS)),
> K(zone_page_state(zone, NR_BOUNCE)),
> --
> 2.5.5
--
Michal Hocko
SUSE Labs
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 05/13] mm: Fix memcg stack accounting for sub-page stacks
2016-06-20 23:43 ` [PATCH v3 05/13] mm: Fix memcg stack accounting for sub-page stacks Andy Lutomirski
2016-06-21 9:54 ` Vladimir Davydov
@ 2016-06-22 7:38 ` Michal Hocko
1 sibling, 0 replies; 7+ messages in thread
From: Michal Hocko @ 2016-06-22 7:38 UTC (permalink / raw)
To: Andy Lutomirski
Cc: x86, linux-kernel, linux-arch, Borislav Petkov, Nadav Amit,
Kees Cook, Brian Gerst, kernel-hardening@lists.openwall.com,
Linus Torvalds, Josh Poimboeuf, Jann Horn, Heiko Carstens,
Vladimir Davydov, Johannes Weiner, linux-mm
On Mon 20-06-16 16:43:35, Andy Lutomirski wrote:
> We should account for stacks regardless of stack size, and we need
> to account in sub-page units if THREAD_SIZE < PAGE_SIZE. Change the
> units to kilobytes and Move it into account_kernel_stack().
>
> Fixes: 12580e4b54ba8 ("mm: memcontrol: report kernel stack usage in cgroup2 memory.stat")
> Cc: Vladimir Davydov <vdavydov@virtuozzo.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Michal Hocko <mhocko@kernel.org>
> Cc: linux-mm@kvack.org
> Signed-off-by: Andy Lutomirski <luto@kernel.org>
Acked-by: Michal Hocko <mhocko@suse.com>
> ---
> include/linux/memcontrol.h | 2 +-
> kernel/fork.c | 15 ++++++---------
> mm/memcontrol.c | 2 +-
> 3 files changed, 8 insertions(+), 11 deletions(-)
>
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index a805474df4ab..3b653b86bb8f 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -52,7 +52,7 @@ enum mem_cgroup_stat_index {
> MEM_CGROUP_STAT_SWAP, /* # of pages, swapped out */
> MEM_CGROUP_STAT_NSTATS,
> /* default hierarchy stats */
> - MEMCG_KERNEL_STACK = MEM_CGROUP_STAT_NSTATS,
> + MEMCG_KERNEL_STACK_KB = MEM_CGROUP_STAT_NSTATS,
> MEMCG_SLAB_RECLAIMABLE,
> MEMCG_SLAB_UNRECLAIMABLE,
> MEMCG_SOCK,
> diff --git a/kernel/fork.c b/kernel/fork.c
> index be7f006af727..ff3c41c2ba96 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -165,20 +165,12 @@ static struct thread_info *alloc_thread_info_node(struct task_struct *tsk,
> struct page *page = alloc_kmem_pages_node(node, THREADINFO_GFP,
> THREAD_SIZE_ORDER);
>
> - if (page)
> - memcg_kmem_update_page_stat(page, MEMCG_KERNEL_STACK,
> - 1 << THREAD_SIZE_ORDER);
> -
> return page ? page_address(page) : NULL;
> }
>
> static inline void free_thread_info(struct thread_info *ti)
> {
> - struct page *page = virt_to_page(ti);
> -
> - memcg_kmem_update_page_stat(page, MEMCG_KERNEL_STACK,
> - -(1 << THREAD_SIZE_ORDER));
> - __free_kmem_pages(page, THREAD_SIZE_ORDER);
> + free_kmem_pages((unsigned long)ti, THREAD_SIZE_ORDER);
> }
> # else
> static struct kmem_cache *thread_info_cache;
> @@ -227,6 +219,11 @@ static void account_kernel_stack(struct thread_info *ti, int account)
>
> mod_zone_page_state(zone, NR_KERNEL_STACK_KB,
> THREAD_SIZE / 1024 * account);
> +
> + /* All stack pages belong to the same memcg. */
> + memcg_kmem_update_page_stat(
> + virt_to_page(ti), MEMCG_KERNEL_STACK_KB,
> + account * (THREAD_SIZE / 1024));
> }
>
> void free_task(struct task_struct *tsk)
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 75e74408cc8f..8e13a2419dad 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -5133,7 +5133,7 @@ static int memory_stat_show(struct seq_file *m, void *v)
> seq_printf(m, "file %llu\n",
> (u64)stat[MEM_CGROUP_STAT_CACHE] * PAGE_SIZE);
> seq_printf(m, "kernel_stack %llu\n",
> - (u64)stat[MEMCG_KERNEL_STACK] * PAGE_SIZE);
> + (u64)stat[MEMCG_KERNEL_STACK_KB] * 1024);
> seq_printf(m, "slab %llu\n",
> (u64)(stat[MEMCG_SLAB_RECLAIMABLE] +
> stat[MEMCG_SLAB_UNRECLAIMABLE]) * PAGE_SIZE);
> --
> 2.5.5
--
Michal Hocko
SUSE Labs
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-06-22 7:38 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <cover.1466466093.git.luto@kernel.org>
2016-06-20 23:43 ` [PATCH v3 01/13] x86/mm/hotplug: Don't remove PGD entries in remove_pagetable() Andy Lutomirski
2016-06-20 23:43 ` [PATCH v3 04/13] mm: Track NR_KERNEL_STACK in KiB instead of number of stacks Andy Lutomirski
2016-06-21 9:46 ` Vladimir Davydov
2016-06-22 7:35 ` Michal Hocko
2016-06-20 23:43 ` [PATCH v3 05/13] mm: Fix memcg stack accounting for sub-page stacks Andy Lutomirski
2016-06-21 9:54 ` Vladimir Davydov
2016-06-22 7:38 ` Michal Hocko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).