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 6C8EAC00140 for ; Wed, 10 Aug 2022 19:21:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C0F276B0071; Wed, 10 Aug 2022 15:21:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BBE786B0072; Wed, 10 Aug 2022 15:21:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A86258E0001; Wed, 10 Aug 2022 15:21:25 -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 99E746B0071 for ; Wed, 10 Aug 2022 15:21:25 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 70678ABDBE for ; Wed, 10 Aug 2022 19:21:25 +0000 (UTC) X-FDA: 79784651730.03.A6B2C42 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf14.hostedemail.com (Postfix) with ESMTP id E694F1000A9 for ; Wed, 10 Aug 2022 19:21:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660159284; 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=IKtPa1b3cUCAoD5B4a66OaPs8cv/e+sQ8MAuok0BMJk=; b=JlitoCq55TGYzTDqCsFkMYNxJgIm7IoZpSJ8K7mD66ipF6NEEahXc20X3k0Ku3fWVFg3ak ybiT1E5OHzkk2blB2p2+tlpujlXsHcHbJu14/xh7XiL9sdQKtHVY4wSQC/CB/+mAxElDcN efuf5lX+u166WoUFchP5m+eCMHIIKBE= Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-656-tbif7zfEOLeTsZxxlSqezQ-1; Wed, 10 Aug 2022 15:21:23 -0400 X-MC-Unique: tbif7zfEOLeTsZxxlSqezQ-1 Received: by mail-io1-f71.google.com with SMTP id t7-20020a6b6407000000b00684ed320f97so4608414iog.11 for ; Wed, 10 Aug 2022 12:21:23 -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=IKtPa1b3cUCAoD5B4a66OaPs8cv/e+sQ8MAuok0BMJk=; b=7G1tPBE3vvvkKAoESGIKp64OD6jCG99xsJlPa7UiUVzhCS8dVi7ZXVlC51ZHAWvszp i98ln/V6YEEDsnlwOVH0IaZZ3bxI5AhfjUqRa4H9oqAa5ee7slgFnb/m1i8yocgPaB9g QyOUXLYks4XST4r/tss4skdHfP4cuQk3bAkTNGYeuMk0sUmKzEh8Y/m1LGA+oMlLEybk jn2LrwkRkv6lMI+r8YLNjsHSpKdypm2ck2fh1+pUppka6pXLphZZcOUDpdUmPAn9CX8J 6MzcNTH/ExJp+0d+5dcDaKE5zkhWEAV231WlIwOA5jKhXzJriwTsR37KQsPw3/XhElqj t6Dw== X-Gm-Message-State: ACgBeo2XSTyrAjtKWXoTcshZYAcbWcAGtS/GujHxdXTo9XmDoSFgH9iK Jm3D0wqjtnzWRxavTWsAIBWx3x5B6o0jSTTeRhp5GAhAZYdar/qwrCgrAePoLcPmIpg2NODxJwg ig3/cl1j+xvU= X-Received: by 2002:a05:6638:24d1:b0:343:25c0:a2d with SMTP id y17-20020a05663824d100b0034325c00a2dmr5549456jat.76.1660159282508; Wed, 10 Aug 2022 12:21:22 -0700 (PDT) X-Google-Smtp-Source: AA6agR4Zr+K6kcQFSlk0EDzaIxLZX04rwSbXbxvY4k9mieXk0+MMJr5Dg2hqHkj3y5+L+2pU6lMo7Q== X-Received: by 2002:a05:6638:24d1:b0:343:25c0:a2d with SMTP id y17-20020a05663824d100b0034325c00a2dmr5549442jat.76.1660159282311; Wed, 10 Aug 2022 12:21:22 -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 bo20-20020a056638439400b00339ef592279sm7636398jab.127.2022.08.10.12.21.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 12:21:21 -0700 (PDT) Date: Wed, 10 Aug 2022 15:21:20 -0400 From: Peter Xu To: "Huang, Ying" Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrea Arcangeli , David Hildenbrand , Minchan Kim , Andrew Morton , Vlastimil Babka , Nadav Amit , Hugh Dickins , Andi Kleen , "Kirill A . Shutemov" , Christoph Hellwig , Alistair Popple , Jason Gunthorpe Subject: Re: [PATCH v2 2/2] mm: Remember young/dirty bit for page migrations Message-ID: References: <20220804203952.53665-1-peterx@redhat.com> <20220804203952.53665-3-peterx@redhat.com> <877d3hhksz.fsf@yhuang6-desk2.ccr.corp.intel.com> <87wnbggbqa.fsf@yhuang6-desk2.ccr.corp.intel.com> MIME-Version: 1.0 In-Reply-To: <87wnbggbqa.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660159285; a=rsa-sha256; cv=none; b=QwgGO/mzaf5j0Ia0Jvub4Nz1xNCk9vWUTyeGr/r9XuGFg6fW3wxqILGJKphoD362M7D/0o c4QC7u3Fz+TOFdYvuAB3hxGr2iyile0dmQzEq4D4Zlt8CTCkPQNMuTDdXnxN77NWHQm6fP a2JTyWZ3fosC69Q1ZYrGAXsl3uTkQDc= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JlitoCq5; spf=pass (imf14.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@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=1660159285; 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=IKtPa1b3cUCAoD5B4a66OaPs8cv/e+sQ8MAuok0BMJk=; b=g2fJ2j7BVamAhXrlxU7Eq0Sl+03WGahNm6Los/77BvIMo1pNRlUPKbk3zXlhbS9Zjv4HI/ aeWG8JKb3XWoaia+fst216cMx1rchew4xfpYN5hv7zv7qnRVMLsJPeI+hJOmAIqz32A8cH vxJC+1DRMEChmEmAAcdFdFNVbHJpmBM= X-Rspam-User: X-Stat-Signature: jj8hxru1qw9wamf5t4yyh7oceyeayt1b X-Rspamd-Queue-Id: E694F1000A9 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JlitoCq5; spf=pass (imf14.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam01 X-HE-Tag: 1660159284-45557 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 Wed, Aug 10, 2022 at 08:53:49AM +0800, Huang, Ying wrote: > Peter Xu writes: > > > On Tue, Aug 09, 2022 at 04:40:12PM +0800, Huang, Ying wrote: > [snip] > > > >> I don't find pte_dirty() is synced to PageDirty() as in > >> try_to_migrate_one(). Is it a issue in the original code? > > > > I think it has? There is: > > > > /* Set the dirty flag on the folio now the pte is gone. */ > > if (pte_dirty(pteval)) > > folio_mark_dirty(folio); > > > > Sorry, my original words are confusing. Yes, there's dirty bit syncing > in try_to_migrate_one(). But I don't find that in migrate_device.c > > $ grep dirty mm/migrate_device.c > if (pte_soft_dirty(pte)) > swp_pte = pte_swp_mksoft_dirty(swp_pte); > if (pte_swp_soft_dirty(pte)) > swp_pte = pte_swp_mksoft_dirty(swp_pte); > entry = pte_mkwrite(pte_mkdirty(entry)); > > I guess that migrate_device.c is used to migrate between CPU visible > page to CPU un-visible page (device visible), so the rule is different? IIUC migrate_vma_collect() handles migrations for both directions (RAM <-> device mem). Yeah, indeed I also didn't see how migrate_vma_collect_pmd() handles the carry-over of pte dirty to page dirty, which looks a bit odd. I also don't see why the dirty bit doesn't need to be maintained, e.g. when a previous page was dirty then after migration of ram->dev->ram it seems to be clean with current code. Another scenario is, even if the page was clean, as long as page migrated to device mem, device DMAed to the page, then page migrated back to RAM. I also didn't see how we could detect the DMAs and set pte/page dirty properly after migrated back. Copy Alistair and Jason.. -- Peter Xu