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 0B999C25B0E for ; Mon, 15 Aug 2022 19:18:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 647BE6B0073; Mon, 15 Aug 2022 15:18:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F7016B0075; Mon, 15 Aug 2022 15:18:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BFD48D0001; Mon, 15 Aug 2022 15:18:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 3BF886B0073 for ; Mon, 15 Aug 2022 15:18:56 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0EFDA140FBD for ; Mon, 15 Aug 2022 19:18:56 +0000 (UTC) X-FDA: 79802789472.06.7AAF5B5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 3F3721801AC for ; Mon, 15 Aug 2022 19:18:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660591134; 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: in-reply-to:in-reply-to:references:references; bh=trYiUZWGHSUh+Fi/mUD7Vj9TWPb8FmuPVtaP1Bo49SM=; b=Sp3BtlDzZGXKUSB5ED1mDrxz5KXpE5SdfJnFXsyMdu9keO69E5vaxuC4c0/sahVHWvNmIb Xssf6QUmC1z/cyIRyRZf7CpG5dEvoYywKz0jjb4S+tzgGayZT+DGD2Io7f24l4iI4qzOKC 31fKxjW8qO+IVIPhvcepG92DmWfEMrU= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-3-3JQ-L4k_PY-73uULEQqZEw-1; Mon, 15 Aug 2022 15:18:53 -0400 X-MC-Unique: 3JQ-L4k_PY-73uULEQqZEw-1 Received: by mail-qv1-f71.google.com with SMTP id kk30-20020a056214509e00b004780ff644d7so3041926qvb.12 for ; Mon, 15 Aug 2022 12:18:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=trYiUZWGHSUh+Fi/mUD7Vj9TWPb8FmuPVtaP1Bo49SM=; b=qodUUal21r5o/YFGigCgkwv4D4rw5tIvveFiMqpbjVNWpqRI6CnbqUJ8FCGQaa45cv Bk//fnXOG7Nf7ddRxqiNrSf8zcP7aVtn0FGxO8pwvGSlXbGD5Rx9Wjju5nAg0qNRmfOw JdnPQFELNELAEJXA3gwgUP7gfRRZ1jXz10bLsomWDAS+0DYy4bhnmYcswnv+XreEDtcY ohEpT5dPrKkSGuV5jrO/TXpRGucItQ2taYTt+PRH4sXgkeffeUGNAZzk8+mdaiJgpqVV Rto4uYCIzZE/p4+1Q9AlXGI0RBgC6haZWdEYjfhXv4CKdP3PXL+/6NSUt3B1cDHwJStt voYg== X-Gm-Message-State: ACgBeo1Smlrm70nLTK7unBdnao+cz9lxQN9fUTQ8JEQTvYaKcSVF5BFv bUP4FMm3WJ10YxlglFj1Aq5sYEkHOUWKApUmdRxZlOFX+F9mX4gnrPCfPRJ/mgvvks/CnV1L/Ml Zj2l7epq58dQ= X-Received: by 2002:a05:622a:30d:b0:343:63d1:3751 with SMTP id q13-20020a05622a030d00b0034363d13751mr15450252qtw.679.1660591133252; Mon, 15 Aug 2022 12:18:53 -0700 (PDT) X-Google-Smtp-Source: AA6agR6J0tMp+p84xYVRm1RNDQxrWF79DfIoMrksUSH4K5nPKwTdkxuhOXkdYZ5vNOGu4LScwGYtJQ== X-Received: by 2002:a05:622a:30d:b0:343:63d1:3751 with SMTP id q13-20020a05622a030d00b0034363d13751mr15450229qtw.679.1660591133009; Mon, 15 Aug 2022 12:18:53 -0700 (PDT) Received: from xz-m1.local (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id bs30-20020a05620a471e00b006b910e588a4sm9888488qkb.129.2022.08.15.12.18.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 12:18:52 -0700 (PDT) Date: Mon, 15 Aug 2022 15:18:50 -0400 From: Peter Xu To: "Huang, Ying" Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Minchan Kim , David Hildenbrand , Nadav Amit , Andrew Morton , Hugh Dickins , Vlastimil Babka , Andrea Arcangeli , Andi Kleen , "Kirill A . Shutemov" Subject: Re: [PATCH v3 5/7] mm: Remember young/dirty bit for page migrations Message-ID: References: <20220809220100.20033-1-peterx@redhat.com> <20220809220100.20033-6-peterx@redhat.com> <87pmh6dwdr.fsf@yhuang6-desk2.ccr.corp.intel.com> MIME-Version: 1.0 In-Reply-To: <87pmh6dwdr.fsf@yhuang6-desk2.ccr.corp.intel.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660591135; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=trYiUZWGHSUh+Fi/mUD7Vj9TWPb8FmuPVtaP1Bo49SM=; b=thFLRtJUCQbgGINnSbq/Y7rl2eN7/U/nZMDLURCJKaWrxvbdxq/iosb1lJ4+q01ms8iq+T BQNZXW1yxS9I9uQX6gW2p5hAebP09F0+C0Qq5wRTf/OHzu4UJNPmw9sgeaRE4pcCoABfS4 n0UdTimvrSjLS7B2EzHhuE1arFvh5rw= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Sp3BtlDz; spf=pass (imf16.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660591135; a=rsa-sha256; cv=none; b=QT/oP1KoYbBxvxsM8kHHnGkrvH/8G2mgr5QbtiiD1gsXIGycp5iVb9fzfsc+NjfSQ7SKys AS3urqHzlYNtXQ01+h2gxc7QLM6wQJtRWIky9Moc8rp3gtX9GI1nvk+3UKcRXXFBGDUuDq 94dGvXsYgdhp9nU+6BJMjL4zWorZIvw= X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3F3721801AC X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Sp3BtlDz; spf=pass (imf16.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: 1i5565eqry1max9tgnby6dnr4uepc9r4 X-HE-Tag: 1660591135-569224 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 Fri, Aug 12, 2022 at 10:32:48AM +0800, Huang, Ying wrote: > Peter Xu writes: > > > On Tue, Aug 09, 2022 at 06:00:58PM -0400, Peter Xu wrote: > >> diff --git a/mm/migrate_device.c b/mm/migrate_device.c > >> index 27fb37d65476..699f821b8443 100644 > >> --- a/mm/migrate_device.c > >> +++ b/mm/migrate_device.c > >> @@ -221,6 +221,10 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, > >> else > >> entry = make_readable_migration_entry( > >> page_to_pfn(page)); > >> + if (pte_young(pte)) > >> + entry = make_migration_entry_young(entry); > >> + if (pte_dirty(pte)) > >> + entry = make_migration_entry_dirty(entry); > >> swp_pte = swp_entry_to_pte(entry); > >> if (pte_present(pte)) { > >> if (pte_soft_dirty(pte)) > > > > This change needs to be wrapped with pte_present() at least.. > > > > I also just noticed that this change probably won't help anyway because: > > > > (1) When ram->device, the pte will finally be replaced with a device > > private entry, and device private entry does not yet support A/D, it > > means A/D will be dropped again, > > > > (2) When device->ram, we are missing information on either A/D bits, or > > even if device private entries start to suport A/D, it's still not > > clear whether we should take device read/write into considerations > > too on the page A/D bits to be accurate. > > > > I think I'll probably keep the code there for completeness, but I think it > > won't really help much until more things are done. > > It appears that there are more issues. Between "pte = *ptep" and pte > clear, CPU may set A/D bit in PTE, so we may need to update pte when > clearing PTE. Agreed, I didn't see it a huge problem with current code, but it should be better in that way. > And I don't find the TLB is flushed in some cases after PTE is cleared. I think it's okay to not flush tlb if pte not present. But maybe you're talking about something else? Thanks, -- Peter Xu