From mboxrd@z Thu Jan 1 00:00:00 1970 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 DDA37C77B73 for ; Thu, 25 May 2023 05:42:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 570DD900004; Thu, 25 May 2023 01:42:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 528B0900002; Thu, 25 May 2023 01:42:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 40FE9900004; Thu, 25 May 2023 01:42:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 32572900002 for ; Thu, 25 May 2023 01:42:13 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E724C1A020B for ; Thu, 25 May 2023 05:42:12 +0000 (UTC) X-FDA: 80827681704.23.34E287F Received: from mxct.zte.com.cn (mxct.zte.com.cn [183.62.165.209]) by imf01.hostedemail.com (Postfix) with ESMTP id 3FB7A40015 for ; Thu, 25 May 2023 05:42:08 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of yang.yang29@zte.com.cn designates 183.62.165.209 as permitted sender) smtp.mailfrom=yang.yang29@zte.com.cn; dmarc=pass (policy=none) header.from=zte.com.cn ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684993330; a=rsa-sha256; cv=none; b=zUwsTy1U99Wi0V2172OGtIDj12nXTNj4C5vR6ZnVgicHLrzVnCUKs3JFrTC7iW03cfHR71 vgnN0g0fw3eO/P1Cq4+3YPdBZleKEPy0TyF1ZLycCYezBkjYihs+2PqNPeDT/OzhVci55W sLUTViNPUxDrVaxLjS3MU0bewbQeyUQ= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of yang.yang29@zte.com.cn designates 183.62.165.209 as permitted sender) smtp.mailfrom=yang.yang29@zte.com.cn; dmarc=pass (policy=none) header.from=zte.com.cn ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684993330; 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-type:content-transfer-encoding:in-reply-to: references; bh=M+8KwI7AJROYSU76+XeJIXfdJUeGIk822nw5hB98YBo=; b=JrSlPqLBVRsDGMcPnX8gDTOYcTKb8pRckswpBiE+seWwJwGCh1CfGt7j0sGEmVaFz9BL2q BpPphGqq7gxcGfnoPuWttZDBRzj5UrexX+rPeAljjaJs5XXmuYUPWAYW4++HVbbg02sydt etVrH+2O1wELdRF22ZauigRfKRcJA+o= Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxct.zte.com.cn (FangMail) with ESMTPS id 4QRcPj6mDLz4y3ZQ; Thu, 25 May 2023 13:42:01 +0800 (CST) Received: from szxlzmapp07.zte.com.cn ([10.5.230.251]) by mse-fl2.zte.com.cn with SMTP id 34P5fuuu048390; Thu, 25 May 2023 13:41:56 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp03[null]) by mapi (Zmail) with MAPI id mid14; Thu, 25 May 2023 13:41:58 +0800 (CST) Date: Thu, 25 May 2023 13:41:58 +0800 (CST) X-Zmail-TransId: 2b05646ef526ffffffff997-8eb34 X-Mailer: Zmail v1.0 Message-ID: <202305251341580149313@zte.com.cn> Mime-Version: 1.0 From: To: , Cc: , , , , , , , Subject: =?UTF-8?B?W1BBVENIIHYxMCAwLzVdIGtzbTogc3VwcG9ydCB0cmFja2luZyBLU00tcGxhY2VkIHplcm8tcGFnZXM=?= Content-Type: text/plain; charset="UTF-8" X-MAIL:mse-fl2.zte.com.cn 34P5fuuu048390 X-Fangmail-Gw-Spam-Type: 0 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 646EF529.001/4QRcPj6mDLz4y3ZQ X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 3FB7A40015 X-Stat-Signature: xnbmj99myhctr1691j7rsj8y7ezueq43 X-HE-Tag: 1684993328-563751 X-HE-Meta: U2FsdGVkX18OJRmxxPTWB2Mg1sLGHYF6bbMc/52FpeMzy4vgsiuStQrHnBDT1itd6fB0WjTslwwMOpftA/oP8nYNtK8NExenIWESHaZRqvgrfaQkdCTfw/I4j2VtaX+0j3OMTs/0xkFWqe3KBnkYAtjhGKM5usbFxPGp2cCdY/2vMQy2s/WpFEJLvkQSuPcRnsdbW/b99mDf6kEdFn+daJmVFHJ1TdKHICxno/OKXga3Vj1G2v+qkejaJ7NlI7NT218zDm+mL+3f44Ke32rAsqeN9xJQiPnX19LKQtR24Xm0JASD7S1T+CDpf6Z7MJK85jYf6vq1Y0R/XLOpuaOhdeTifRqSBV199c0cjNos5DDterCIf9ou8m/+LrbVkJ/DeaSG/dWVizOx+c8s1XQgTKlhRxh/x8wYd03AndItOeidFeKUTRk+cAFBmW5B1IjVjalJvzankN38l5AZcjf8BpB/oNpVN58n+zyZ2UjQOW1y08CWN1HbLv6NjVmcBqOH1emY9ieeaF+NnYaahu6E9W/hIc19+PoPLmTcyVYjjmjCmh7oEJEeGciF5ch7hKooqGhaOxad4Yk6aJPPYzYK+fTs7m8H2W1d3jZRT4yGupB4MOnlmcggoEuaUXpFkJHgXNp9YoYCUFlzDrLUICT1TNMzAqVfrIboK0X77gY2Mq1bxOfBhuUrVHtkuru7yBScgXsBjBUBTAx041p1z7BWfRw20+GKmtkfdMhfRbSOHG/sTZ06NmRArPtQF9JzW6auWE/v0UgJPudZL/7IoRZ5HsGNF69rnaNvaq5zMcsoC4q27nX+vg+v4pukHCBiBPFMUn963SyTy3nlwb6osLCL2YrRw0UHD88ffcmQntH9WjZXU76wHadYwHMk7AEF7FafLO3OeR1wR+GcgnwHrRAPidQcmXVJofYOq28FA3Tsytj3F141j9lulRHIvvQoG2h06VTj1uOvZfe7pIV1Ojq ydi0yoOT APRiWGrd9RoqYV2NuXaWkps3V1JrIuTZ0EyaZ7uNhiYdATBExFMu4hCdifrOjvqGb3y5R4ihyNJG7lIrfOYYZ9hIz0Pz+qtxXNPjykepcWdz+f0Prsj4n5T/NRj3GjJ3Z3vSRtLXzkGj2ShI7sxNDjxn0F6cVQfWKxUZE9pEbgJzU0j4kTiHeVfNqofkyEwrc33kl5NbIKCtbz7+0eRJAs5XMsjMTnvRVXs6p9VTJXWm6ziCBC4BVQLW+8CBAeHVtra7wIHnwlseCne2uUFLUepszhFqPCl631Vq+N2XAfzJwKvRasQXdKUbHHiKKfrqzH41A1iRUzckHxoGtgIoS6lr0YvaCtvYXsl0yDpi4eAfpw5Xd+UEUr52GbKl2q0olkFd90pIOlRaQcNBd04vZCSVc8Obty3/c9HDRo4bLbOGwRJkMbRDMWy2wbhs2SZp5Jpr6SLZAnmoc+V/t2SXxv1HY2s8dxXGm2M+lezv8mYIdQJY= 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 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. Change log ---------- v9->v10: ------- (1) Fix a compile error due to [PATCH v8 3/5] when CONFIG_KSM is not set. (2) Rename the function 'ksm_notify_unmap_zero_page' as 'ksm_might_unmap_zero_page'. (3) In [PATCH 5/5], we get ksm_zero_pages from its own 'mm' instead of the global system. (4) In [PATCH 5/5], we add a subject task of testing ksm zero pages when unmerging by triggering write fault. v8->v9: ------ (1) The previous [PATCH v8 4/6] is squashed into the current [PATCH v9 2/5]. (2) Improve the codes as David's suggestions. v7->v8: ------- (1) Since [1] which fix the bug of pte_mkdirty on sparc64 that makes pte writable, then we can remove the architechture restrictions of our features. (2) Improve the scheme of update ksm_zero_pages: add the handling case when khugepaged replaces a shared zeropage by a THP. [1] https://lore.kernel.org/all/20230411141529.428991-2-david@redhat.com/ v6->v7: ------- This is an all-newed version which is different from v6 which relys on KSM's rmap_item. The patch series don't rely on rmap_item but pte_dirty, so the general handling of tracking KSM-placed zero-pages is simplified a lot. For safety, we restrict this feature only to the tested and known-working architechtures (ARM, ARM64, and X86) fow now. xu xin (5): ksm: support unsharing KSM-placed zero pages ksm: count all zero pages placed by KSM ksm: add ksm zero pages for each process ksm: consider KSM-placed zeropages when calculating KSM profit selftest: add a testcase of ksm zero pages Documentation/admin-guide/mm/ksm.rst | 25 ++++-- fs/proc/base.c | 1 + include/linux/ksm.h | 20 +++++ include/linux/mm_types.h | 9 ++- mm/khugepaged.c | 2 + mm/ksm.c | 28 +++++-- mm/memory.c | 5 +- tools/testing/selftests/mm/ksm_functional_tests.c | 98 ++++++++++++++++++++++- 8 files changed, 172 insertions(+), 16 deletions(-) -- 2.15.2