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 471E9C04A6A for ; Thu, 3 Aug 2023 12:33:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C3E11280243; Thu, 3 Aug 2023 08:33:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BED7728022C; Thu, 3 Aug 2023 08:33:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A8E3A280243; Thu, 3 Aug 2023 08:33:02 -0400 (EDT) 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 99F2D28022C for ; Thu, 3 Aug 2023 08:33:02 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6B3E9A105C for ; Thu, 3 Aug 2023 12:33:02 +0000 (UTC) X-FDA: 81082733004.22.93F6B62 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf26.hostedemail.com (Postfix) with ESMTP id C22DF140005 for ; Thu, 3 Aug 2023 12:32:59 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KKW56C+E; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf26.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691065979; 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=mCy6ACBk2KCNXN+/iDvlXEbsgVPUPclqPGko8x8fDms=; b=d+tNQslcTSeSAuk8XmkzBUYMl0poM2op6Fdg3vqoycxIvPr5iO8Nt+E7jBOXXXrsNP+Tu1 xF5LuWb5DkJ2O1B8tASfH6bOixR4zxa5wr/jGMrPAkxfL/hdAK1pubUcykqtqziin5qYZn mNGM7ac27vQuosXoeX7aViSYabA6abw= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KKW56C+E; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf26.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691065979; a=rsa-sha256; cv=none; b=1V6ro6hfLDkX/uVe0t8IY9SPhxwe6zNlYLsfSv+58RkZvORbwCELee58mQ1Pa0H5TtzEAN mIQhOcinC7emVfnUG+Cw6VUr+7pF+LkXWwxK4LUKw0go6ic0mfz9OCDA9X8+L5QVzmNJpR beYYo2Iz1QYXvTXLK6E5HE7atuAA+rM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691065979; 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=mCy6ACBk2KCNXN+/iDvlXEbsgVPUPclqPGko8x8fDms=; b=KKW56C+E0drJl0Is1Xe+ajEqg0r0cBkCRd9CCcTVvdS/B+UdVnLpuPdYYFoiKKNWiFhUTP NiXcPmWw70gvJa2GaN2/VUIOirQcKVUFXAf3etuO4V9QwHLokczxzBpmSDWf1x3/MtS8bn NWLAxfVcZJsdbUfONMGX0rzpePRwxlI= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-437-1DJlobRCMNi4PjPup7Yp8A-1; Thu, 03 Aug 2023 08:32:57 -0400 X-MC-Unique: 1DJlobRCMNi4PjPup7Yp8A-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-3fc08d6a40cso5984105e9.0 for ; Thu, 03 Aug 2023 05:32:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691065976; x=1691670776; 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:message-id :reply-to; bh=mCy6ACBk2KCNXN+/iDvlXEbsgVPUPclqPGko8x8fDms=; b=kWQWRl49dn0VqPMK5SD5xRvYLW48mJ4bkeerTFgRxiGyvKV5ogM0JHIj1Dv98po7wZ oQ2G2+XQfyb2q931WQePrEf/pp6blHsd/Z8wRdbnais21hRZQ+ajciPfIIyrI0vlbNVd zzL3V1g+cZIk2rSXomvhKTCS/gaGoYe+hSiJ+3wP1u0eGEcRalQ6XPg2tgyAgANUZG1k Igbia7EA1MIIl7SPu7Z6QbXon/aqZUdaq1WED1fV/n9nUz1W0+3H6nzJ/exgTaq+siuZ 6co15qOmSstMScG+OuxTYCnHjJV68p24AM37QkhjCGBH1SvqxrAmefw6GbHqkFksX3Qg n5fQ== X-Gm-Message-State: ABy/qLZX5W6C9FdJUQft7AT2bbXMNStGSlSxAO4oHyIOjc3R0L6utyOv 5PR7DgoZLBuPUybbTc6R+1hgvyW8+T6um3zSdsEZYjF8AlnOCXtGGJGrDvNaKCuS3JSkfXCAJ3Q m3sy0OlbTzaI= X-Received: by 2002:a05:600c:2213:b0:3fe:2813:6130 with SMTP id z19-20020a05600c221300b003fe28136130mr7305705wml.22.1691065976699; Thu, 03 Aug 2023 05:32:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlFxhdZ+Hook9QUXIMSL0v2ViZvLCsw4Q6coD0i/eEas+TGS7eIHRK9GWXTyHThhfA67P3jRzA== X-Received: by 2002:a05:600c:2213:b0:3fe:2813:6130 with SMTP id z19-20020a05600c221300b003fe28136130mr7305684wml.22.1691065976344; Thu, 03 Aug 2023 05:32:56 -0700 (PDT) Received: from ?IPV6:2003:cb:c718:9a00:a5f5:5315:b9fa:64df? (p200300cbc7189a00a5f55315b9fa64df.dip0.t-ipconnect.de. [2003:cb:c718:9a00:a5f5:5315:b9fa:64df]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c029300b003fe2de3f94fsm4212666wmk.12.2023.08.03.05.32.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Aug 2023 05:32:55 -0700 (PDT) Message-ID: <2aee6681-f756-9ace-74d8-2f1e1e7b3ae6@redhat.com> Date: Thu, 3 Aug 2023 14:32:54 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [RFC v1 1/3] mm/mmu_notifier: Add a new notifier for mapping updates (new pages) To: Jason Gunthorpe , "Kasireddy, Vivek" Cc: "Kim, Dongwon" , "Chang, Junxiao" , "dri-devel@lists.freedesktop.org" , Alistair Popple , Hugh Dickins , Peter Xu , "linux-mm@kvack.org" , Gerd Hoffmann , Mike Kravetz References: <48f22686-2c1b-fd9d-91ba-da6105d410db@redhat.com> <3427735b-2a73-2df7-ebd9-0d1066a55771@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: 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 X-Rspamd-Queue-Id: C22DF140005 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 3z419i47jmcqta1wenyhd1wtzxeg9fg9 X-HE-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viDTctJlXcu1I+El6NQZvRn2urQRMhA6Nwe+W9wmIZs+XYAVyxwIcL8AdAC4yvpX8jHumNV0wmzSMhkofWz2hWA5GNqNSPw2gnlMLP87cl8aJcr15fS/rDIbNAh3gS7+NNvQwLo/VJpfxZVMVThyPSr/AsJlnQZb+k2F7BcHgLQHNmp2WRsr7//zasSUBysW4Xv9oX7r4WVQ6FJ8vIkuSuRWwDtZszUx8KxCpAcgS0YL9oQzTHHTVitT2BZHX9OjZ4w8n1VFFgoSYryNWy3KTJL/toLpRzg1/es1fQPhTl4JxQKlK1avLoS9ZfxtanWGJa3KwpiQkNKYZvHmU+XFUR/XyYVddVXB+Zbr5Su7N36+ajwjAbxKVw6tVM3qZRZaIs7/joa1JS6rhmi9zA5Wwt2YThAsArUIVn+P2affgcFLSBKvS1lfH0jf2Ib9HHnLlx01xJsF64So1Jy0a62tvSt3RP0UM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000004, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 03.08.23 14:14, Jason Gunthorpe wrote: > On Thu, Aug 03, 2023 at 07:35:51AM +0000, Kasireddy, Vivek wrote: >> Hi Jason, >> >>>>> Right, the "the zero pages are changed into writable pages" in your >>>>> above comment just might not apply, because there won't be any page >>>>> replacement (hopefully :) ). >>> >>>> If the page replacement does not happen when there are new writes to the >>>> area where the hole previously existed, then would we still get an >>> invalidate >>>> when this happens? Is there any other way to get notified when the zeroed >>>> page is written to if the invalidate does not get triggered? >>> >>> What David is saying is that memfd does not use the zero page >>> optimization for hole punches. Any access to the memory, including >>> read-only access through hmm_range_fault() will allocate unique >>> pages. Since there is no zero page and no zero-page replacement there >>> is no issue with invalidations. > >> It looks like even with hmm_range_fault(), the invalidate does not get >> triggered when the hole is refilled with new pages because of writes. >> This is probably because hmm_range_fault() does not fault in any pages >> that get invalidated later when writes occur. > > hmm_range_fault() returns the current content of the VMAs, or it > faults. If it returns pages then it came from one of these two places. > > If your VMA is incoherent with what you are doing then you have bigger > problems, or maybe you found a bug. > >> The above log messages are seen immediately after the hole is punched. As >> you can see, hmm_range_fault() returns the pfns of old pages and not zero >> pages. And, I see the below messages (with patch #2 in this series applied) >> as the hole is refilled after writes: > > I don't know what you are doing, but it is something wrong or you've > found a bug in the memfds. Maybe THP is involved? I recently had to dig that out for an internal discussion: "Currently when truncating shmem file, if the range is partial of THP (start or end is in the middle of THP), the pages actually will just get cleared rather than being freed unless the range cover the whole THP. Even though all the subpages are truncated (randomly or sequentially), the THP may still be kept in page cache. This might be fine for some usecases which prefer preserving THP." My recollection is that this behavior was never changed. https://lore.kernel.org/all/1575420174-19171-1-git-send-email-yang.shi@linux.alibaba.com/ -- Cheers, David / dhildenb