Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3014471rwb; Wed, 30 Nov 2022 14:10:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf4kMOIKObr38M2WJfj2GY6dD2dDzydzRMaGhTtmTk166OB50JXfnxVdzeZkBEnkfJVSVz/j X-Received: by 2002:a17:902:aa06:b0:182:f36b:3221 with SMTP id be6-20020a170902aa0600b00182f36b3221mr44221529plb.36.1669846215016; Wed, 30 Nov 2022 14:10:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669846215; cv=none; d=google.com; s=arc-20160816; b=BOLjTN3nNeMch/aRwiiX4fuNKa/JswsXlQohdjely/+SkZTWrPB6SxXDkYDwtwKGGO +rlmsnAKnt+BLCtCJq5Pt5NUI0KobDLOf23aMCrsENkUebRGIdlK+qPSSrc35sdkIxwr EB/pQ2YWFzFzanqd5zr+oh/m8w8hGZnqe80v2BHZ7cUFGdj+/131QV7LdySubDKOHhmV ILV28LRHCzbHVHm4Sk+5aFLRbA6Nc3uk2EYrZ3cKt2obGvhXlYr9Wc0DcR18w6CX25cq 6ITgWw3BgrK8mTCh2X441DyytdE/K305qZKqPpG9QPlERPnsa1tCznfrYfwoG95ZTz5e 8DfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=SoweguhVdE9rkHNrrE2YnwSJZtPETT6uz4SqPHeAVg8=; b=W2BKuEINxxnlBeeNrGszcCbnxC65aA/LI+KGA4BtukjIeCTgKjyzaZu36JF0JovgzL mqB16eZTVfJBKTv3OzkxLySjWU72uvneCZP1t4F6G9RWCQ90ZbgJc8R2v7Hv0EXytY1p Ffkx7aCRIgPIp21umh/ewGFyv73wgpQqnEwOgVVM6LFFQlUbGq1rIn0HtFekVDJ1tPf1 qY5EIGaIhPR6SXk2uYAqYV4kaCmzEDngnwdJSUDU7P7sgXhjUAufU3bmh0Cq8DrXTirh DpQbF3rrDJeqB+CdwS3bsTxs6HTPuwFea0TuSEbyGNG+2i0+SGjHNLF9TEM0cUD/+Qos dRYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IB9l1Juu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r8-20020a632048000000b0046e9babe7a1si2411293pgm.54.2022.11.30.14.09.56; Wed, 30 Nov 2022 14:10:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IB9l1Juu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229695AbiK3VoF (ORCPT + 84 others); Wed, 30 Nov 2022 16:44:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbiK3VoD (ORCPT ); Wed, 30 Nov 2022 16:44:03 -0500 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10EDB31ED9; Wed, 30 Nov 2022 13:44:02 -0800 (PST) Received: by mail-lf1-x12b.google.com with SMTP id j4so28987804lfk.0; Wed, 30 Nov 2022 13:44:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=SoweguhVdE9rkHNrrE2YnwSJZtPETT6uz4SqPHeAVg8=; b=IB9l1JuueX9k7YvnYxgtAXfq1Y4yF0UbKLjtpuxrqZRmtpkYLkm5pndlEj0U31dfxz IhuGO+OvT35+dXY/iQOfGYso+sP5TLLqHlwAWesH6mzVHf/8dUvvK3WZxJ90zbZ1d0Sa Abg6Zz/UCTYW63icUCyTyjEuWoE3gwAO0hrxmKCTCZGKl+veLeX5MuYsmy2JVioaF4df kOlMrN1xJ/WnhO8YLRdD4Cj0tgfyEQDogfUfe+sszj5GBL0mZNw4LKCkLvdRi2JQRkAq WsPcoSlRD0eHDBIlvhrMGB6496NLHe/9um3DhTN/qa4VW4lFbbaNLLV9K33PvHKli6bq plNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SoweguhVdE9rkHNrrE2YnwSJZtPETT6uz4SqPHeAVg8=; b=7n+O75Rfl+xZ+TnVJmTULXfInuIS/q2+nAcpibxzQ5fSH8DZJ1wU2UvtTXfw+k0SAn AadmCLthq8CMEBWsMknORKjYlemWut/tVGiUtOYdt4iruQGN8bQV6t5WTugFp96VKG4Z u74IOsLIFPfEdD/4H8A+bMdVMzwFQZ8bcXTMJFJGGdL+Hbfae5/fx2Cre8sJB4iJOz3i 0Wkm6YeV30QFmVY4l3cplvVrR7srWtCP+cgXjK+8qAGlokC4Il+zWZ2KJjZBsFX3NLcX YBEfjWlGUCtxj5FDyFltPnEW63UtKtUCAI9WqLzvEzXEL3UVxhRZsdDbY0LG6NxDjHl0 9HGA== X-Gm-Message-State: ANoB5plr85vj4wAcSXrpW4xtvmTSUJvYLts6pGRkk2hq2/ixtudYB/dq QOSBepHxzIP/GPF55eTY/KY= X-Received: by 2002:ac2:47ea:0:b0:4a2:2f4b:2f30 with SMTP id b10-20020ac247ea000000b004a22f4b2f30mr23696915lfp.357.1669844640254; Wed, 30 Nov 2022 13:44:00 -0800 (PST) Received: from grain.localdomain ([5.18.253.97]) by smtp.gmail.com with ESMTPSA id a19-20020ac25e73000000b0049110ba325asm385891lfr.158.2022.11.30.13.43.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 13:43:59 -0800 (PST) Received: by grain.localdomain (Postfix, from userid 1000) id B77925A0020; Thu, 1 Dec 2022 00:43:58 +0300 (MSK) Date: Thu, 1 Dec 2022 00:43:58 +0300 From: Cyrill Gorcunov To: Muhammad Usama Anjum Cc: Andrew Morton , Mel Gorman , Peter Xu , David Hildenbrand , Andrei Vagin , kernel@collabora.com, stable@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm: set the vma flags dirty before testing if it is mergeable Message-ID: References: <20221122115007.2787017-1-usama.anjum@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.7 (2022-08-07) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 29, 2022 at 06:49:53PM +0500, Muhammad Usama Anjum wrote: > > ioctl might be an option indeed > Thank you for supporting this. I'll track down the issue caused by > remapping and mprotect mentioned here: > https://lore.kernel.org/all/bfcae708-db21-04b4-0bbe-712badd03071@redhat.com/ > and we can proceed with this. > > > > >> > >> [1] https://lore.kernel.org/all/20221109102303.851281-1-usama.anjum@collabora.com/ > >> [2] https://lore.kernel.org/all/bfcae708-db21-04b4-0bbe-712badd03071@redhat.com/ Hi Muhammad! Hopefully I'll find some time soon to read all these conversation, so for now my replies might be simply out of context. Initially the vma softdirty was needed to catch a case where memory remapped inplace and what is worse it might have _same_ ptes dirty after clear_refs call. IOW, the process allocated vma and write some data into. Then we (page tracker process) come in, read pagemap and clear softdirty bits, and page traker process terminates. While we're not watching the program unmaps vma, maps new one with same size and what is worse it writes data to the same pages as we saw at last scan time. So without VM_SOFTDIRTY we won't be able to find that this VMA is actually carrying new pages which were not yet dumped. And similar scenario can be for merging: say former vma has been 4 pages, we scan it and clear dirty pages at low and hight address. Then process splits this VMA to two with gap inbetween and then map new area which merge them all into one vma, and process can write again pages to same address so we have to mark this new VMA as softdirty. If only I rememeber correctly about the initial idea :)