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 CAC09C77B70 for ; Mon, 17 Apr 2023 08:03:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 480028E0002; Mon, 17 Apr 2023 04:03:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 40A368E0001; Mon, 17 Apr 2023 04:03:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2833C8E0002; Mon, 17 Apr 2023 04:03:09 -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 161718E0001 for ; Mon, 17 Apr 2023 04:03:09 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C42198045E for ; Mon, 17 Apr 2023 08:03:08 +0000 (UTC) X-FDA: 80690142456.10.0D232C3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 8909E40005 for ; Mon, 17 Apr 2023 08:03:05 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Viwfsxtn; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681718585; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=k+xDztrP5K0atvexPe7AsFD1VGHJO8wE5vvIvghj6Aw=; b=tNTWDw1csgctokIPtSW1CfqM0GVxcOcanKyuncXNDe04YVGHUfW6CDpWu/C/aeI8YNuxgz NkhIKQgIIYbocUjlAJfaekKUiZ4+M32aEKlfBontwpGQp1SHHKVKzBV2EUnUIAbd3tm8tB 5j16oGHq03jVLtsM4hAato2xG8oLndw= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Viwfsxtn; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681718585; a=rsa-sha256; cv=none; b=SAoWCwN2xI5YMsHzvG54+xOlBEzAriyEmWLCT3kPAURooZrcGkpKUqg/H1F8qLsSfmdC5c LvNGzIe+Mz5KX6VCImZjkrrBCytzicB2ivUg4B5oFZ+GTh1x4Dl/jw+qZddU4Auwv3ZveF 2eDm3bp9I8ptfzBsMQqR5S61dlzS51w= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681718584; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k+xDztrP5K0atvexPe7AsFD1VGHJO8wE5vvIvghj6Aw=; b=ViwfsxtnMuQE5mjtHk6KPmDRvH6NtqOmnl8O/YKH3dsMqX1SV6bNNOurKxo3yG4zOFaKYc 3r6EgpA/gSu4irw+hQyiTzogGtnxVlOaUFjnQc+oPe1K8DQNWStlLj+zSjhhncI9rAjTMe m6ipMRvT/YDz42sKbUdSKb+g6XNuT4Y= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-266-XFD1PhAaNvKFn0XtgrPYAA-1; Mon, 17 Apr 2023 04:03:03 -0400 X-MC-Unique: XFD1PhAaNvKFn0XtgrPYAA-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-3f16ef3bf06so3288525e9.3 for ; Mon, 17 Apr 2023 01:03:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681718582; x=1684310582; h=content-transfer-encoding:in-reply-to:subject:organization:from :content-language:references:cc:to:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=k+xDztrP5K0atvexPe7AsFD1VGHJO8wE5vvIvghj6Aw=; b=g/xoQspgIVXU8vpAzL2rXUng5b9Z+QTsTG3eKuKmNpOxQu/cHTAVAnTQ9PYrjXCkKK eD6I3wW+Q7MLkhseNqBjk3pTFt1tga7U+9V/BFqVIgPVwPnBxsTlCip7t+84ax3KcZci a1c3sS9UrnFTPpj7DxdFVVpRJg0KRDInIdyB9hLE9h0in3KCnkFK7Ne3n13OPFyRzhKB b9aR7zAe8o602Ux8Ll5zlISirKIowrx4IR1xkSQUoiiaHmeThNMS3hBIPZe55CiC/Rea m9ZAP36IgBrCN8aI/v+WP6fp2YTPRdKJMeylui//ZBZqlLocbD39aUT6zFx8hDn1gqfG fd5g== X-Gm-Message-State: AAQBX9eTMGGPiJc+9lIsDOqk+bv87+IZV75JYKcXW8ml9q4OpAb+JoA+ TXKAnMwCS61qgi2Kjd1RPB6pq0kFfH2OaZJuLrWppwu3trIcqLJwBZbkAsKsPY2Hkq2pxL9d3vQ oWl7t61ldwyA= X-Received: by 2002:adf:fa4a:0:b0:2ce:fd37:938c with SMTP id y10-20020adffa4a000000b002cefd37938cmr4246121wrr.50.1681718582463; Mon, 17 Apr 2023 01:03:02 -0700 (PDT) X-Google-Smtp-Source: AKy350YE4uFxV+bAUN+xrFK6nXNSGjCTnPBk85Csxmz3uAjeiolmxCGm7Fm9/ZEZFEUhZZ8oXqyKvQ== X-Received: by 2002:adf:fa4a:0:b0:2ce:fd37:938c with SMTP id y10-20020adffa4a000000b002cefd37938cmr4246100wrr.50.1681718582077; Mon, 17 Apr 2023 01:03:02 -0700 (PDT) Received: from ?IPV6:2003:cb:c700:fc00:db07:68a9:6af5:ecdf? (p200300cbc700fc00db0768a96af5ecdf.dip0.t-ipconnect.de. [2003:cb:c700:fc00:db07:68a9:6af5:ecdf]) by smtp.gmail.com with ESMTPSA id c8-20020a5d63c8000000b002f4c2ea66absm9877045wrw.85.2023.04.17.01.03.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 Apr 2023 01:03:01 -0700 (PDT) Message-ID: Date: Mon, 17 Apr 2023 10:03:00 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 To: yang.yang29@zte.com.cn, akpm@linux-foundation.org Cc: imbrenda@linux.ibm.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ran.xiaokai@zte.com.cn, xu.xin.sc@gmail.com, xu.xin16@zte.com.cn, Stefan Roesch References: <202304131346489021903@zte.com.cn> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v7 0/6] ksm: support tracking KSM-placed zero-pages In-Reply-To: <202304131346489021903@zte.com.cn> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 8909E40005 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: uyor34qit4wamddzmnrmy6qzp9qqtyns X-HE-Tag: 1681718585-14106 X-HE-Meta: U2FsdGVkX18IG8Ue4kS+Mht063FoBtOCMLNWjdgyZNyEtVx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qG15D1GNIXPF1s+z9nW5v5fegebTUbIBFn6bzD+38TNM4n33egrauHakU1uHNE76jGlsFQoLVGbOnTlfXN8MP5L1/Wu3HmAQHgTpBdwAmHOvF5f/mIgLyGGOVUHfbxPB+FfxYLSBVrp/aR1gA4pL7sQc355ONtII/YNveQqIb3iZ9twx9ZjteR0u45M59j7ZHwsJ5Qqs8ksuvj6sQPPKhQyveTuSpCpqEd5+XRKEvfw+YwBYq4QT751rE34eKZj0sCsl7gpJIP9Df4h6ySj0ntDpLxwR/CDLBy2tYZ95F05oqX4NXdWQybLDSnxWNa/9cHWW7/HinCfHEPhZsD6bTEWGzcnn5NzRHOrhwUZg1LffR8U8fFFGJ+NYzCoSb686/GkR7VkzkIzwxzO6Af8qmtdfGJnwvxvjhb9UF/iJg1TbyJGkblV6rVCdUX7CVQAtO2cJcRO6aylJ3J1/gr5hsdIBNQdfpVuLZaRrdHXk7yup7E 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: On 13.04.23 07:46, yang.yang29@zte.com.cn wrote: > 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. > Thanks for the update! > the patch uses pte_mkdirty (related with architecture) to mark KSM-placed > zero pages. Some architecture(like sparc64) treat R/O dirty PTEs as > writable, which will break KSM pages state (wrprotect) and affect With [1] that should be resolved and we should be able to enable it unconditionally. Further, ideally this should get based on [2], such that we can include the zeropages in the ksm and per-mm profit calculation. Last but not least, I realized that we also have to handle the case when khugepaged replaces a shared zeropage by a THP. I think that should be easy by adjusting the counters in the the is_zero_pfn() handling in mm/khugepaged.c:__collapse_huge_page_copy(). > the KSM functionality. For safety, we restrict this feature only to the > tested and known-working architechtures (ARM, ARM64, and X86) fow now. > > Change log > ---------- > 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. Yeah, with [1] this can be further simplified. I'll be on vacation starting on Thursday for ~1.5 weeks, not sure if I get to review before that. But it's unlikely that we'll make the upcoming merge windows, so I guess we still have time (especially, for [1] and [2] to land) [1] https://lkml.kernel.org/r/20230411142512.438404-4-david@redhat.com [2] https://lkml.kernel.org/r/20230413233115.1878303-1-shr@devkernel.io -- Thanks, David / dhildenb