From patchwork Sun Oct 9 02:18:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xu xin X-Patchwork-Id: 13001877 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 644FCC433F5 for ; Sun, 9 Oct 2022 02:18:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8CE7B6B0071; Sat, 8 Oct 2022 22:18:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 87C3E6B0073; Sat, 8 Oct 2022 22:18:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 71D0A6B0074; Sat, 8 Oct 2022 22:18:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5CE776B0071 for ; Sat, 8 Oct 2022 22:18:32 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 32C0B1A081F for ; Sun, 9 Oct 2022 02:18:32 +0000 (UTC) X-FDA: 79999802064.02.630BC65 Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by imf15.hostedemail.com (Postfix) with ESMTP id D4C60A001B for ; Sun, 9 Oct 2022 02:18:31 +0000 (UTC) Received: by mail-pl1-f193.google.com with SMTP id x6so7654890pll.11 for ; Sat, 08 Oct 2022 19:18:31 -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=5a/DovPCD12eZJTVKdniqOPRiNNYGTTOdUFZS0hw8WI=; b=iAVupyDZOWfN+dPvM/5OKfpMjx92BJ53/PhY5wJaaqL/cPKG7czwPdubp/uV/hQPH1 ZmeIH1XI/gX6y/M0aXE/h6gQrsNH9yHEIX+xwLVEcXEZmWkeZ3p3F2rIzSKpoNSh2LDF Jz4xwn/yJG8UHDRgf9Db80aSfy19GDU4kcRuno1grEos/JRZ3JGsDOPI4qXO6kvyeAHo gp6fGfKr5i2Y5Y0LF1K7JAOrB3dWP9M3Nz6CTjGlo0E+U4BQfQQX8Xc0nEo+ZbiYcNb5 blLJ+BfhKtr/66vQ7IAnyvd0ZYJ+wFo9W5IGApFoumqjESaVQ2By2BprhlURH96WUBvO vi9w== 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=5a/DovPCD12eZJTVKdniqOPRiNNYGTTOdUFZS0hw8WI=; b=aB3cUZvQgRy+g2kOAsLm1a83LI/kHV8SPz93O1k3Z6d/i2JIMY10G5jEt5DP1/DYa2 2lj2Q66YC864OKuczKZ+PCQg1n8fcM6OJ/+14P4EJZbVSSHMovJRkNPICAOnXlVRSlGw jQunjvGUK407yz7Cbvp1GbD4st0gBAC2zxqdbW0KcbJJ28yMEJ8PbL1PKeF+6J+L2Stp E6aAyEs3VXKzUcGRLCpHw1Bsf3WZKM2PAeo+ELY7r8Og24YfLfGje8Ru8Vu1SJzAeszn 5KJy3azgfPJptRh2vWprYSaAIQgVOGc/nqmfXcLQlBZo0XHpyMwCHu3glKAma+Ud1k94 nEsg== X-Gm-Message-State: ACrzQf1WLBVzCzOzuLf+q+bE4/nb3uQwnqBcnx2cINZUQ7oGLyo3in9t FX25PSNpId2n10rILg09g1A= X-Google-Smtp-Source: AMsMyM7lqrOf8pZtc3CkeRa6rrH75Q2UE5YymHX6vWFwtpN52RnxJsbKP1beXYpak+vSGKRU0nMQSQ== X-Received: by 2002:a17:903:2445:b0:17c:f033:92f5 with SMTP id l5-20020a170903244500b0017cf03392f5mr12371293pls.31.1665281910753; Sat, 08 Oct 2022 19:18:30 -0700 (PDT) Received: from localhost.localdomain ([193.203.214.57]) by smtp.gmail.com with ESMTPSA id v8-20020a1709029a0800b001708c4ebbaesm3823607plp.309.2022.10.08.19.18.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Oct 2022 19:18:30 -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 v2 0/5] ksm: support tracking KSM-placed zero-pages Date: Sun, 9 Oct 2022 02:18:16 +0000 Message-Id: <20221009021816.315205-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=1665281911; 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=5a/DovPCD12eZJTVKdniqOPRiNNYGTTOdUFZS0hw8WI=; b=RYbsKQsJnVMGzdB+b80Ks/NRiBzOjDeY1+qaVZIJyGf4HzzeCzvDCZYsT903kYMezSEedr THNlQA53hJwCIfJgIUCL+jsWdEpy0Img4f5lsFXv3i+sX3AMUaV09pxdSYQDk5BOaMROp0 oJHStQVz9MHw+SwZZMdIrPYGJiVKxZY= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=iAVupyDZ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf15.hostedemail.com: domain of xu.xin.sc@gmail.com designates 209.85.214.193 as permitted sender) smtp.mailfrom=xu.xin.sc@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665281911; a=rsa-sha256; cv=none; b=DR6jzkChPQHHRzrbXq5zZejXTwURgjlFyWVEiqy4HiV1TIbDPuVSgEsXVURhwtTp7V7X2D 9msIoRSFdoHhd1AHC28ZilOWRxHbL7MZopxgeNEeKkLYlR5TsO56NZieLMhftF/hfPvdRl I+5LVTecjRpAPPoD0r11u1JFF27viC8= Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=iAVupyDZ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf15.hostedemail.com: domain of xu.xin.sc@gmail.com designates 209.85.214.193 as permitted sender) smtp.mailfrom=xu.xin.sc@gmail.com X-Stat-Signature: okobbqtrug3yebt35y5ohsrtx8s9rp5a X-Rspamd-Queue-Id: D4C60A001B X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1665281911-154875 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, 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. --- v1->v2: [patch 4/5] fix build warning, mm/ksm.c:550, misleading indentation; statement 'rmap_item->mm->ksm_zero_pages_sharing--;' is not part of the previous 'if'. *** 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(-)