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 24CCCC433FE for ; Mon, 21 Nov 2022 15:00:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ABEB96B0071; Mon, 21 Nov 2022 10:00:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A6EE46B0073; Mon, 21 Nov 2022 10:00:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 936136B0074; Mon, 21 Nov 2022 10:00:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8403B6B0071 for ; Mon, 21 Nov 2022 10:00:50 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3A3C91C6653 for ; Mon, 21 Nov 2022 15:00:50 +0000 (UTC) X-FDA: 80157761460.30.9581B0F Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by imf11.hostedemail.com (Postfix) with ESMTP id D28CA40026 for ; Mon, 21 Nov 2022 15:00:47 +0000 (UTC) Received: from [192.168.10.9] (unknown [39.45.241.105]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: usama.anjum) by madras.collabora.co.uk (Postfix) with ESMTPSA id 7C72966029A5; Mon, 21 Nov 2022 15:00:39 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1669042845; bh=M3Swul50R+VFzoP/f23mK9UtV+LTG0RgsqO+dggNkSQ=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=SVo6rWoKLhGqK/3yW6FwCRbq8ukHC9MYFCfi4LnciyABINq/fPBgOtwhni7jrmyM3 jdaB6k0MblEL+tf8xTkEi5QnaLjltCWUjQFAC0gkuWWsD/Va5Vl2Bx4qVrO9Su4uAm r5+4cGFzZj8QnQl711qeIVBRHF9EeV5KAq9Gqwn+CEi+flLuWnb8poVbW5iI8WTNfM /Hnz9Hs+8EUauSedzSfarCQbh4OBkqH1GyxE/1G9SOEnqHkQN0ugM32Q+9mPJgvSgM ZfVpKaqqcQVmDUzImfIoAqSd9sYm47H27BoBNJEX230JJKn29bA7xH+bU6gwDgvbtK QQKeO6/p4XZOA== Message-ID: <254130e7-7fb1-6cf1-e8fa-5bc2d4450431@collabora.com> Date: Mon, 21 Nov 2022 20:00:36 +0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Cc: Muhammad Usama Anjum , Suren Baghdasaryan , Greg KH , Christian Brauner , Peter Xu , Yang Shi , Vlastimil Babka , Zach O'Keefe , "Matthew Wilcox (Oracle)" , "Gustavo A. R. Silva" , Dan Williams , kernel@collabora.com, Gabriel Krisman Bertazi , Peter Enderborg , "open list : KERNEL SELFTEST FRAMEWORK" , Shuah Khan , open list , "open list : PROC FILESYSTEM" , "open list : MEMORY MANAGEMENT" Subject: Re: [PATCH v6 0/3] Implement IOCTL to get and/or the clear info about PTEs Content-Language: en-US To: David Hildenbrand , =?UTF-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= , Andrei Vagin , Danylo Mocherniuk , Alexander Viro , Andrew Morton , Paul Gofman References: <20221109102303.851281-1-usama.anjum@collabora.com> <9c167d01-ef09-ec4e-b4a1-2fff62bf01fe@redhat.com> <6fdce544-8d4f-8b3c-9208-735769a9e624@collabora.com> From: Muhammad Usama Anjum In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669042848; a=rsa-sha256; cv=none; b=rRlq8KEZllK7Bl8GlSItxIqRLchPiMo5HgVe389vVeCOm9DjaqoORE8OEzo77NXaLB1vSH iR3vKrD5oAGEJFDJxEFbCWO3jjKmuNrLU2jyy54/zTrUlELUheYOovgH9YSC2Z9Oi7f1TI uD8lHJmSdQNAVki9IDmuL4eQ5MsIqoE= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=SVo6rWoK; dmarc=pass (policy=none) header.from=collabora.com; spf=pass (imf11.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.172 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669042848; 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=AawY9bDOylY2uuq1mG9fSI5coM+ziz2e9UKj7RA4TNs=; b=Hxi5NdKF/dMOJwZDCnTJcQ/swyXFM6pUp5eYoFmtyPNg+yf6RziWt8egqbutA2JQqG+foN TkXMD0MCz7UnU9BSkOD4DAWqVyFYIdhg8H0uKmrwbNY0G0WFPv6EQiKSzQv/Vbyvg79Wps C4C5ImFZcnB44mOXPE8Q6oJV0xw2q1U= Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=SVo6rWoK; dmarc=pass (policy=none) header.from=collabora.com; spf=pass (imf11.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.172 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com X-Stat-Signature: ohbwei9ric5geasjq5rw9zudzeia4gxy X-Rspamd-Queue-Id: D28CA40026 X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1669042847-447736 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: Hello, Thank you for replying. On 11/14/22 8:46 PM, David Hildenbrand wrote: >> The soft-dirtiness is stored in the PTE. VMA is marked dirty to store the >> dirtiness for reused regions. Clearing the soft-dirty status of whole >> process is straight forward. When we want to clear/monitor the >> soft-dirtiness of a part of the virtual memory, there is a lot of internal >> noise. We don't want the non-dirty pages to become dirty because of how the >> soft-dirty feature has been working. Soft-dirty feature wasn't being used >> the way we want to use now. While monitoring a part of memory, it is not >> acceptable to get non-dirty pages as dirty. Non-dirty pages become dirty >> when the two VMAs are merged without considering if they both are dirty or >> not (34228d473efe). To monitor changes over the memory, sometimes VMAs are >> split to clear the soft-dirty bit in the VMA flags. But sometimes kernel >> decide to merge them backup. It is so waste of resources. > > Maybe you'd want a per-process option to not merge if the VM_SOFTDIRTY > property differs. But that might be just one alternative for handling this > case. > >> >> To keep things consistent, the default behavior of the IOCTL is to output >> even the extra non-dirty pages as dirty from the kernel noise. A optional >> PAGEMAP_NO_REUSED_REGIONS flag is added for those use cases which aren't >> tolerant of extra non-dirty pages. This flag can be considered as something >> which is by-passing the already present buggy implementation in the kernel. >> It is not buggy per say as the issue can be solved if we don't allow the >> two VMA which have different soft-dirty bits to get merged. But we are >> allowing that so that the total number of VMAs doesn't increase. This was >> acceptable at the time, but now with the use case of monitoring a part of >> memory for soft-dirty doesn't want this merging. So either we need to >> revert 34228d473efe and PAGEMAP_NO_REUSED_REGIONS flag will not be needed >> or we should allow PAGEMAP_NO_REUSED_REGIONS or similar mechanism to ignore >> the extra dirty pages which aren't dirty in reality. >> >> When PAGEMAP_NO_REUSED_REGIONS flag is used, only the PTEs are checked to >> find if the pages are dirty. So re-used regions cannot be detected. This >> has the only side-effect of not checking the VMAs. So this is limitation of >> using this flag which should be acceptable in the current state of code. >> This limitation is okay for the users as they can clear the soft-dirty bit >> of the VMA before starting to monitor a range of memory for soft-dirtiness. >> >> >>> Please separate that part out from the other changes; I am still not >>> convinced that we want this and what the semantical implications are. >>> >>> Let's take a look at an example: can_change_pte_writable() >>> >>>      /* Do we need write faults for softdirty tracking? */ >>>      if (vma_soft_dirty_enabled(vma) && !pte_soft_dirty(pte)) >>>          return false; >>> >>> We care about PTE softdirty tracking, if it is enabled for the VMA. >>> Tracking is enabled if: vma_soft_dirty_enabled() >>> >>>      /* >>>       * Soft-dirty is kind of special: its tracking is enabled when >>>       * the vma flags not set. >>>       */ >>>      return !(vma->vm_flags & VM_SOFTDIRTY); >>> >>> Consequently, if VM_SOFTDIRTY is set, we are not considering the soft_dirty >>> PTE bits accordingly. >> Sorry, I'm unable to completely grasp the meaning of the example. We have >> followed clear_refs_write() to write the soft-dirty bit clearing code in >> the current patch. Dirtiness of the VMA and the PTE may be set >> independently. Newer allocated memory has dirty bit set in the VMA. When >> something is written the memory, the soft dirty bit is set in the PTEs as >> well regardless if the soft dirty bit is set in the VMA or not. >> > > Let me try to find a simple explanation: > > After clearing a SOFTDIRTY PTE flag inside an area with VM_SOFTDIRTY set, > there are ways that PTE could get written to and it could become dirty, > without the PTE becoming softdirty. > > Essentially, inside a VMA with VM_SOFTDIRTY set, the PTE softdirty values > might be stale: there might be entries that are softdirty even though the > PTE is *not* marked softdirty. Can someone please share the example to reproduce this? In all of my testing, even if I ignore VM_SOFTDIRTY and only base my decision of soft-dirtiness on individual pages, it always passes. > > These are, AFAIU, the current semantics, and I am not sure if we want user > space to explicitly work around that. > >>> >>> >>> I'd suggest moving forward without this controversial >>> PAGEMAP_NO_REUSED_REGIONS functionality for now, and preparing it as a >>> clear add-on we can discuss separately.Like I've described above, I've >>> only added this flag to not get the >> non-dirty pages as dirty. Can there be some alternative to adding this >> flag? Please suggest. > > Please split it out into a separate patch for now. We can discuss further > what the semantics are and if there are better alternatives for that. In > the meantime, you could move forward without PAGEMAP_NO_REUSED_REGIONS > while we are discussing them further. > -- BR, Muhammad Usama Anjum