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 931F5C88CB5 for ; Tue, 13 Jun 2023 03:05:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C96DC6B0071; Mon, 12 Jun 2023 23:05:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C1F638E0003; Mon, 12 Jun 2023 23:05:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE6BE8E0002; Mon, 12 Jun 2023 23:05:24 -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 9C2876B0071 for ; Mon, 12 Jun 2023 23:05:24 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 67260403B0 for ; Tue, 13 Jun 2023 03:05:24 +0000 (UTC) X-FDA: 80896233768.08.2357C3A Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.35]) by imf28.hostedemail.com (Postfix) with ESMTP id D87C1C0009 for ; Tue, 13 Jun 2023 03:05:20 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=zte.com.cn; spf=pass (imf28.hostedemail.com: domain of yang.yang29@zte.com.cn designates 63.216.63.35 as permitted sender) smtp.mailfrom=yang.yang29@zte.com.cn ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686625522; 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=e74F6FobrJyeQ4Am2SURkahDV53MB++X4r4PZkAEVW6aprQQRdquSpzkgDmLARcKWTzJvm g807GFe0kEenki3MSP5WDuwpq3w2iOG6zD7zDHw+kQjgxTE719TXmMoTSz4+nMMslh0zqA PwEFnBK5SUg02qHCLhAs3Yo0F9xkRhY= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=zte.com.cn; spf=pass (imf28.hostedemail.com: domain of yang.yang29@zte.com.cn designates 63.216.63.35 as permitted sender) smtp.mailfrom=yang.yang29@zte.com.cn ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686625522; a=rsa-sha256; cv=none; b=52Zvh0OodKtLqAonUU9tflcEv35sjSCM8VvSA9ijoz5bZL7JO0RDCan5KSRaA7vNNViBJN L/lDEJYu5fxtXQeBc3mP0q6g7/MJdcjw6GvXXieZrNH7LEZlLt8OoFwlRbosJvbYid9Y79 5k6TUp+ZaHGZgiUDio+AlBHz0uFJ5Ic= 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 mxhk.zte.com.cn (FangMail) with ESMTPS id 4QgD224jXpz5B151; Tue, 13 Jun 2023 11:05:14 +0800 (CST) Received: from szxlzmapp03.zte.com.cn ([10.5.231.207]) by mse-fl2.zte.com.cn with SMTP id 35D34s1V090643; Tue, 13 Jun 2023 11:04:54 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp01[null]) by mapi (Zmail) with MAPI id mid14; Tue, 13 Jun 2023 11:04:55 +0800 (CST) Date: Tue, 13 Jun 2023 11:04:55 +0800 (CST) X-Zmail-TransId: 2b036487dcd7685-e54ce X-Mailer: Zmail v1.0 Message-ID: <202306131104554703428@zte.com.cn> Mime-Version: 1.0 From: To: , Cc: , , , , , , Subject: =?UTF-8?B?W1BBVENIIFJFU0VORCB2MTAgMC81XSBrc206IHN1cHBvcnQgdHJhY2tpbmcgS1NNLXBsYWNlZCB6ZXJvLXBhZ2Vz?= Content-Type: text/plain; charset="UTF-8" X-MAIL:mse-fl2.zte.com.cn 35D34s1V090643 X-Fangmail-Gw-Spam-Type: 0 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6487DCEA.000/4QgD224jXpz5B151 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: D87C1C0009 X-Stat-Signature: nm3539mgky345fef6ipqim667nc7yxw4 X-HE-Tag: 1686625520-213195 X-HE-Meta: U2FsdGVkX196e5IqyypU8oPWvJD64gaYQth7LHosu0fwSRh7glxZ0ZOTGXHsy+rFN2bhmyU4vmDZUWIr3RmBtgvaZWIyMY9ZayU/g7OWnVtnwEgHiW/Fk54Qw8R96l/2cM5HH0Oljk+4rjvzxNpTStlHcbq8co0ePbKD5n0c90H0akFk05MJQzo2PegvAGcBnltnALjGz/7jzM0gG1No1NCD5CFxOkqJLuAY4/I2y39X+YZoeqzwrs60NJKS7ezAKx2F54QQA0yVHv5VgKjBwQIWjmKWsuPZS+grpSuoMtgusVQzCArqzMsYOagaX+KiF0VoO/y2yL0GC3ybvxfG4s+OCj4l5llE8P9Gfjl1qE0dQEkjjsQ5RM+UjT8HOL2miLWOpFazdiUFZx6JRdndtUi0XkA5cqnDukt7BE7sQSuj0huMczF7G1+u/iJa7maYV433uFWFXx7pLvbHThBwQfHBy4UQ5VxM+LmBjggLSJe3FqlKXuvr22eg8YmL4utm2La6VIsP1rqJpLFD4UWHp58qx7q/yui2t2lMVp3mvqIfZPBg0z6vplKSO+PZCwgKDjVO+RAnUHFWHa81oMPhRcNXDg5/2xwGHm99JUWM5/7NdFh6R2PIBFbk4d8we5szLHhI+zS7eX6u3SQudqpiJ+k/jnvBXp68drdqwupOS6ElqsfKZyz2zcv4sN6foYUxV4lral/y/iPJf32tR4ySukN8qTZIDznBMZJJgG7UcsAPSQMT+hL8V7lGpPJ+KA2xXEdCFxJuCusC+dAwG6RswbiE5eeLJwwpmJ8urHh+PzfeLqwM5woVMwiW1iD6Rz56IK/+jY0zc2jHUg58JotRISMNBmHxbWbEOzuaQiI1h45oOCLQlcK3A2iEu0EVLLW+xMZSlCM9E09bhztjXsNp5NQX+iaMdh9WepjiXx+pqpRTIDxHgP6Obvm6VEwG0lvJAbYHp7kEW75sgEbxrAm a+tyr2dK jJEd30sPPJ+0uBs+Z8kKdYRTOWf6IOZoKbI/EmvUaMeSkhNQPaBXUEs3Yzy5Dg0u9UzdyDYtNgKGhOmj9aRmZK0X5PK8075WQKprkXFKxgNlSV7jgVW1TohWO01E4jfCRLBSZlER2pN3Wl7qR+PonIdHyST3YWrhiKrSckcrRhnf+rQkwac9mOUzpFTafNk5V/ZfT/1qwd0ONDQgdaG/M4e9ifzmAhb7rFJMkSEA00bZfMLqcuYe12w3PQuI8GEl/sT+IZMpTJDtKZqq4jlfqptu2OtvurqGNW5SzaQLPRIHA9jG9qv3V2euI1F/vi185aFWSszXhMVIKWLD54fP5aLoh4ZDwnHnfy30UOqrkUrymx8pcpkTp7BF5aVJ8bGUOLBiBikALg45CfSs= 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