Go to file
Rafael Aquini eb91b58bf5 ksm: support unsharing KSM-placed zero pages
JIRA: https://issues.redhat.com/browse/RHEL-27743

This patch is a backport of the following upstream commit:
commit 79271476b3362a9e69adae949a520647f8af3559
Author: xu xin <xu.xin16@zte.com.cn>
Date:   Tue Jun 13 11:09:28 2023 +0800

    ksm: support unsharing KSM-placed zero pages

    Patch series "ksm: support tracking KSM-placed zero-pages", v10.

    The core idea of this patch set is to enable users to perceive the number
    of any pages merged by KSM, regardless of whether use_zero_page switch has
    been turned on, so that users can know how much free memory increase is
    really due to their madvise(MERGEABLE) actions.  But the problem is, when
    enabling use_zero_pages, all empty pages will be merged with kernel zero
    pages instead of with each other as use_zero_pages is disabled, and then
    these zero-pages are no longer monitored by KSM.

    The motivations to do this is seen at:
    https://lore.kernel.org/lkml/202302100915227721315@zte.com.cn/

    In one word, we hope to implement the support for KSM-placed zero pages
    tracking without affecting the feature of use_zero_pages, so that app
    developer can also benefit from knowing the actual KSM profit by getting
    KSM-placed zero pages to optimize applications eventually when
    /sys/kernel/mm/ksm/use_zero_pages is enabled.

    This patch (of 5):

    When use_zero_pages of ksm is enabled, madvise(addr, len,
    MADV_UNMERGEABLE) and other ways (like write 2 to /sys/kernel/mm/ksm/run)
    to trigger unsharing will *not* actually unshare the shared zeropage as
    placed by KSM (which is against the MADV_UNMERGEABLE documentation).  As
    these KSM-placed zero pages are out of the control of KSM, the related
    counts of ksm pages don't expose how many zero pages are placed by KSM
    (these special zero pages are different from those initially mapped zero
    pages, because the zero pages mapped to MADV_UNMERGEABLE areas are
    expected to be a complete and unshared page).

    To not blindly unshare all shared zero_pages in applicable VMAs, the patch
    use pte_mkdirty (related with architecture) to mark KSM-placed zero pages.
    Thus, MADV_UNMERGEABLE will only unshare those KSM-placed zero pages.

    In addition, we'll reuse this mechanism to reliably identify KSM-placed
    ZeroPages to properly account for them (e.g., calculating the KSM profit
    that includes zeropages) in the latter patches.

    The patch will not degrade the performance of use_zero_pages as it doesn't
    change the way of merging empty pages in use_zero_pages's feature.

    Link: https://lkml.kernel.org/r/202306131104554703428@zte.com.cn
    Link: https://lkml.kernel.org/r/20230613030928.185882-1-yang.yang29@zte.com.cn
    Signed-off-by: xu xin <xu.xin16@zte.com.cn>
    Acked-by: David Hildenbrand <david@redhat.com>
    Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
    Cc: Xuexin Jiang <jiang.xuexin@zte.com.cn>
    Reviewed-by: Xiaokai Ran <ran.xiaokai@zte.com.cn>
    Reviewed-by: Yang Yang <yang.yang29@zte.com.cn>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Rafael Aquini <raquini@redhat.com>
2024-10-01 11:17:19 -04:00
Documentation Documentation/x86: Add CET shadow stack description 2024-10-01 11:17:07 -04:00
LICENSES
arch x86/shstk: Wire in shadow stack interface 2024-10-01 11:17:17 -04:00
block Merge: CVE-2024-42294: block: fix deadlock between sd_remove &#38; sd_release 2024-09-11 07:52:53 +00:00
certs integrity: PowerVM support for loading third party code signing keys 2024-02-05 19:05:32 +08:00
crypto crypto: pcrypt - Fix hungtask for PADATA_RESET 2024-05-29 13:20:49 +08:00
drivers Merge: 9.5 Merge-up kernel-5.14.0-503.4.1.el9_5 to kernel-5.14.0-503.7.1.el9_5 2024-09-27 19:11:03 +00:00
fs mm: Introduce VM_SHADOW_STACK for shadow stack memory 2024-10-01 11:17:02 -04:00
include ksm: support unsharing KSM-placed zero pages 2024-10-01 11:17:19 -04:00
init modules: wait do_free_init correctly 2024-06-17 14:17:30 -04:00
io_uring mm/gup: remove vmas parameter from pin_user_pages() 2024-09-05 20:35:37 -04:00
ipc mm: Re-introduce vm_flags to do_mmap() 2024-10-01 11:17:00 -04:00
kernel x86/shstk: Introduce map_shadow_stack syscall 2024-10-01 11:17:15 -04:00
lib Merge: CVE-2024-42292: kobject_uevent: Fix OOB access within zap_modalias_env() 2024-09-27 19:09:13 +00:00
mm ksm: support unsharing KSM-placed zero pages 2024-10-01 11:17:19 -04:00
net Merge: 9.5 Merge-up kernel-5.14.0-503.4.1.el9_5 to kernel-5.14.0-503.7.1.el9_5 2024-09-27 19:11:03 +00:00
redhat [redhat] kernel-5.14.0-514.el9 2024-09-27 19:11:55 +00:00
samples samples/bpf: Use %lu format specifier for unsigned long values 2024-06-25 11:07:33 +02:00
scripts Merge: 9.5 Merge-up kernel-5.14.0-503.4.1.el9_5 to kernel-5.14.0-503.7.1.el9_5 2024-09-27 19:11:03 +00:00
security Merge: Refresh s390x subsystem to upstream kernel 6.7 2024-09-26 17:55:24 +00:00
sound Merge: CVE-2024-42278: ASoC: TAS2781: Fix tasdev_load_calibrated_data() 2024-09-11 07:15:26 +00:00
tools selftests/x86: Add shadow stack test 2024-10-01 11:17:18 -04:00
usr kexec.h: add linux/kexec.h to UAPI compile-test coverage 2024-05-15 13:58:51 +08:00
virt mm: ptep_get() conversion 2024-09-05 20:36:52 -04:00
.clang-format printk: Prepare for SRCU console list protection 2024-05-09 11:25:16 -04:00
.cocciconfig
.get_maintainer.ignore
.gitattributes gitattributes: Remove unnecesary export restrictions 2021-08-30 10:50:35 -04:00
.gitignore redhat: rhdocs: delete .get_maintainer.conf 2024-06-06 09:36:57 -04:00
.gitlab-ci.yml redhat: set defaults for RHEL 9.5 2024-09-02 17:30:00 +00:00
.mailmap mailmap: remove my redhat.com address from RHEL9's .mailmap file 2022-09-26 09:34:38 -04:00
COPYING
CREDITS MAINTAINERS: Drop Gustavo Pimentel as PCI DWC Maintainer 2024-05-13 15:56:48 -06:00
Kbuild
Kconfig Introduce CONFIG_RH_DISABLE_DEPRECATED 2021-08-30 10:50:55 -04:00
Kconfig.redhat redhat: kABI: add missing RH_KABI_SIZE_ALIGN_CHECKS Kconfig option 2024-01-12 14:27:16 +01:00
MAINTAINERS Merge: Refresh s390x subsystem to upstream kernel 6.7 2024-09-26 17:55:24 +00:00
Makefile Merge: Update MM Selftests for 9.5 2024-08-21 12:51:18 +00:00
Makefile.rhelver [redhat] kernel-5.14.0-514.el9 2024-09-27 19:11:55 +00:00
README
makefile

README

Linux kernel
============

There are several guides for kernel developers and users. These guides can
be rendered in a number of formats, like HTML and PDF. Please read
Documentation/admin-guide/README.rst first.

In order to build the documentation, use ``make htmldocs`` or
``make pdfdocs``.  The formatted documentation can also be read online at:

    https://www.kernel.org/doc/html/latest/

There are various text files in the Documentation/ subdirectory,
several of them using the Restructured Text markup notation.

Please read the Documentation/process/changes.rst file, as it contains the
requirements for building and running the kernel, and information about
the problems which may result by upgrading your kernel.