From patchwork Tue Feb 6 08:48:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Muhammad Usama Anjum X-Patchwork-Id: 13546864 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 8CEB2C48286 for ; Tue, 6 Feb 2024 08:48:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 030D46B006E; Tue, 6 Feb 2024 03:48:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F238F6B0071; Tue, 6 Feb 2024 03:48:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DEAC56B0072; Tue, 6 Feb 2024 03:48:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id CD5276B006E for ; Tue, 6 Feb 2024 03:48:35 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 758FDA0BF5 for ; Tue, 6 Feb 2024 08:48:35 +0000 (UTC) X-FDA: 81760752990.16.A3B13CE Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf25.hostedemail.com (Postfix) with ESMTP id C323EA0003 for ; Tue, 6 Feb 2024 08:48:33 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=oHBD9nEY; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf25.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 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=1707209314; 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: references:dkim-signature; bh=52BOaMVUM1qOw8R0QYiPT4dZBJ9B/kJn4tJ8pYk+AhI=; b=zhxSWxLBvamCaTP1tiZ9uG7SdRACjfwM3AgCwpBlvFNsKZUskFUloL0lOJeNDA/zUu6vha rmpmtPtvIWPLWPSBC/3gUN9R9848h+zw25VMWRJj9AFnlSp/ws4CbPsoZb196IiFce6R6o O+imlyC5e7cDEzg3WmD9zX2QrLq0vs4= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=oHBD9nEY; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf25.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707209314; a=rsa-sha256; cv=none; b=zEqC2bTmcQAnnscXO8TqMNbrZ+i+d/qEHUWo7Uefgia6TF/j3uPsbSy4eEeNB8po2SJyyi BOh+sqMeVPuOsJdlDxNna1XUB9/SoOYhuOe2emAcR5+qNIPUKsmzFEXBai0ocWl1jtGjx8 Kd14cZsh0jGqJ+4TdufTQUaZGH0tRcw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1707209312; bh=aT/CkiJIYu8ukwP0OeHxZgN3d9mcS6SutCMYSXztOEw=; h=From:To:Cc:Subject:Date:From; b=oHBD9nEYlfXbX0kGB1OD8e3b3FDSusD5ao88V1k54bq/fP1UPoCh4WlCpEj0zDgKI zzDGFy0VDBc4u2FVDOZNkAb/hY9p1xHkLvANakuW7xod4ZTVo/3XacBlPfmn5mXoCn FyjpPLijwAyt/Tts6DGZ6ZsWAx9rx5lDlbJJqzC4U/qruMAvVvAMC161hO0LiREh/c BMwO7r63QTTj4+rJMsnd9J+WeAPDpMkDg7neU1COnIL7aIU7o1pui4lp01LYjVqZ/A hAOqHo2pUaS3loFPYmgb9VBSAD5w7S9UKnoV42sjTDStrz217I5cG2OpDdcS0eQ57Q i1MUmVbSf+QqA== Received: from localhost.localdomain (ec2-34-240-57-77.eu-west-1.compute.amazonaws.com [34.240.57.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id B7C43378000E; Tue, 6 Feb 2024 08:48:29 +0000 (UTC) From: Muhammad Usama Anjum To: Andrew Morton Cc: Paul Gofman , usama.anjum@collabora.com, kernel@collabora.com, =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Andrei Vagin , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/migrate: preserve exact soft-dirty state Date: Tue, 6 Feb 2024 13:48:01 +0500 Message-ID: <20240206084838.34560-1-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: C323EA0003 X-Stat-Signature: dchuu7r1pw45i4cnntqrxk1j8d8rip31 X-HE-Tag: 1707209313-875072 X-HE-Meta: U2FsdGVkX1+WtLviwEQLnxC3PjnKLkSw9bzPkT2S0BveDHQvJfQlmZGuMsTUZvpdQqVYKoqSxVIwgvcOAtueSVCWJQISPnkPQUg/6E7/EsKmnYpSvVYK/QRWd+R8Fgaa38Dxfz3MtkEkvVO0yF/M5SnVQn+GJMzQjJkhRpKNOWD7a/NvgWpVqeH4gYeZt+lXJ1iCCfnNPpFMU49Fg7RAuavbt+bMohWGCIA7nmRlyOne2w5up73Lj3NBB4XX/AN8M3ZSFQcg7rt5vdRUpIDJQd4n2XBssa801PJImWGCRaWQAaZZ7PVeEgq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b3jYTlzypHCNwU1EIheMbcyA08VojctkxJCdzaZfeM8zq0n6mfy+ji+cej6TkiMc7l7oe+I 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: List-Subscribe: List-Unsubscribe: From: Paul Gofman pte_mkdirty() sets both _PAGE_DIRTY and _PAGE_SOFT_DIRTY bits. The _PAGE_SOFT_DIRTY can get set even if it wasn't set on original page before migration. This makes non-soft-dirty pages soft-dirty just because of migration/compaction. Clear the _PAGE_SOFT_DIRTY flag if it wasn't set on original page. By definition of soft-dirty feature, there can be spurious soft-dirty pages because of kernel's internal activity such as VMA merging or migration/compaction. This patch is eliminating the spurious soft-dirty pages because of migration/compaction. Cc: Michał Mirosław Cc: Andrei Vagin Signed-off-by: Paul Gofman Signed-off-by: Muhammad Usama Anjum Acked-by: Andrei Vagin --- mm/migrate.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index cc9f2bcd73b4..05d6ca437321 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -211,14 +211,17 @@ static bool remove_migration_pte(struct folio *folio, folio_get(folio); pte = mk_pte(new, READ_ONCE(vma->vm_page_prot)); old_pte = ptep_get(pvmw.pte); - if (pte_swp_soft_dirty(old_pte)) - pte = pte_mksoft_dirty(pte); entry = pte_to_swp_entry(old_pte); if (!is_migration_entry_young(entry)) pte = pte_mkold(pte); if (folio_test_dirty(folio) && is_migration_entry_dirty(entry)) pte = pte_mkdirty(pte); + if (pte_swp_soft_dirty(old_pte)) + pte = pte_mksoft_dirty(pte); + else + pte = pte_clear_soft_dirty(pte); + if (is_writable_migration_entry(entry)) pte = pte_mkwrite(pte, vma); else if (pte_swp_uffd_wp(old_pte))