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 4C609C433FE for ; Thu, 29 Sep 2022 11:12:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B3A248D0003; Thu, 29 Sep 2022 07:12:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AEA398D0001; Thu, 29 Sep 2022 07:12:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98AC48D0003; Thu, 29 Sep 2022 07:12:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 89BA98D0001 for ; Thu, 29 Sep 2022 07:12:50 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 440E3140CEC for ; Thu, 29 Sep 2022 11:12:50 +0000 (UTC) X-FDA: 79964860500.25.CD9E2CA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 46C8620011 for ; Thu, 29 Sep 2022 11:12:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664449968; 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=8n1tzf6l3ZAoFU3fQ1/TWRNrSqhpIqUhxfDxIN+Hz74=; b=EiiOEz5ubK5qwEqT3TJG4v3xPfAvZRG3TMPlGYkXVF/soXI4pFfhoskc4K2/oKryTaKYeZ /vJTHeeOkun5v8y8XW30hfjiFHw0V6CJrn3I5Cxox9tZ1kF1/tbKoX+BLv8l4N4Rgs7mwz TAj9iAvvypH1ayTveUzhJzQaqSnLQM0= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-602-epyQXMuBPSKPom-XV-L_Sg-1; Thu, 29 Sep 2022 07:12:47 -0400 X-MC-Unique: epyQXMuBPSKPom-XV-L_Sg-1 Received: by mail-wr1-f72.google.com with SMTP id i1-20020adfa501000000b0022cd1e1137bso399646wrb.0 for ; Thu, 29 Sep 2022 04:12:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date; bh=8n1tzf6l3ZAoFU3fQ1/TWRNrSqhpIqUhxfDxIN+Hz74=; b=op639xsLo3Y7784DsipXHgvrmRdpGYY68C//NGYrp2ReUM7otz9gJxDY3WbC1K8HBq tnXKcrG4epGQQHsHollZqk1pC3C7cpTY+jMBFVut5PqaX/UbjZxaSRCK7PUza877TMJq WwEq2oPaPUwX42zRumgsj/nZw9B34+QUUOgZVWPrUOrayx2A3MbMArW/k2Cc2rrxnnSV l0aSJkGGr48r6UJUNQDRQjmgDk320rLuMpVejLueXvqEb+EwlJA5Po9fpj8k9ZZkGUdT VwAICj/srEx94EFAm2QL2HOWkBdTUSFs+Bx77+/JULQ/ssmyMcZumAORaLbJiij8fwwy YeGw== X-Gm-Message-State: ACrzQf3OCZgTE9FgqWNQ4L2FpmIUUpY+JqZb0sxQqN6sTeiYqbzPHryD sLMXa30at9CXw8196tlN1TfFSTgelm0IroqB+iHSfeBxmq7KPiVYY8B7t+KirqPoOwd1hnxTzKJ BrKgmjOkPV2s= X-Received: by 2002:a05:600c:524d:b0:3b4:91ee:933e with SMTP id fc13-20020a05600c524d00b003b491ee933emr1950011wmb.80.1664449966525; Thu, 29 Sep 2022 04:12:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM63urpPF0tMcfh0uoQnrtkfZy8NEBrgdlFDDyB16VVL5UtdAS8f9v9m0kQfC4/rjvgN3MujyQ== X-Received: by 2002:a05:600c:524d:b0:3b4:91ee:933e with SMTP id fc13-20020a05600c524d00b003b491ee933emr1949988wmb.80.1664449966189; Thu, 29 Sep 2022 04:12:46 -0700 (PDT) Received: from ?IPV6:2003:cb:c705:ce00:b5d:2b28:1eb5:9245? (p200300cbc705ce000b5d2b281eb59245.dip0.t-ipconnect.de. [2003:cb:c705:ce00:b5d:2b28:1eb5:9245]) by smtp.gmail.com with ESMTPSA id y3-20020a5d4ac3000000b0022ac672654dsm6690558wrs.58.2022.09.29.04.12.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 29 Sep 2022 04:12:45 -0700 (PDT) Message-ID: <745f75a4-6a2a-630f-8228-0c5e081588e7@redhat.com> Date: Thu, 29 Sep 2022 13:12:44 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Subject: Re: [PATCH 0/3] ksm: fix incorrect count of merged pages when enabling use_zero_pages To: Claudio Imbrenda Cc: xu.xin.sc@gmail.com, akpm@linux-foundation.org, imbrenda@linux.vnet.ibm.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, xu xin References: <20220929025206.280970-1-xu.xin16@zte.com.cn> <4a3daba6-18f9-d252-697c-197f65578c44@redhat.com> <20220929123630.0951b199@p-imbrenda> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20220929123630.0951b199@p-imbrenda> 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 ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EiiOEz5u; spf=pass (imf03.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664449969; a=rsa-sha256; cv=none; b=U3tuPy9/qL9AixO8b8P5yUR4vlnQSHohwrKPa3x18TlaYXqAJVRngK5QpbQ2IJovq2WV/B you/BDZQuBaB5st4VDdyoPYMV1yY54VGVYK1VSYVhNm96rGtoV6olCLOV9lEfXR2KGQQ95 SCMUCbf1T7RoQVplMa4PxuuYYuNW6vk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664449969; 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=8n1tzf6l3ZAoFU3fQ1/TWRNrSqhpIqUhxfDxIN+Hz74=; b=t8T6+/oY7mDIEtKJ9zxvTjegHDWAUr3rJLyO0r/JC/LFGN0JylblX/46IP1F3Jn6xyxO3r xkxak1DtBUNGVzMfKxBqbqefgrvASUoKnC1SHLlsPM9PQIFXs7f+RZ6viruqw5KtTEZP0W +8TW9f9mKmDoCIGtNw44jBvg9RdkmGQ= X-Rspam-User: Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EiiOEz5u; spf=pass (imf03.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam10 X-Stat-Signature: u8zo9qca8mwxscf95t97p3tjmfij3epk X-Rspamd-Queue-Id: 46C8620011 X-HE-Tag: 1664449969-819066 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 29.09.22 12:36, Claudio Imbrenda wrote: > On Thu, 29 Sep 2022 11:21:44 +0200 > David Hildenbrand wrote: > >> On 29.09.22 04:52, xu.xin.sc@gmail.com wrote: >>> 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 >>> after 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 the rmap_items of these ksm zero pages are not >>> appended to The Stable Tree of KSM. >>> >>> We need to add the count of empty pages to let users know how many empty >>> pages are merged with kernel zero page(s). >>> >>> Please see the subsequent patches for details. >> >> Just raising the topic here because it's related to the KSM usage of the >> shared zero-page: >> >> 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). It will only unshare actual >> KSM pages. We might not want want to blindly unshare all shared >> zeropages in applicable VMAs ... using a dedicated shared zero (KSM) >> page -- instead of the generic zero page -- might be one way to handle >> this cleaner. > > I don't understand why do you need this. > > first of all, one zero page would not be enough (depending on the > architecture, e.g. on s390x you need many). the whole point of zero > page merging is that one zero page is not enough. I don't follow. Having multiple ones is a pure optimization on s390x (I recall something about cache coloring), no? So why should we blindly care in the special KSM use case here? > > second, once a page is merged with a zero page, it's not really handled > by KSM anymore. if you have a big allocation, of which you only touch a > few pages, would the rest be considered "merged"? no, it's just zero > pages, right? If you haven't touched memory, there is nothing populated -- no shared zeropage. We only populate shared zeropages in private anonymous mappings on read access without prior write. > this is the same, except that we take present pages with zeroes in it > and we discard them and map them to zero pages. it's kinda like if we > had never touched them. MADV_UNMERGEABLE "Undo the effect of an earlier MADV_MERGEABLE operation on the specified address range; KSM unmerges whatever pages it had merged in the address range specified by addr and length." Now please explain to me how not undoing a zeropage merging is correct according to this documentation. -- Thanks, David / dhildenb