From patchwork Sat Oct 8 07:01:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xu xin X-Patchwork-Id: 13001705 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 856F7C433F5 for ; Sat, 8 Oct 2022 07:02:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8E0236B0072; Sat, 8 Oct 2022 03:02:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 869E16B0073; Sat, 8 Oct 2022 03:02:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6BB0D6B0074; Sat, 8 Oct 2022 03:02:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 53A916B0072 for ; Sat, 8 Oct 2022 03:02:13 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0930A406AC for ; Sat, 8 Oct 2022 07:02:13 +0000 (UTC) X-FDA: 79996888146.24.3C56254 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf03.hostedemail.com (Postfix) with ESMTP id A48BA20011 for ; Sat, 8 Oct 2022 07:02:12 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id g28so6676995pfk.8 for ; Sat, 08 Oct 2022 00:02:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=b9N5RbcXNeHRQoNQNCKxlzUZ9H+RkGCubTDWVE1lNM8=; b=K6xslpaQm12IfNE9utx1q9cy5IMiP9iK/yybo0lEVo6aeCAghlYhYnYeepo3Ra/Nc8 Ut05uHV/8T3k+mWTswCtJtBOS5SXV/CVmSpccrJEVdHPganNHibOtBs03zdCH6QOdNUc yzzdVA4KzcbQroZu9/a6ZrGPRgqc+UUo/HMK83g1kjYDdu7QJONtu//EyckiCMDuKimI P1LvoWPHNqzQ+ov8pYjR3QCRt5ilB6u1oT0R/+bQUE2oSqkSnsyR35IA+y7cw2KJvK+E Yb2EsjLvXB08pph9MnMYCvl7CjhNpnt5bnQ7feWmaypfGCYjh8RF2Pq7+bx/e0bO2ly9 BTFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=b9N5RbcXNeHRQoNQNCKxlzUZ9H+RkGCubTDWVE1lNM8=; b=BeXm0a7Wih21zIEeRBvgOcSumBs7mEJXVKl8lAPcjacJjrmQFLBwUce8YpBYsCMCAi 7loqZbSlhSNEmoM0/2Mcy/fHru4rckd9N3tm9lnVZ5vo66zV9ENx9M3qIQN37QctWMHQ +L41lt09PPDAcYPVZFcnFa6/gVJcmJw2WnhnKRCAzYDrJER2/wOKyMIl6e/bt/xDZ208 sdvPg6GMpDo5sfZdLDdaO8I8xvyz/rouuRqzJpi9SZBfJ5syZM+Jysa58dPSvYCFCvv4 dmQWDg+ePfByimTJ1AtzWUPjcI8ePCyM+Fj4cMzHvrUII2ggc21WYdlgBIsS/8gGgJ5k 2LvA== X-Gm-Message-State: ACrzQf0LOEFJ9tkYVrvHT+WttajRkwmk3MQrb8IW0jHJyOmstL1FeDd3 iCbpYa2Mc7CbKT+dQf3NUxk= X-Google-Smtp-Source: AMsMyM7J+etiNelbRnm852vp9JCNZ1MD2yn70pGzDcgK6o+ADrXnsfe1G/Hi+DN8AxFrJLsEr9UBpg== X-Received: by 2002:a63:2155:0:b0:455:7b5b:c2d7 with SMTP id s21-20020a632155000000b004557b5bc2d7mr7708186pgm.309.1665212531485; Sat, 08 Oct 2022 00:02:11 -0700 (PDT) Received: from localhost.localdomain ([193.203.214.57]) by smtp.gmail.com with ESMTPSA id x9-20020a170902a38900b0017f9db0236asm2618726pla.82.2022.10.08.00.02.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Oct 2022 00:02:10 -0700 (PDT) From: xu.xin.sc@gmail.com X-Google-Original-From: xu.xin16@zte.com.cn To: akpm@linux-foundation.org Cc: ran.xiaokai@zte.com.cn, yang.yang29@zte.com.cn, jiang.xuexin@zte.com.cn, imbrenda@linux.ibm.com, david@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, xu xin Subject: [PATCH 0/5] ksm: support tracking KSM-placed zero-pages Date: Sat, 8 Oct 2022 07:01:56 +0000 Message-Id: <20221008070156.308465-1-xu.xin16@zte.com.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665212532; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=b9N5RbcXNeHRQoNQNCKxlzUZ9H+RkGCubTDWVE1lNM8=; b=4sNVirJ4CKq3V+0ajczJZJjYZSkXBfvxLxWV85qSFyGWXTOvHDTdpH857DPfExm1wRzio7 +zchjvUAq1aToJshkQpCExBlVgSFCogKnDMAIw3XeUsw1Qib/cgQhgCbSxBelFIiD0nePq mna6Bj/Pbb+5qqWPUPFhkdZRVsDNmgA= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=K6xslpaQ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of xu.xin.sc@gmail.com designates 209.85.210.196 as permitted sender) smtp.mailfrom=xu.xin.sc@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665212532; a=rsa-sha256; cv=none; b=5ptwMXl3cWIsTzKQdJ4LRz87ERGPw5b44AHbooUUIV1wKhtJUF6Eh4w+h/ZWrCaj7+Hp6F XdS+7uz0XfBwoUOclPwJRlSaIqQ0iMMcjqM9vsAcUd1DsU44TXobhklcFnprwpWDhxriDo Ho2e+2vNfy/NivgxuB0r0RZdP7/JdyE= Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=K6xslpaQ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of xu.xin.sc@gmail.com designates 209.85.210.196 as permitted sender) smtp.mailfrom=xu.xin.sc@gmail.com X-Stat-Signature: q6ryujaw5ur79ywbs54gpe58cgy9g6dx X-Rspamd-Queue-Id: A48BA20011 X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1665212532-720279 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: xu xin Before enabling use_zero_pages by setting /sys/kernel/mm/ksm/ use_zero_pages to 1, pages_sharing of KSM is basically accurate. But when enabling use_zero_pages, all empty pages that are merged with kernel zero page are not counted in pages_sharing or pages_shared. That is because these empty pages are merged with zero-pages then no longer managed by KSM, which leads to two issues at least: 1) MADV_UNMERGEABLE and other ways to trigger unsharing will *not* unshare the shared zeropage as placed by KSM (which is against the MADV_UNMERGEABLE documentation at least); see the link: https://lore.kernel.org/lkml/4a3daba6-18f9-d252-697c-197f65578c44@redhat.com/ 2) we cannot know how many pages are zero pages placed by KSM when enabling use_zero_pages, which leads to KSM not being transparent with all actual merged pages by KSM. With the patch series, we can unshare zero-pages(KSM-placed) accurately and count ksm zero pages. *** BLURB HERE *** xu xin (5): ksm: abstract the function try_to_get_old_rmap_item ksm: support unsharing zero pages placed by KSM ksm: count all zero pages placed by KSM ksm: count zero pages for each process ksm: add zero_pages_sharing documentation Documentation/admin-guide/mm/ksm.rst | 10 +- fs/proc/base.c | 1 + include/linux/mm_types.h | 7 +- mm/ksm.c | 177 +++++++++++++++++++++------ 4 files changed, 157 insertions(+), 38 deletions(-)