License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 07:07:57 -07:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
2012-03-28 14:42:55 -07:00
|
|
|
# Makefile for vm tools
|
2013-02-20 08:32:33 -07:00
|
|
|
#
|
2020-04-20 18:14:23 -07:00
|
|
|
include ../scripts/Makefile.include
|
|
|
|
|
tools/mm: introduce a tool to assess swap entry allocation for thp_swapout
Both Ryan and Chris have been utilizing the small test program to aid in
debugging and identifying issues with swap entry allocation. While a real
or intricate workload might be more suitable for assessing the correctness
and effectiveness of the swap allocation policy, a small test program
presents a simpler means of understanding the problem and initially
verifying the improvements being made.
Let's endeavor to integrate it into tools/mm. Although it presently only
accommodates 64KB and 4KB, I'm optimistic that we can expand its
capabilities to support multiple sizes and simulate more complex systems
in the future as required.
Basically, we have
1. Use MADV_PAGEPUT for rapid swap-out, putting the swap allocation
code under high exercise in a short time.
2. Use MADV_DONTNEED to simulate the behavior of libc and Java heap in
freeing memory, as well as for munmap, app exits, or OOM killer
scenarios. This ensures new mTHP is always generated, released or
swapped out, similar to the behavior on a PC or Android phone where
many applications are frequently started and terminated.
3. Swap in with or without the "-a" option to observe how fragments
due to swap-in and the incoming swap-in of large folios will impact
swap-out fallback.
Due to 2, we ensure a certain proportion of mTHP. Similarly, because of
3, we maintain a certain proportion of small folios, as we don't support
large folios swap-in, meaning any swap-in will immediately result in small
folios. Therefore, with both 2 and 3, we automatically achieve a system
containing both mTHP and small folios. Additionally, 1 provides the
ability to continuously swap them out.
We can also use "-s" to add a dedicated small folios memory area.
[akpm@linux-foundation.org: thp_swap_allocator_test.c needs mman.h, per Kairui Song]
Link: https://lkml.kernel.org/r/20240622071231.576056-2-21cnbao@gmail.com
Signed-off-by: Barry Song <v-songbaohua@oppo.com>
Acked-by: Chris Li <chrisl@kernel.org>
Tested-by: Chris Li <chrisl@kernel.org>
Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>
Tested-by: Ryan Roberts <ryan.roberts@arm.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: "Huang, Ying" <ying.huang@intel.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Kairui Song <kasong@tencent.com>
Cc: Kalesh Singh <kaleshsingh@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-06-22 00:12:31 -07:00
|
|
|
BUILD_TARGETS=page-types slabinfo page_owner_sort thp_swap_allocator_test
|
tools/mm: add thpmaps script to dump THP usage info
With the proliferation of large folios for file-backed memory, and more
recently the introduction of multi-size THP for anonymous memory, it is
becoming useful to be able to see exactly how large folios are mapped into
processes. For some architectures (e.g. arm64), if most memory is mapped
using contpte-sized and -aligned blocks, TLB usage can be optimized so
it's useful to see where these requirements are and are not being met.
thpmaps is a Python utility that reads /proc/<pid>/smaps,
/proc/<pid>/pagemap and /proc/kpageflags to print information about how
transparent huge pages (both file and anon) are mapped to a specified
process or cgroup. It aims to help users debug and optimize their
workloads. In future we may wish to introduce stats directly into the
kernel (e.g. smaps or similar), but for now this provides a short term
solution without the need to introduce any new ABI.
Run with help option for a full listing of the arguments:
# ./thpmaps --help
--8<--
usage: thpmaps [-h] [--pid pid | --cgroup path] [--rollup]
[--cont size[KMG]] [--inc-smaps] [--inc-empty]
[--periodic sleep_ms]
Prints information about how transparent huge pages are mapped, either
system-wide, or for a specified process or cgroup.
When run with --pid, the user explicitly specifies the set of pids to
scan. e.g. "--pid 10 [--pid 134 ...]". When run with --cgroup, the user
passes either a v1 or v2 cgroup and all pids that belong to the cgroup
subtree are scanned. When run with neither --pid nor --cgroup, the full
set of pids on the system is gathered from /proc and scanned as if the
user had provided "--pid 1 --pid 2 ...".
A default set of statistics is always generated for THP mappings.
However, it is also possible to generate additional statistics for
"contiguous block mappings" where the block size is user-defined.
Statistics are maintained independently for anonymous and file-backed
(pagecache) memory and are shown both in kB and as a percentage of either
total anonymous or total file-backed memory as appropriate.
THP Statistics
--------------
Statistics are always generated for fully- and contiguously-mapped THPs
whose mapping address is aligned to their size, for each <size> supported
by the system. Separate counters describe THPs mapped by PTE vs those
mapped by PMD. (Although note a THP can only be mapped by PMD if it is
PMD-sized):
- anon-thp-pte-aligned-<size>kB
- file-thp-pte-aligned-<size>kB
- anon-thp-pmd-aligned-<size>kB
- file-thp-pmd-aligned-<size>kB
Similarly, statistics are always generated for fully- and contiguously-
mapped THPs whose mapping address is *not* aligned to their size, for each
<size> supported by the system. Due to the unaligned mapping, it is
impossible to map by PMD, so there are only PTE counters for this case:
- anon-thp-pte-unaligned-<size>kB
- file-thp-pte-unaligned-<size>kB
Statistics are also always generated for mapped pages that belong to a THP
but where the is THP is *not* fully- and contiguously- mapped. These
"partial" mappings are all counted in the same counter regardless of the
size of the THP that is partially mapped:
- anon-thp-pte-partial
- file-thp-pte-partial
Contiguous Block Statistics
---------------------------
An optional, additional set of statistics is generated for every
contiguous block size specified with `--cont <size>`. These statistics
show how much memory is mapped in contiguous blocks of <size> and also
aligned to <size>. A given contiguous block must all belong to the same
THP, but there is no requirement for it to be the *whole* THP. Separate
counters describe contiguous blocks mapped by PTE vs those mapped by PMD:
- anon-cont-pte-aligned-<size>kB
- file-cont-pte-aligned-<size>kB
- anon-cont-pmd-aligned-<size>kB
- file-cont-pmd-aligned-<size>kB
As an example, if monitoring 64K contiguous blocks (--cont 64K), there are
a number of sources that could provide such blocks: a fully- and
contiguously-mapped 64K THP that is aligned to a 64K boundary would
provide 1 block. A fully- and contiguously-mapped 128K THP that is
aligned to at least a 64K boundary would provide 2 blocks. Or a 128K THP
that maps its first 100K, but contiguously and starting at a 64K boundary
would provide 1 block. A fully- and contiguously-mapped 2M THP would
provide 32 blocks. There are many other possible permutations.
options:
-h, --help show this help message and exit
--pid pid Process id of the target process. Maybe issued
multiple times to scan multiple processes. --pid
and --cgroup are mutually exclusive. If neither
are provided, all processes are scanned to
provide system-wide information.
--cgroup path Path to the target cgroup in sysfs. Iterates
over every pid in the cgroup and its children.
--pid and --cgroup are mutually exclusive. If
neither are provided, all processes are scanned
to provide system-wide information.
--rollup Sum the per-vma statistics to provide a summary
over the whole system, process or cgroup.
--cont size[KMG] Adds stats for memory that is mapped in
contiguous blocks of <size> and also aligned to
<size>. May be issued multiple times to track
multiple sized blocks. Useful to infer e.g.
arm64 contpte and hpa mappings. Size must be a
power-of-2 number of pages.
--inc-smaps Include all numerical, additive
/proc/<pid>/smaps stats in the output.
--inc-empty Show all statistics including those whose value
is 0.
--periodic sleep_ms Run in a loop, polling every sleep_ms
milliseconds.
Requires root privilege to access pagemap and kpageflags.
--8<--
Example command to summarise fully and partially mapped THPs and 64K
contiguous blocks over all VMAs in all processes in the system
(--inc-empty forces printing stats that are 0):
# ./thpmaps --cont 64K --rollup --inc-empty
--8<--
anon-thp-pmd-aligned-2048kB: 139264 kB ( 6%)
file-thp-pmd-aligned-2048kB: 0 kB ( 0%)
anon-thp-pte-aligned-16kB: 0 kB ( 0%)
anon-thp-pte-aligned-32kB: 0 kB ( 0%)
anon-thp-pte-aligned-64kB: 72256 kB ( 3%)
anon-thp-pte-aligned-128kB: 0 kB ( 0%)
anon-thp-pte-aligned-256kB: 0 kB ( 0%)
anon-thp-pte-aligned-512kB: 0 kB ( 0%)
anon-thp-pte-aligned-1024kB: 0 kB ( 0%)
anon-thp-pte-aligned-2048kB: 0 kB ( 0%)
anon-thp-pte-unaligned-16kB: 0 kB ( 0%)
anon-thp-pte-unaligned-32kB: 0 kB ( 0%)
anon-thp-pte-unaligned-64kB: 0 kB ( 0%)
anon-thp-pte-unaligned-128kB: 0 kB ( 0%)
anon-thp-pte-unaligned-256kB: 0 kB ( 0%)
anon-thp-pte-unaligned-512kB: 0 kB ( 0%)
anon-thp-pte-unaligned-1024kB: 0 kB ( 0%)
anon-thp-pte-unaligned-2048kB: 0 kB ( 0%)
anon-thp-pte-partial: 63232 kB ( 3%)
file-thp-pte-aligned-16kB: 809024 kB (47%)
file-thp-pte-aligned-32kB: 43168 kB ( 3%)
file-thp-pte-aligned-64kB: 98496 kB ( 6%)
file-thp-pte-aligned-128kB: 17536 kB ( 1%)
file-thp-pte-aligned-256kB: 0 kB ( 0%)
file-thp-pte-aligned-512kB: 0 kB ( 0%)
file-thp-pte-aligned-1024kB: 0 kB ( 0%)
file-thp-pte-aligned-2048kB: 0 kB ( 0%)
file-thp-pte-unaligned-16kB: 21712 kB ( 1%)
file-thp-pte-unaligned-32kB: 704 kB ( 0%)
file-thp-pte-unaligned-64kB: 896 kB ( 0%)
file-thp-pte-unaligned-128kB: 44928 kB ( 3%)
file-thp-pte-unaligned-256kB: 0 kB ( 0%)
file-thp-pte-unaligned-512kB: 0 kB ( 0%)
file-thp-pte-unaligned-1024kB: 0 kB ( 0%)
file-thp-pte-unaligned-2048kB: 0 kB ( 0%)
file-thp-pte-partial: 9252 kB ( 1%)
anon-cont-pmd-aligned-64kB: 139264 kB ( 6%)
file-cont-pmd-aligned-64kB: 0 kB ( 0%)
anon-cont-pte-aligned-64kB: 100672 kB ( 4%)
file-cont-pte-aligned-64kB: 161856 kB ( 9%)
--8<--
Link: https://lkml.kernel.org/r/20240116141235.960842-1-ryan.roberts@arm.com
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Tested-by: Barry Song <v-songbaohua@oppo.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: William Kucharski <william.kucharski@oracle.com>
Cc: Zenghui Yu <yuzenghui@huawei.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-01-16 07:12:35 -07:00
|
|
|
INSTALL_TARGETS = $(BUILD_TARGETS) thpmaps
|
2013-02-20 08:32:33 -07:00
|
|
|
|
2013-12-09 09:14:23 -07:00
|
|
|
LIB_DIR = ../lib/api
|
2015-05-14 15:16:53 -07:00
|
|
|
LIBS = $(LIB_DIR)/libapi.a
|
2012-03-28 14:42:55 -07:00
|
|
|
|
2023-08-30 20:42:05 -07:00
|
|
|
CFLAGS += -Wall -Wextra -I../lib/ -pthread
|
|
|
|
LDFLAGS += $(LIBS) -pthread
|
2013-02-20 08:32:33 -07:00
|
|
|
|
tools/mm: add thpmaps script to dump THP usage info
With the proliferation of large folios for file-backed memory, and more
recently the introduction of multi-size THP for anonymous memory, it is
becoming useful to be able to see exactly how large folios are mapped into
processes. For some architectures (e.g. arm64), if most memory is mapped
using contpte-sized and -aligned blocks, TLB usage can be optimized so
it's useful to see where these requirements are and are not being met.
thpmaps is a Python utility that reads /proc/<pid>/smaps,
/proc/<pid>/pagemap and /proc/kpageflags to print information about how
transparent huge pages (both file and anon) are mapped to a specified
process or cgroup. It aims to help users debug and optimize their
workloads. In future we may wish to introduce stats directly into the
kernel (e.g. smaps or similar), but for now this provides a short term
solution without the need to introduce any new ABI.
Run with help option for a full listing of the arguments:
# ./thpmaps --help
--8<--
usage: thpmaps [-h] [--pid pid | --cgroup path] [--rollup]
[--cont size[KMG]] [--inc-smaps] [--inc-empty]
[--periodic sleep_ms]
Prints information about how transparent huge pages are mapped, either
system-wide, or for a specified process or cgroup.
When run with --pid, the user explicitly specifies the set of pids to
scan. e.g. "--pid 10 [--pid 134 ...]". When run with --cgroup, the user
passes either a v1 or v2 cgroup and all pids that belong to the cgroup
subtree are scanned. When run with neither --pid nor --cgroup, the full
set of pids on the system is gathered from /proc and scanned as if the
user had provided "--pid 1 --pid 2 ...".
A default set of statistics is always generated for THP mappings.
However, it is also possible to generate additional statistics for
"contiguous block mappings" where the block size is user-defined.
Statistics are maintained independently for anonymous and file-backed
(pagecache) memory and are shown both in kB and as a percentage of either
total anonymous or total file-backed memory as appropriate.
THP Statistics
--------------
Statistics are always generated for fully- and contiguously-mapped THPs
whose mapping address is aligned to their size, for each <size> supported
by the system. Separate counters describe THPs mapped by PTE vs those
mapped by PMD. (Although note a THP can only be mapped by PMD if it is
PMD-sized):
- anon-thp-pte-aligned-<size>kB
- file-thp-pte-aligned-<size>kB
- anon-thp-pmd-aligned-<size>kB
- file-thp-pmd-aligned-<size>kB
Similarly, statistics are always generated for fully- and contiguously-
mapped THPs whose mapping address is *not* aligned to their size, for each
<size> supported by the system. Due to the unaligned mapping, it is
impossible to map by PMD, so there are only PTE counters for this case:
- anon-thp-pte-unaligned-<size>kB
- file-thp-pte-unaligned-<size>kB
Statistics are also always generated for mapped pages that belong to a THP
but where the is THP is *not* fully- and contiguously- mapped. These
"partial" mappings are all counted in the same counter regardless of the
size of the THP that is partially mapped:
- anon-thp-pte-partial
- file-thp-pte-partial
Contiguous Block Statistics
---------------------------
An optional, additional set of statistics is generated for every
contiguous block size specified with `--cont <size>`. These statistics
show how much memory is mapped in contiguous blocks of <size> and also
aligned to <size>. A given contiguous block must all belong to the same
THP, but there is no requirement for it to be the *whole* THP. Separate
counters describe contiguous blocks mapped by PTE vs those mapped by PMD:
- anon-cont-pte-aligned-<size>kB
- file-cont-pte-aligned-<size>kB
- anon-cont-pmd-aligned-<size>kB
- file-cont-pmd-aligned-<size>kB
As an example, if monitoring 64K contiguous blocks (--cont 64K), there are
a number of sources that could provide such blocks: a fully- and
contiguously-mapped 64K THP that is aligned to a 64K boundary would
provide 1 block. A fully- and contiguously-mapped 128K THP that is
aligned to at least a 64K boundary would provide 2 blocks. Or a 128K THP
that maps its first 100K, but contiguously and starting at a 64K boundary
would provide 1 block. A fully- and contiguously-mapped 2M THP would
provide 32 blocks. There are many other possible permutations.
options:
-h, --help show this help message and exit
--pid pid Process id of the target process. Maybe issued
multiple times to scan multiple processes. --pid
and --cgroup are mutually exclusive. If neither
are provided, all processes are scanned to
provide system-wide information.
--cgroup path Path to the target cgroup in sysfs. Iterates
over every pid in the cgroup and its children.
--pid and --cgroup are mutually exclusive. If
neither are provided, all processes are scanned
to provide system-wide information.
--rollup Sum the per-vma statistics to provide a summary
over the whole system, process or cgroup.
--cont size[KMG] Adds stats for memory that is mapped in
contiguous blocks of <size> and also aligned to
<size>. May be issued multiple times to track
multiple sized blocks. Useful to infer e.g.
arm64 contpte and hpa mappings. Size must be a
power-of-2 number of pages.
--inc-smaps Include all numerical, additive
/proc/<pid>/smaps stats in the output.
--inc-empty Show all statistics including those whose value
is 0.
--periodic sleep_ms Run in a loop, polling every sleep_ms
milliseconds.
Requires root privilege to access pagemap and kpageflags.
--8<--
Example command to summarise fully and partially mapped THPs and 64K
contiguous blocks over all VMAs in all processes in the system
(--inc-empty forces printing stats that are 0):
# ./thpmaps --cont 64K --rollup --inc-empty
--8<--
anon-thp-pmd-aligned-2048kB: 139264 kB ( 6%)
file-thp-pmd-aligned-2048kB: 0 kB ( 0%)
anon-thp-pte-aligned-16kB: 0 kB ( 0%)
anon-thp-pte-aligned-32kB: 0 kB ( 0%)
anon-thp-pte-aligned-64kB: 72256 kB ( 3%)
anon-thp-pte-aligned-128kB: 0 kB ( 0%)
anon-thp-pte-aligned-256kB: 0 kB ( 0%)
anon-thp-pte-aligned-512kB: 0 kB ( 0%)
anon-thp-pte-aligned-1024kB: 0 kB ( 0%)
anon-thp-pte-aligned-2048kB: 0 kB ( 0%)
anon-thp-pte-unaligned-16kB: 0 kB ( 0%)
anon-thp-pte-unaligned-32kB: 0 kB ( 0%)
anon-thp-pte-unaligned-64kB: 0 kB ( 0%)
anon-thp-pte-unaligned-128kB: 0 kB ( 0%)
anon-thp-pte-unaligned-256kB: 0 kB ( 0%)
anon-thp-pte-unaligned-512kB: 0 kB ( 0%)
anon-thp-pte-unaligned-1024kB: 0 kB ( 0%)
anon-thp-pte-unaligned-2048kB: 0 kB ( 0%)
anon-thp-pte-partial: 63232 kB ( 3%)
file-thp-pte-aligned-16kB: 809024 kB (47%)
file-thp-pte-aligned-32kB: 43168 kB ( 3%)
file-thp-pte-aligned-64kB: 98496 kB ( 6%)
file-thp-pte-aligned-128kB: 17536 kB ( 1%)
file-thp-pte-aligned-256kB: 0 kB ( 0%)
file-thp-pte-aligned-512kB: 0 kB ( 0%)
file-thp-pte-aligned-1024kB: 0 kB ( 0%)
file-thp-pte-aligned-2048kB: 0 kB ( 0%)
file-thp-pte-unaligned-16kB: 21712 kB ( 1%)
file-thp-pte-unaligned-32kB: 704 kB ( 0%)
file-thp-pte-unaligned-64kB: 896 kB ( 0%)
file-thp-pte-unaligned-128kB: 44928 kB ( 3%)
file-thp-pte-unaligned-256kB: 0 kB ( 0%)
file-thp-pte-unaligned-512kB: 0 kB ( 0%)
file-thp-pte-unaligned-1024kB: 0 kB ( 0%)
file-thp-pte-unaligned-2048kB: 0 kB ( 0%)
file-thp-pte-partial: 9252 kB ( 1%)
anon-cont-pmd-aligned-64kB: 139264 kB ( 6%)
file-cont-pmd-aligned-64kB: 0 kB ( 0%)
anon-cont-pte-aligned-64kB: 100672 kB ( 4%)
file-cont-pte-aligned-64kB: 161856 kB ( 9%)
--8<--
Link: https://lkml.kernel.org/r/20240116141235.960842-1-ryan.roberts@arm.com
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Tested-by: Barry Song <v-songbaohua@oppo.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: William Kucharski <william.kucharski@oracle.com>
Cc: Zenghui Yu <yuzenghui@huawei.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-01-16 07:12:35 -07:00
|
|
|
all: $(BUILD_TARGETS)
|
2017-02-22 16:40:12 -07:00
|
|
|
|
tools/mm: add thpmaps script to dump THP usage info
With the proliferation of large folios for file-backed memory, and more
recently the introduction of multi-size THP for anonymous memory, it is
becoming useful to be able to see exactly how large folios are mapped into
processes. For some architectures (e.g. arm64), if most memory is mapped
using contpte-sized and -aligned blocks, TLB usage can be optimized so
it's useful to see where these requirements are and are not being met.
thpmaps is a Python utility that reads /proc/<pid>/smaps,
/proc/<pid>/pagemap and /proc/kpageflags to print information about how
transparent huge pages (both file and anon) are mapped to a specified
process or cgroup. It aims to help users debug and optimize their
workloads. In future we may wish to introduce stats directly into the
kernel (e.g. smaps or similar), but for now this provides a short term
solution without the need to introduce any new ABI.
Run with help option for a full listing of the arguments:
# ./thpmaps --help
--8<--
usage: thpmaps [-h] [--pid pid | --cgroup path] [--rollup]
[--cont size[KMG]] [--inc-smaps] [--inc-empty]
[--periodic sleep_ms]
Prints information about how transparent huge pages are mapped, either
system-wide, or for a specified process or cgroup.
When run with --pid, the user explicitly specifies the set of pids to
scan. e.g. "--pid 10 [--pid 134 ...]". When run with --cgroup, the user
passes either a v1 or v2 cgroup and all pids that belong to the cgroup
subtree are scanned. When run with neither --pid nor --cgroup, the full
set of pids on the system is gathered from /proc and scanned as if the
user had provided "--pid 1 --pid 2 ...".
A default set of statistics is always generated for THP mappings.
However, it is also possible to generate additional statistics for
"contiguous block mappings" where the block size is user-defined.
Statistics are maintained independently for anonymous and file-backed
(pagecache) memory and are shown both in kB and as a percentage of either
total anonymous or total file-backed memory as appropriate.
THP Statistics
--------------
Statistics are always generated for fully- and contiguously-mapped THPs
whose mapping address is aligned to their size, for each <size> supported
by the system. Separate counters describe THPs mapped by PTE vs those
mapped by PMD. (Although note a THP can only be mapped by PMD if it is
PMD-sized):
- anon-thp-pte-aligned-<size>kB
- file-thp-pte-aligned-<size>kB
- anon-thp-pmd-aligned-<size>kB
- file-thp-pmd-aligned-<size>kB
Similarly, statistics are always generated for fully- and contiguously-
mapped THPs whose mapping address is *not* aligned to their size, for each
<size> supported by the system. Due to the unaligned mapping, it is
impossible to map by PMD, so there are only PTE counters for this case:
- anon-thp-pte-unaligned-<size>kB
- file-thp-pte-unaligned-<size>kB
Statistics are also always generated for mapped pages that belong to a THP
but where the is THP is *not* fully- and contiguously- mapped. These
"partial" mappings are all counted in the same counter regardless of the
size of the THP that is partially mapped:
- anon-thp-pte-partial
- file-thp-pte-partial
Contiguous Block Statistics
---------------------------
An optional, additional set of statistics is generated for every
contiguous block size specified with `--cont <size>`. These statistics
show how much memory is mapped in contiguous blocks of <size> and also
aligned to <size>. A given contiguous block must all belong to the same
THP, but there is no requirement for it to be the *whole* THP. Separate
counters describe contiguous blocks mapped by PTE vs those mapped by PMD:
- anon-cont-pte-aligned-<size>kB
- file-cont-pte-aligned-<size>kB
- anon-cont-pmd-aligned-<size>kB
- file-cont-pmd-aligned-<size>kB
As an example, if monitoring 64K contiguous blocks (--cont 64K), there are
a number of sources that could provide such blocks: a fully- and
contiguously-mapped 64K THP that is aligned to a 64K boundary would
provide 1 block. A fully- and contiguously-mapped 128K THP that is
aligned to at least a 64K boundary would provide 2 blocks. Or a 128K THP
that maps its first 100K, but contiguously and starting at a 64K boundary
would provide 1 block. A fully- and contiguously-mapped 2M THP would
provide 32 blocks. There are many other possible permutations.
options:
-h, --help show this help message and exit
--pid pid Process id of the target process. Maybe issued
multiple times to scan multiple processes. --pid
and --cgroup are mutually exclusive. If neither
are provided, all processes are scanned to
provide system-wide information.
--cgroup path Path to the target cgroup in sysfs. Iterates
over every pid in the cgroup and its children.
--pid and --cgroup are mutually exclusive. If
neither are provided, all processes are scanned
to provide system-wide information.
--rollup Sum the per-vma statistics to provide a summary
over the whole system, process or cgroup.
--cont size[KMG] Adds stats for memory that is mapped in
contiguous blocks of <size> and also aligned to
<size>. May be issued multiple times to track
multiple sized blocks. Useful to infer e.g.
arm64 contpte and hpa mappings. Size must be a
power-of-2 number of pages.
--inc-smaps Include all numerical, additive
/proc/<pid>/smaps stats in the output.
--inc-empty Show all statistics including those whose value
is 0.
--periodic sleep_ms Run in a loop, polling every sleep_ms
milliseconds.
Requires root privilege to access pagemap and kpageflags.
--8<--
Example command to summarise fully and partially mapped THPs and 64K
contiguous blocks over all VMAs in all processes in the system
(--inc-empty forces printing stats that are 0):
# ./thpmaps --cont 64K --rollup --inc-empty
--8<--
anon-thp-pmd-aligned-2048kB: 139264 kB ( 6%)
file-thp-pmd-aligned-2048kB: 0 kB ( 0%)
anon-thp-pte-aligned-16kB: 0 kB ( 0%)
anon-thp-pte-aligned-32kB: 0 kB ( 0%)
anon-thp-pte-aligned-64kB: 72256 kB ( 3%)
anon-thp-pte-aligned-128kB: 0 kB ( 0%)
anon-thp-pte-aligned-256kB: 0 kB ( 0%)
anon-thp-pte-aligned-512kB: 0 kB ( 0%)
anon-thp-pte-aligned-1024kB: 0 kB ( 0%)
anon-thp-pte-aligned-2048kB: 0 kB ( 0%)
anon-thp-pte-unaligned-16kB: 0 kB ( 0%)
anon-thp-pte-unaligned-32kB: 0 kB ( 0%)
anon-thp-pte-unaligned-64kB: 0 kB ( 0%)
anon-thp-pte-unaligned-128kB: 0 kB ( 0%)
anon-thp-pte-unaligned-256kB: 0 kB ( 0%)
anon-thp-pte-unaligned-512kB: 0 kB ( 0%)
anon-thp-pte-unaligned-1024kB: 0 kB ( 0%)
anon-thp-pte-unaligned-2048kB: 0 kB ( 0%)
anon-thp-pte-partial: 63232 kB ( 3%)
file-thp-pte-aligned-16kB: 809024 kB (47%)
file-thp-pte-aligned-32kB: 43168 kB ( 3%)
file-thp-pte-aligned-64kB: 98496 kB ( 6%)
file-thp-pte-aligned-128kB: 17536 kB ( 1%)
file-thp-pte-aligned-256kB: 0 kB ( 0%)
file-thp-pte-aligned-512kB: 0 kB ( 0%)
file-thp-pte-aligned-1024kB: 0 kB ( 0%)
file-thp-pte-aligned-2048kB: 0 kB ( 0%)
file-thp-pte-unaligned-16kB: 21712 kB ( 1%)
file-thp-pte-unaligned-32kB: 704 kB ( 0%)
file-thp-pte-unaligned-64kB: 896 kB ( 0%)
file-thp-pte-unaligned-128kB: 44928 kB ( 3%)
file-thp-pte-unaligned-256kB: 0 kB ( 0%)
file-thp-pte-unaligned-512kB: 0 kB ( 0%)
file-thp-pte-unaligned-1024kB: 0 kB ( 0%)
file-thp-pte-unaligned-2048kB: 0 kB ( 0%)
file-thp-pte-partial: 9252 kB ( 1%)
anon-cont-pmd-aligned-64kB: 139264 kB ( 6%)
file-cont-pmd-aligned-64kB: 0 kB ( 0%)
anon-cont-pte-aligned-64kB: 100672 kB ( 4%)
file-cont-pte-aligned-64kB: 161856 kB ( 9%)
--8<--
Link: https://lkml.kernel.org/r/20240116141235.960842-1-ryan.roberts@arm.com
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Tested-by: Barry Song <v-songbaohua@oppo.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: William Kucharski <william.kucharski@oracle.com>
Cc: Zenghui Yu <yuzenghui@huawei.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-01-16 07:12:35 -07:00
|
|
|
$(BUILD_TARGETS): $(LIBS)
|
2013-02-20 08:32:33 -07:00
|
|
|
|
2013-12-09 09:14:23 -07:00
|
|
|
$(LIBS):
|
|
|
|
make -C $(LIB_DIR)
|
2012-03-28 14:42:55 -07:00
|
|
|
|
|
|
|
%: %.c
|
2013-02-20 08:32:33 -07:00
|
|
|
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
|
2012-03-28 14:42:55 -07:00
|
|
|
|
|
|
|
clean:
|
2024-08-28 21:20:08 -07:00
|
|
|
$(RM) page-types slabinfo page_owner_sort thp_swap_allocator_test
|
2013-12-09 09:14:23 -07:00
|
|
|
make -C $(LIB_DIR) clean
|
2017-02-22 16:40:12 -07:00
|
|
|
|
|
|
|
sbindir ?= /usr/sbin
|
|
|
|
|
|
|
|
install: all
|
|
|
|
install -d $(DESTDIR)$(sbindir)
|
tools/mm: add thpmaps script to dump THP usage info
With the proliferation of large folios for file-backed memory, and more
recently the introduction of multi-size THP for anonymous memory, it is
becoming useful to be able to see exactly how large folios are mapped into
processes. For some architectures (e.g. arm64), if most memory is mapped
using contpte-sized and -aligned blocks, TLB usage can be optimized so
it's useful to see where these requirements are and are not being met.
thpmaps is a Python utility that reads /proc/<pid>/smaps,
/proc/<pid>/pagemap and /proc/kpageflags to print information about how
transparent huge pages (both file and anon) are mapped to a specified
process or cgroup. It aims to help users debug and optimize their
workloads. In future we may wish to introduce stats directly into the
kernel (e.g. smaps or similar), but for now this provides a short term
solution without the need to introduce any new ABI.
Run with help option for a full listing of the arguments:
# ./thpmaps --help
--8<--
usage: thpmaps [-h] [--pid pid | --cgroup path] [--rollup]
[--cont size[KMG]] [--inc-smaps] [--inc-empty]
[--periodic sleep_ms]
Prints information about how transparent huge pages are mapped, either
system-wide, or for a specified process or cgroup.
When run with --pid, the user explicitly specifies the set of pids to
scan. e.g. "--pid 10 [--pid 134 ...]". When run with --cgroup, the user
passes either a v1 or v2 cgroup and all pids that belong to the cgroup
subtree are scanned. When run with neither --pid nor --cgroup, the full
set of pids on the system is gathered from /proc and scanned as if the
user had provided "--pid 1 --pid 2 ...".
A default set of statistics is always generated for THP mappings.
However, it is also possible to generate additional statistics for
"contiguous block mappings" where the block size is user-defined.
Statistics are maintained independently for anonymous and file-backed
(pagecache) memory and are shown both in kB and as a percentage of either
total anonymous or total file-backed memory as appropriate.
THP Statistics
--------------
Statistics are always generated for fully- and contiguously-mapped THPs
whose mapping address is aligned to their size, for each <size> supported
by the system. Separate counters describe THPs mapped by PTE vs those
mapped by PMD. (Although note a THP can only be mapped by PMD if it is
PMD-sized):
- anon-thp-pte-aligned-<size>kB
- file-thp-pte-aligned-<size>kB
- anon-thp-pmd-aligned-<size>kB
- file-thp-pmd-aligned-<size>kB
Similarly, statistics are always generated for fully- and contiguously-
mapped THPs whose mapping address is *not* aligned to their size, for each
<size> supported by the system. Due to the unaligned mapping, it is
impossible to map by PMD, so there are only PTE counters for this case:
- anon-thp-pte-unaligned-<size>kB
- file-thp-pte-unaligned-<size>kB
Statistics are also always generated for mapped pages that belong to a THP
but where the is THP is *not* fully- and contiguously- mapped. These
"partial" mappings are all counted in the same counter regardless of the
size of the THP that is partially mapped:
- anon-thp-pte-partial
- file-thp-pte-partial
Contiguous Block Statistics
---------------------------
An optional, additional set of statistics is generated for every
contiguous block size specified with `--cont <size>`. These statistics
show how much memory is mapped in contiguous blocks of <size> and also
aligned to <size>. A given contiguous block must all belong to the same
THP, but there is no requirement for it to be the *whole* THP. Separate
counters describe contiguous blocks mapped by PTE vs those mapped by PMD:
- anon-cont-pte-aligned-<size>kB
- file-cont-pte-aligned-<size>kB
- anon-cont-pmd-aligned-<size>kB
- file-cont-pmd-aligned-<size>kB
As an example, if monitoring 64K contiguous blocks (--cont 64K), there are
a number of sources that could provide such blocks: a fully- and
contiguously-mapped 64K THP that is aligned to a 64K boundary would
provide 1 block. A fully- and contiguously-mapped 128K THP that is
aligned to at least a 64K boundary would provide 2 blocks. Or a 128K THP
that maps its first 100K, but contiguously and starting at a 64K boundary
would provide 1 block. A fully- and contiguously-mapped 2M THP would
provide 32 blocks. There are many other possible permutations.
options:
-h, --help show this help message and exit
--pid pid Process id of the target process. Maybe issued
multiple times to scan multiple processes. --pid
and --cgroup are mutually exclusive. If neither
are provided, all processes are scanned to
provide system-wide information.
--cgroup path Path to the target cgroup in sysfs. Iterates
over every pid in the cgroup and its children.
--pid and --cgroup are mutually exclusive. If
neither are provided, all processes are scanned
to provide system-wide information.
--rollup Sum the per-vma statistics to provide a summary
over the whole system, process or cgroup.
--cont size[KMG] Adds stats for memory that is mapped in
contiguous blocks of <size> and also aligned to
<size>. May be issued multiple times to track
multiple sized blocks. Useful to infer e.g.
arm64 contpte and hpa mappings. Size must be a
power-of-2 number of pages.
--inc-smaps Include all numerical, additive
/proc/<pid>/smaps stats in the output.
--inc-empty Show all statistics including those whose value
is 0.
--periodic sleep_ms Run in a loop, polling every sleep_ms
milliseconds.
Requires root privilege to access pagemap and kpageflags.
--8<--
Example command to summarise fully and partially mapped THPs and 64K
contiguous blocks over all VMAs in all processes in the system
(--inc-empty forces printing stats that are 0):
# ./thpmaps --cont 64K --rollup --inc-empty
--8<--
anon-thp-pmd-aligned-2048kB: 139264 kB ( 6%)
file-thp-pmd-aligned-2048kB: 0 kB ( 0%)
anon-thp-pte-aligned-16kB: 0 kB ( 0%)
anon-thp-pte-aligned-32kB: 0 kB ( 0%)
anon-thp-pte-aligned-64kB: 72256 kB ( 3%)
anon-thp-pte-aligned-128kB: 0 kB ( 0%)
anon-thp-pte-aligned-256kB: 0 kB ( 0%)
anon-thp-pte-aligned-512kB: 0 kB ( 0%)
anon-thp-pte-aligned-1024kB: 0 kB ( 0%)
anon-thp-pte-aligned-2048kB: 0 kB ( 0%)
anon-thp-pte-unaligned-16kB: 0 kB ( 0%)
anon-thp-pte-unaligned-32kB: 0 kB ( 0%)
anon-thp-pte-unaligned-64kB: 0 kB ( 0%)
anon-thp-pte-unaligned-128kB: 0 kB ( 0%)
anon-thp-pte-unaligned-256kB: 0 kB ( 0%)
anon-thp-pte-unaligned-512kB: 0 kB ( 0%)
anon-thp-pte-unaligned-1024kB: 0 kB ( 0%)
anon-thp-pte-unaligned-2048kB: 0 kB ( 0%)
anon-thp-pte-partial: 63232 kB ( 3%)
file-thp-pte-aligned-16kB: 809024 kB (47%)
file-thp-pte-aligned-32kB: 43168 kB ( 3%)
file-thp-pte-aligned-64kB: 98496 kB ( 6%)
file-thp-pte-aligned-128kB: 17536 kB ( 1%)
file-thp-pte-aligned-256kB: 0 kB ( 0%)
file-thp-pte-aligned-512kB: 0 kB ( 0%)
file-thp-pte-aligned-1024kB: 0 kB ( 0%)
file-thp-pte-aligned-2048kB: 0 kB ( 0%)
file-thp-pte-unaligned-16kB: 21712 kB ( 1%)
file-thp-pte-unaligned-32kB: 704 kB ( 0%)
file-thp-pte-unaligned-64kB: 896 kB ( 0%)
file-thp-pte-unaligned-128kB: 44928 kB ( 3%)
file-thp-pte-unaligned-256kB: 0 kB ( 0%)
file-thp-pte-unaligned-512kB: 0 kB ( 0%)
file-thp-pte-unaligned-1024kB: 0 kB ( 0%)
file-thp-pte-unaligned-2048kB: 0 kB ( 0%)
file-thp-pte-partial: 9252 kB ( 1%)
anon-cont-pmd-aligned-64kB: 139264 kB ( 6%)
file-cont-pmd-aligned-64kB: 0 kB ( 0%)
anon-cont-pte-aligned-64kB: 100672 kB ( 4%)
file-cont-pte-aligned-64kB: 161856 kB ( 9%)
--8<--
Link: https://lkml.kernel.org/r/20240116141235.960842-1-ryan.roberts@arm.com
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Tested-by: Barry Song <v-songbaohua@oppo.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: William Kucharski <william.kucharski@oracle.com>
Cc: Zenghui Yu <yuzenghui@huawei.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-01-16 07:12:35 -07:00
|
|
|
install -m 755 -p $(INSTALL_TARGETS) $(DESTDIR)$(sbindir)
|