All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 00/11] mm/kasan: support per-page shadow memory to reduce memory consumption
@ 2017-05-16  1:16 ` js1304
  0 siblings, 0 replies; 104+ messages in thread
From: js1304 @ 2017-05-16  1:16 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Andrey Ryabinin, Alexander Potapenko, Dmitry Vyukov, kasan-dev,
	linux-mm, linux-kernel, Thomas Gleixner, Ingo Molnar,
	H . Peter Anvin, kernel-team, Joonsoo Kim

From: Joonsoo Kim <iamjoonsoo.kim@lge.com>

Hello, all.

This is an attempt to recude memory consumption of KASAN. Please see
following description to get the more information.

1. What is per-page shadow memory

This patch introduces infrastructure to support per-page shadow memory.
Per-page shadow memory is the same with original shadow memory except
the granualarity. It's one byte shows the shadow value for the page.
The purpose of introducing this new shadow memory is to save memory
consumption.

2. Problem of current approach

Until now, KASAN needs shadow memory for all the range of the memory
so the amount of statically allocated memory is so large. It causes
the problem that KASAN cannot run on the system with hard memory
constraint. Even if KASAN can run, large memory consumption due to
KASAN changes behaviour of the workload so we cannot validate
the moment that we want to check.

3. How does this patch fix the problem

This patch tries to fix the problem by reducing memory consumption for
the shadow memory. There are two observations.

1) Type of memory usage can be distinguished well.
2) Shadow memory is manipulated/checked in byte unit only for slab,
kernel stack and global variable. Shadow memory for other usecases
just show KASAN_FREE_PAGE or 0 (means valid) in page unit.

With these two observations, I think an optimized way to support
KASAN feature.

1) Introduces per-page shadow that cover all the memory
2) Checks validity of the access through per-page shadow except
that checking object is a slab, kernel stack, global variable
3) For those byte accessible types of object, allocate/map original
shadow by on-demand and checks validity of the access through
original shadow

Instead original shadow statically consumes 1/8 bytes of the amount of
total memory, per-page shadow statically consumes 1/PAGE_SIZE bytes of it.
Extra memory is required for a slab, kernel stack and global variable by
on-demand in runtime, however, it would not be larger than before.

4. Result

Following is the result of the memory consumption on my QEMU system.
'runtime' shows the maximum memory usage for on-demand shadow allocation
during the kernel build workload.

base vs patched

MemTotal: 858 MB vs 987 MB
runtime: 0 MB vs 30MB
Net Available: 858 MB vs 957 MB

For 4096 MB QEMU system

MemTotal: 3477 MB vs 4000 MB
runtime: 0 MB vs 50MB

base vs patched (2048 MB QEMU system)
204 s vs 224 s
Net Available: 3477 MB vs 3950 MB

Thanks.

Joonsoo Kim (11):
  mm/kasan: rename XXX_is_zero to XXX_is_nonzero
  mm/kasan: don't fetch the next shadow value speculartively
  mm/kasan: handle unaligned end address in zero_pte_populate
  mm/kasan: extend kasan_populate_zero_shadow()
  mm/kasan: introduce per-page shadow memory infrastructure
  mm/kasan: mark/unmark the target range that is for original shadow
    memory
  x86/kasan: use per-page shadow memory
  mm/kasan: support on-demand shadow allocation/mapping
  x86/kasan: support on-demand shadow mapping
  mm/kasan: support dynamic shadow memory free
  mm/kasan: change the order of shadow memory check

 arch/arm64/mm/kasan_init.c       |  17 +-
 arch/x86/include/asm/kasan.h     |   8 +
 arch/x86/include/asm/processor.h |   4 +
 arch/x86/kernel/cpu/common.c     |   4 +-
 arch/x86/kernel/setup_percpu.c   |   2 +
 arch/x86/mm/kasan_init_64.c      | 191 ++++++++++++--
 include/linux/kasan.h            |  71 ++++-
 kernel/fork.c                    |   7 +
 mm/kasan/kasan.c                 | 555 +++++++++++++++++++++++++++++++++------
 mm/kasan/kasan.h                 |  22 +-
 mm/kasan/kasan_init.c            | 158 ++++++++---
 mm/kasan/report.c                |  28 ++
 mm/page_alloc.c                  |  10 +
 mm/slab.c                        |   9 +
 mm/slab_common.c                 |  11 +-
 mm/slub.c                        |   8 +
 16 files changed, 957 insertions(+), 148 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 104+ messages in thread

end of thread, other threads:[~2017-06-14  0:12 UTC | newest]

Thread overview: 104+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-16  1:16 [PATCH v1 00/11] mm/kasan: support per-page shadow memory to reduce memory consumption js1304
2017-05-16  1:16 ` js1304
2017-05-16  1:16 ` [PATCH v1 01/11] mm/kasan: rename XXX_is_zero to XXX_is_nonzero js1304
2017-05-16  1:16 ` [PATCH v1 02/11] mm/kasan: don't fetch the next shadow value speculartively js1304
2017-05-16  1:16   ` js1304
2017-05-16  1:16 ` [PATCH v1 03/11] mm/kasan: handle unaligned end address in zero_pte_populate js1304
2017-05-16  1:16   ` js1304
2017-05-16  1:16 ` [PATCH v1 04/11] mm/kasan: extend kasan_populate_zero_shadow() js1304
2017-05-16  1:16   ` js1304
2017-05-16  1:16 ` [PATCH v1 05/11] mm/kasan: introduce per-page shadow memory infrastructure js1304
2017-05-16  1:16   ` js1304
2017-05-16  1:16 ` [PATCH v1 06/11] mm/kasan: mark/unmark the target range that is for original shadow memory js1304
2017-05-16  1:16   ` js1304
2017-05-16  1:16 ` [PATCH v1 07/11] x86/kasan: use per-page " js1304
2017-05-16  1:16   ` js1304
2017-05-16  1:16 ` [PATCH v1 08/11] mm/kasan: support on-demand shadow allocation/mapping js1304
2017-05-16  1:16   ` js1304
2017-05-16  1:16 ` [PATCH v1 09/11] x86/kasan: support on-demand shadow mapping js1304
2017-05-16  1:16   ` js1304
2017-05-16  1:16 ` [PATCH v1 10/11] mm/kasan: support dynamic shadow memory free js1304
2017-05-16  1:16   ` js1304
2017-05-16  1:16 ` [PATCH v1 11/11] mm/kasan: change the order of shadow memory check js1304
2017-05-16  1:16   ` js1304
2017-05-16  1:28 ` [PATCH(RE-RESEND) v1 01/11] mm/kasan: rename _is_zero to _is_nonzero Joonsoo Kim
2017-05-16  1:28   ` Joonsoo Kim
2017-05-16  4:34 ` [PATCH v1 00/11] mm/kasan: support per-page shadow memory to reduce memory consumption Dmitry Vyukov
2017-05-16  4:34   ` Dmitry Vyukov
2017-05-16  4:47   ` Dmitry Vyukov
2017-05-16  4:47     ` Dmitry Vyukov
2017-05-16  6:23   ` Joonsoo Kim
2017-05-16  6:23     ` Joonsoo Kim
2017-05-16 20:49     ` Dmitry Vyukov
2017-05-16 20:49       ` Dmitry Vyukov
2017-05-17  7:23       ` Joonsoo Kim
2017-05-17  7:23         ` Joonsoo Kim
2017-05-17  7:25         ` Joonsoo Kim
2017-05-17  7:25           ` Joonsoo Kim
2017-05-24  6:57       ` Dmitry Vyukov
2017-05-24  6:57         ` Dmitry Vyukov
2017-05-24  7:45         ` Joonsoo Kim
2017-05-24  7:45           ` Joonsoo Kim
2017-05-24 17:19           ` Dmitry Vyukov
2017-05-24 17:19             ` Dmitry Vyukov
2017-05-25  0:41             ` Joonsoo Kim
2017-05-25  0:41               ` Joonsoo Kim
2017-05-29 15:07               ` Dmitry Vyukov
2017-05-29 15:07                 ` Dmitry Vyukov
2017-05-29 15:12                 ` Dmitry Vyukov
2017-05-29 15:12                   ` Dmitry Vyukov
2017-05-29 15:29                   ` Dmitry Vyukov
2017-05-29 15:29                     ` Dmitry Vyukov
2017-05-30  7:58                     ` Vladimir Murzin
2017-05-30  7:58                       ` Vladimir Murzin
2017-05-30  8:15                       ` Dmitry Vyukov
2017-05-30  8:15                         ` Dmitry Vyukov
2017-05-30  8:31                         ` Vladimir Murzin
2017-05-30  8:31                           ` Vladimir Murzin
2017-05-30  8:40                           ` Vladimir Murzin
2017-05-30  8:40                             ` Vladimir Murzin
2017-05-30  8:49                             ` Dmitry Vyukov
2017-05-30  8:49                               ` Dmitry Vyukov
2017-05-30  9:08                               ` Vladimir Murzin
2017-05-30  9:08                                 ` Vladimir Murzin
2017-05-30  9:26                                 ` Dmitry Vyukov
2017-05-30  9:26                                   ` Dmitry Vyukov
2017-05-30  9:39                                   ` Vladimir Murzin
2017-05-30  9:39                                     ` Vladimir Murzin
2017-05-30  9:45                                     ` Dmitry Vyukov
2017-05-30  9:45                                       ` Dmitry Vyukov
2017-05-30  9:54                                       ` Vladimir Murzin
2017-05-30  9:54                                         ` Vladimir Murzin
2017-05-30 14:16                     ` Andrey Ryabinin
2017-05-30 14:16                       ` Andrey Ryabinin
2017-05-31  5:50                       ` Joonsoo Kim
2017-05-31  5:50                         ` Joonsoo Kim
2017-05-31 16:31                         ` Andrey Ryabinin
2017-05-31 16:31                           ` Andrey Ryabinin
2017-06-08  2:43                           ` Joonsoo Kim
2017-06-08  2:43                             ` Joonsoo Kim
2017-06-01 15:16                       ` 王靖天
2017-06-01 18:06                       ` Dmitry Vyukov
2017-06-01 18:06                         ` Dmitry Vyukov
2017-06-08  2:40                         ` Joonsoo Kim
2017-06-08  2:40                           ` Joonsoo Kim
2017-06-13 16:49                           ` Andrey Ryabinin
2017-06-13 16:49                             ` Andrey Ryabinin
2017-06-14  0:12                             ` Joonsoo Kim
2017-06-14  0:12                               ` Joonsoo Kim
2017-05-17 12:17 ` Andrey Ryabinin
2017-05-17 12:17   ` Andrey Ryabinin
2017-05-19  1:53   ` Joonsoo Kim
2017-05-19  1:53     ` Joonsoo Kim
2017-05-22  6:02     ` Dmitry Vyukov
2017-05-22  6:02       ` Dmitry Vyukov
2017-05-24  6:04       ` Joonsoo Kim
2017-05-24  6:04         ` Joonsoo Kim
2017-05-24 16:31         ` Dmitry Vyukov
2017-05-24 16:31           ` Dmitry Vyukov
2017-05-25  0:46           ` Joonsoo Kim
2017-05-25  0:46             ` Joonsoo Kim
2017-05-22 14:00     ` Andrey Ryabinin
2017-05-22 14:00       ` Andrey Ryabinin
2017-05-24  6:18       ` Joonsoo Kim
2017-05-24  6:18         ` Joonsoo Kim

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.