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 2A419C4332F for ; Tue, 22 Nov 2022 08:37:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E9FB6B0071; Tue, 22 Nov 2022 03:37:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 99A0C6B0073; Tue, 22 Nov 2022 03:37:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 862F16B0074; Tue, 22 Nov 2022 03:37:03 -0500 (EST) 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 7696F6B0071 for ; Tue, 22 Nov 2022 03:37:03 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 29343160D49 for ; Tue, 22 Nov 2022 08:37:03 +0000 (UTC) X-FDA: 80160423126.13.B80D1C0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id BF9F540012 for ; Tue, 22 Nov 2022 08:37:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669106222; 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=QLruKr0Jr2eahRROoPUxGVXkoCQ/kZQ9K7AIqvtY87M=; b=TjsRt3I/j0P59n2suUmMgjor4CuRMZufl+HBEKU55kCee41Q2WKkVoSdOeyTAQpXsIrEdG knjvg42OahMI60ukHMdlyhi5UDTqUTK/eEdDfoS1yOgW6bB6oAlliG1JuIDPlB+BXappfu mil83SzOqMQLwBPSnws2vUOyJb2vAyw= 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-140-ble2k09uMlqlWuM-Xqhfjg-1; Tue, 22 Nov 2022 03:37:00 -0500 X-MC-Unique: ble2k09uMlqlWuM-Xqhfjg-1 Received: by mail-wr1-f72.google.com with SMTP id w11-20020adfbacb000000b002418a90da01so3986822wrg.16 for ; Tue, 22 Nov 2022 00:37:00 -0800 (PST) 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 :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=QLruKr0Jr2eahRROoPUxGVXkoCQ/kZQ9K7AIqvtY87M=; b=70E5O6gjq5KFm6A4+xEgteEmRsryEEAHs5e/tDzwcw3gjJDCO3SXWPdYCG1BORjHkB QYDs1wgVqhsDTG59TzyB2FkJYwdqetqlfL7MTd8lsq8WLMo4f+uQbUkGHXeyznZffhht u2Fh6d7d82XUanNW0ZZDlQSvw475vQVfdXNqz8ssqO+xnvgA7YX2jytvCWINLNTpDe70 jqgteVZa5bq1qxkbYx8jTBPeW356+Hmi9qDW3iZFGiV3ieBujlWqewMgTMgdHd8VH87N cJH5jSIb3XaWq08e7SRG0XjtkTmSYrcCmCvh7Kfy1YPxowE/iMcVmRVqRxIfyWqKKwkL E0Cw== X-Gm-Message-State: ANoB5pmDthOaDpWf7mBcu8STNrlZfEcBbgUrdy3lLBBD8HOoew4nDVB2 4f6wJSAjGKmTUGO6s+LmK/zw9OiHKcuguGnJphdVIa9LhYBjM7DE5p56rFbQoLLg8eIAXL1aOTp 6eBRr6tFPClg= X-Received: by 2002:adf:f38a:0:b0:236:5270:7347 with SMTP id m10-20020adff38a000000b0023652707347mr13776275wro.35.1669106219572; Tue, 22 Nov 2022 00:36:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Jpq8EHSKME9hAJw0iZDI3FnUcjkLgwyOZsbm/iLUpg4dCKbX5r0QXPyxe27p+C7Ps22imIA== X-Received: by 2002:adf:f38a:0:b0:236:5270:7347 with SMTP id m10-20020adff38a000000b0023652707347mr13776245wro.35.1669106219206; Tue, 22 Nov 2022 00:36:59 -0800 (PST) Received: from [192.168.3.108] (p5b0c65c4.dip0.t-ipconnect.de. [91.12.101.196]) by smtp.gmail.com with ESMTPSA id a5-20020adfe5c5000000b00241bc209ae0sm12955717wrn.32.2022.11.22.00.36.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Nov 2022 00:36:58 -0800 (PST) Message-ID: Date: Tue, 22 Nov 2022 09:36:57 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCH] mm: set the vma flags dirty before testing if it is mergeable To: Muhammad Usama Anjum , Andrew Morton , Cyrill Gorcunov Cc: Mel Gorman , Peter Xu , Andrei Vagin , kernel@collabora.com, stable@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20221122082442.1938606-1-usama.anjum@collabora.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20221122082442.1938606-1-usama.anjum@collabora.com> 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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669106222; a=rsa-sha256; cv=none; b=aOQpWVQoJSohRClbk8sBxpJZxCgb8td8MJ7QnqZeFWbfO4ODarbNWiEFZNc08oAJIVnESt l76d6k6iB0ciwbE9aArxrsb0p3qABaqZ0uCFTXQGRNUTNMF0SzPOuHYPqjmnwsVEf5bYjk UgqyZoUrJjo5Di0AWpYE7yTIwTIITiM= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="TjsRt3I/"; spf=pass (imf17.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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669106222; 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=QLruKr0Jr2eahRROoPUxGVXkoCQ/kZQ9K7AIqvtY87M=; b=Ifjj9rtUW1zimUjWnTFWx7oYghhN5BvxMNB8v6Syn3GmoazUI1qNg8dHLogDgVRKcN8lxh k8w9NW9gY8sEKHY/4xhlGG2HYJwTRuZcs9JptOI26C6QsadNoP8EhZhWOVoVuILaqW07vT /kCiSRhLuPYECMoxC2oy85EOnDssdZE= X-Stat-Signature: o41ozzg3fsn7fw9wcp369d9gmhsx6t7h X-Rspamd-Queue-Id: BF9F540012 X-Rspam-User: Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="TjsRt3I/"; spf=pass (imf17.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: rspam02 X-HE-Tag: 1669106222-91443 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 22.11.22 09:24, Muhammad Usama Anjum wrote: > The VM_SOFTDIRTY should be set in the vma flags to be tested if new > allocation should be merged in previous vma or not. With this patch, > the new allocations are merged in the previous VMAs. > > I've tested it by reverting the commit 34228d473efe ("mm: ignore > VM_SOFTDIRTY on VMA merging") and after adding this following patch, > I'm seeing that all the new allocations done through mmap() are merged > in the previous VMAs. The number of VMAs doesn't increase drastically > which had contributed to the crash of gimp. If I run the same test after > reverting and not including this patch, the number of VMAs keep on > increasing with every mmap() syscall which proves this patch. > > The commit 34228d473efe ("mm: ignore VM_SOFTDIRTY on VMA merging") > seems like a workaround. But it lets the soft-dirty and non-soft-dirty > VMA to get merged. It helps in avoiding the creation of too many VMAs. > But it creates the problem while adding the feature of clearing the > soft-dirty status of only a part of the memory region. > > Cc: > Fixes: d9104d1ca966 ("mm: track vma changes with VM_SOFTDIRTY bit") > Signed-off-by: Muhammad Usama Anjum > --- > We need more testing of this patch. > > While implementing clear soft-dirty bit for a range of address space, I'm > facing an issue. The non-soft dirty VMA gets merged sometimes with the soft > dirty VMA. Thus the non-soft dirty VMA become dirty which is undesirable. > When discussed with the some other developers they consider it the > regression. Why the non-soft dirty page should appear as soft dirty when it > isn't soft dirty in reality? I agree with them. Should we revert > 34228d473efe or find a workaround in the IOCTL? > > * Revert may cause the VMAs to expand in uncontrollable situation where the > soft dirty bit of a lot of memory regions or the whole address space is > being cleared again and again. AFAIK normal process must either be only > clearing a few memory regions. So the applications should be okay. There is > still chance of regressions if some applications are already using the > soft-dirty bit. I'm not sure how to test it. > > * Add a flag in the IOCTL to ignore the dirtiness of VMA. The user will > surely lose the functionality to detect reused memory regions. But the > extraneous soft-dirty pages would not appear. I'm trying to do this in the > patch series [1]. Some discussion is going on that this fails with some > mprotect use case [2]. I still need to have a look at the mprotect selftest > to see how and why this fails. I think this can be implemented after some > more work probably in mprotect side. > > [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/ > --- > mm/mmap.c | 21 +++++++++++---------- > 1 file changed, 11 insertions(+), 10 deletions(-) > > diff --git a/mm/mmap.c b/mm/mmap.c > index f9b96b387a6f..6934b8f61fdc 100644 > --- a/mm/mmap.c > +++ b/mm/mmap.c > @@ -1708,6 +1708,15 @@ unsigned long mmap_region(struct file *file, unsigned long addr, > vm_flags |= VM_ACCOUNT; > } > > + /* > + * New (or expanded) vma always get soft dirty status. > + * Otherwise user-space soft-dirty page tracker won't > + * be able to distinguish situation when vma area unmapped, > + * then new mapped in-place (which must be aimed as > + * a completely new data area). > + */ > + vm_flags |= VM_SOFTDIRTY; > + > /* > * Can we just expand an old mapping? > */ > @@ -1823,15 +1832,6 @@ unsigned long mmap_region(struct file *file, unsigned long addr, > if (file) > uprobe_mmap(vma); > > - /* > - * New (or expanded) vma always get soft dirty status. > - * Otherwise user-space soft-dirty page tracker won't > - * be able to distinguish situation when vma area unmapped, > - * then new mapped in-place (which must be aimed as > - * a completely new data area). > - */ > - vma->vm_flags |= VM_SOFTDIRTY; > - > vma_set_page_prot(vma); vma_set_page_prot(vma) has to be called after adjusting vma->vm_flags. Did not look into the details here, but that jumped at me. -- Thanks, David / dhildenb