Message ID | 20230606050149.25699-1-mpenttil@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3157259vqr; Mon, 5 Jun 2023 22:26:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4JWapP1KxFeS+Lf3tr5IKwylZ149YMKG5WLAaLuRSHtzWpvvTvdr3Zc+LR56LziGpgY5oB X-Received: by 2002:a05:6a00:22cc:b0:63d:2d99:2e7c with SMTP id f12-20020a056a0022cc00b0063d2d992e7cmr1301039pfj.0.1686029193309; Mon, 05 Jun 2023 22:26:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686029193; cv=none; d=google.com; s=arc-20160816; b=R35HFchGkkYF8hIjX25oacyZk32FIB1ysMYxDn4Xkd/TiQWb/R3F9wR3e+367m+5Q7 cIuwD1paM9PDb6jkFBrV8CBGS1BulomHl4wgprSKAzGUiMyeB+Ix4lx8ZMwRh7vcvFZK uIEj/RdaNTpE97NGfS+sEa/b9/5urpCHrGflmiSPZH7aSblUTHM5bRwiuuIhy7rWzmBk c2pfUhjwoGBN5zWPMrjSHHwWwGaRv7SjFLKDB06uHrcxORF/dEyE/TmjP79h4TlgW6Ii JlyeYFk3JXAm2CFqx2wWiC86/nR7VwU2IoI4mrwgETBFKnHF0ZrxikJrLRcDEAuPwmR4 +5VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Q6TiThBigVDB9aOyNqXFDkJ+jf7GDr7BiU78S3IKVbg=; b=DwVdy81Pr38fdFlET+YKKOOLcBY684h/FIbyreNIHWmW5k6+fmFvOY2VPb9+YrSlor ftlLALj1YPzQiYU41REDF7xTtxuLtyVZ0QRKz01piGcYEaJhKpyOlH1emIi/9ldsBhb3 BcvjgTvBzNJ9GqHtGhRrbvvr+A670xYKzfhrOyHW/EBcUPDj+2/0OZXeppOAePXPPGPO e/Fovdc41mJgFsCVTBmIqigDSE77yQk1jG39ujA7RopPbVCOYEfvg8XY/2TaGODdmmM9 E9Fobx/h3KRCnvCNNmDvCmnc2ZkhgrGrA9zl6L5rigAugBgkFczEZdrx03MqYXEG695n rWkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DXOSmGQu; 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=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k186-20020a633dc3000000b005348977b5c5si6819632pga.97.2023.06.05.22.26.19; Mon, 05 Jun 2023 22:26:33 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=DXOSmGQu; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233187AbjFFFDS (ORCPT <rfc822;xxoosimple@gmail.com> + 99 others); Tue, 6 Jun 2023 01:03:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231419AbjFFFDP (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 6 Jun 2023 01:03:15 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3FE111A for <linux-kernel@vger.kernel.org>; Mon, 5 Jun 2023 22:02:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686027747; 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; bh=Q6TiThBigVDB9aOyNqXFDkJ+jf7GDr7BiU78S3IKVbg=; b=DXOSmGQuJPWqI3JjrijL3JdgIbSjHJVOttzKXLdF++Hah6mDhu7ZLv+4NlWG2U40tetT9/ /Lg8Qm4TtjKxwmy2D0vRPkTrUEaRJbHdbct6NuQFjUSUdwmN7gWHHz22X6YzhF35MZZKth 7JBjm/xUL0Mj7ZfawNYgve/e0H/0BSo= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-360-xb3VxhJGO8mBpvtHMTtG2w-1; Tue, 06 Jun 2023 01:02:26 -0400 X-MC-Unique: xb3VxhJGO8mBpvtHMTtG2w-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-4f61f59c230so1876194e87.2 for <linux-kernel@vger.kernel.org>; Mon, 05 Jun 2023 22:02:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686027744; x=1688619744; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Q6TiThBigVDB9aOyNqXFDkJ+jf7GDr7BiU78S3IKVbg=; b=fMPL9gS7cQgLSBdInRKU2YEEzI3BXJli5dDmEkFaF3ZPSwJ/ywL2iXf5DcHDz0Dsm3 M9YzzDr3oQMX+uH6oqAzI5VgheNClKc95lOR+Vc8cvUXWKQ8XV/hy8U1F3WrKIpZh95f 5OxuhH+3DXkZ0QjUyFiKfB7PLhd2j1+eh5rPp0jgLYEqq3cBG9IwnVgWNsbxkY4oIa0f kcolVmnFIZFoKLELmWpWcNkSuGO4nnybw8+tMO5hmtPdEaUa+65qzkfBzjc1m1S9V1Mb b13Liw6LPd2ngv89aNAR12eoQEzShvCBTAtyITajUnLSruxS1w7OKGDH9ylG+2sSoa2m SrAA== X-Gm-Message-State: AC+VfDzEiv0RBFe8RKWs7N328xMajHBUkV/opPxSRerA4cQ9d2IcM1iK xKZ9+Yw5lrXYciZ1fjgYFIAIvqBTa8YXTAE52bR3bgDNXRCOzT2q1lwf4JK010m60uGoKla0cj2 wBry4a4hCsj3u0ktrNS9DgMSKbvwb4zk3ZvDev8S1ef5ogP81XLdJ4yp2viRiwHGMtbHHESYGQv a9CZyi0K9fNw== X-Received: by 2002:ac2:5a51:0:b0:4f3:7a59:d19 with SMTP id r17-20020ac25a51000000b004f37a590d19mr509150lfn.59.1686027744592; Mon, 05 Jun 2023 22:02:24 -0700 (PDT) X-Received: by 2002:ac2:5a51:0:b0:4f3:7a59:d19 with SMTP id r17-20020ac25a51000000b004f37a590d19mr509133lfn.59.1686027744205; Mon, 05 Jun 2023 22:02:24 -0700 (PDT) Received: from mjp-Z390-AORUS-MASTER.redhat.com (62-78-130-207.bb.dnainternet.fi. [62.78.130.207]) by smtp.gmail.com with ESMTPSA id v11-20020a056512096b00b004f5bc4e80easm1323915lft.171.2023.06.05.22.02.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jun 2023 22:02:23 -0700 (PDT) From: mpenttil@redhat.com To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: =?utf-8?q?Mika_Penttil=C3=A4?= <mpenttil@redhat.com>, Alistair Popple <apopple@nvidia.com>, John Hubbard <jhubbard@nvidia.com>, Ralph Campbell <rcampbell@nvidia.com>, "Huang, Ying" <ying.huang@intel.com> Subject: [PATCH v3] mm/migrate_device: Try to handle swapcache pages Date: Tue, 6 Jun 2023 08:01:49 +0300 Message-Id: <20230606050149.25699-1-mpenttil@redhat.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767929747797880534?= X-GMAIL-MSGID: =?utf-8?q?1767929747797880534?= |
Series |
[v3] mm/migrate_device: Try to handle swapcache pages
|
|
Commit Message
Mika Penttilä
June 6, 2023, 5:01 a.m. UTC
From: Mika Penttilä <mpenttil@redhat.com> Migrating file pages and swapcache pages into device memory is not supported. The decision is done based on page_mapping(). For now, swapcache pages are not migrated. Things can however be improved, for swapcache pages. Try to get rid of the swap cache, and if successful, go ahead as with other anonymous pages. Cc: Alistair Popple <apopple@nvidia.com> Cc: John Hubbard <jhubbard@nvidia.com> Cc: Ralph Campbell <rcampbell@nvidia.com> Cc: "Huang, Ying" <ying.huang@intel.com> Reviewed-by: "Huang, Ying" <ying.huang@intel.com> Reviewed-by: Alistair Popple <apopple@nvidia.com> Signed-off-by: Mika Penttilä <mpenttil@redhat.com> --- v3: - Adjust comments - Add Reviewed-bys v2: - use folio_test_anon() (Huang, Ying) mm/migrate_device.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
Comments
On 06.06.23 07:01, mpenttil@redhat.com wrote: > From: Mika Penttilä <mpenttil@redhat.com> > > Migrating file pages and swapcache pages into device memory is not supported. > The decision is done based on page_mapping(). For now, swapcache pages are not migrated. > > Things can however be improved, for swapcache pages. Try to get rid of the swap cache, > and if successful, go ahead as with other anonymous pages. > > Cc: Alistair Popple <apopple@nvidia.com> > Cc: John Hubbard <jhubbard@nvidia.com> > Cc: Ralph Campbell <rcampbell@nvidia.com> > Cc: "Huang, Ying" <ying.huang@intel.com> > Reviewed-by: "Huang, Ying" <ying.huang@intel.com> > Reviewed-by: Alistair Popple <apopple@nvidia.com> > Signed-off-by: Mika Penttilä <mpenttil@redhat.com> > --- > > v3: > - Adjust comments > - Add Reviewed-bys > > v2: > - use folio_test_anon() (Huang, Ying) > > mm/migrate_device.c | 22 ++++++++++++++++------ > 1 file changed, 16 insertions(+), 6 deletions(-) > > diff --git a/mm/migrate_device.c b/mm/migrate_device.c > index d30c9de60b0d..f76ebccfe067 100644 > --- a/mm/migrate_device.c > +++ b/mm/migrate_device.c > @@ -747,13 +747,23 @@ static void __migrate_device_pages(unsigned long *src_pfns, > > if (is_device_private_page(newpage) || > is_device_coherent_page(newpage)) { > - /* > - * For now only support anonymous memory migrating to > - * device private or coherent memory. > - */ > + > if (mapping) { > - src_pfns[i] &= ~MIGRATE_PFN_MIGRATE; > - continue; > + struct folio *folio; > + > + folio = page_folio(page); > + > + /* > + * For now only support anonymous memory migrating to > + * device private or coherent memory. > + * > + * Try to get rid of swap cache if possible. > + * > + */ > + if (!folio_test_anon(folio) || !folio_free_swap(folio)) { > + src_pfns[i] &= ~MIGRATE_PFN_MIGRATE; > + continue; I'm pretty sure the folio has to be locked in order to call folio_free_swap().
On 06.06.23 09:44, David Hildenbrand wrote: > On 06.06.23 07:01, mpenttil@redhat.com wrote: >> From: Mika Penttilä <mpenttil@redhat.com> >> >> Migrating file pages and swapcache pages into device memory is not supported. >> The decision is done based on page_mapping(). For now, swapcache pages are not migrated. >> >> Things can however be improved, for swapcache pages. Try to get rid of the swap cache, >> and if successful, go ahead as with other anonymous pages. >> >> Cc: Alistair Popple <apopple@nvidia.com> >> Cc: John Hubbard <jhubbard@nvidia.com> >> Cc: Ralph Campbell <rcampbell@nvidia.com> >> Cc: "Huang, Ying" <ying.huang@intel.com> >> Reviewed-by: "Huang, Ying" <ying.huang@intel.com> >> Reviewed-by: Alistair Popple <apopple@nvidia.com> >> Signed-off-by: Mika Penttilä <mpenttil@redhat.com> >> --- >> >> v3: >> - Adjust comments >> - Add Reviewed-bys >> >> v2: >> - use folio_test_anon() (Huang, Ying) >> >> mm/migrate_device.c | 22 ++++++++++++++++------ >> 1 file changed, 16 insertions(+), 6 deletions(-) >> >> diff --git a/mm/migrate_device.c b/mm/migrate_device.c >> index d30c9de60b0d..f76ebccfe067 100644 >> --- a/mm/migrate_device.c >> +++ b/mm/migrate_device.c >> @@ -747,13 +747,23 @@ static void __migrate_device_pages(unsigned long *src_pfns, >> >> if (is_device_private_page(newpage) || >> is_device_coherent_page(newpage)) { >> - /* >> - * For now only support anonymous memory migrating to >> - * device private or coherent memory. >> - */ >> + >> if (mapping) { >> - src_pfns[i] &= ~MIGRATE_PFN_MIGRATE; >> - continue; >> + struct folio *folio; >> + >> + folio = page_folio(page); >> + >> + /* >> + * For now only support anonymous memory migrating to >> + * device private or coherent memory. >> + * >> + * Try to get rid of swap cache if possible. >> + * >> + */ >> + if (!folio_test_anon(folio) || !folio_free_swap(folio)) { >> + src_pfns[i] &= ~MIGRATE_PFN_MIGRATE; >> + continue; > > I'm pretty sure the folio has to be locked in order to call > folio_free_swap(). > Oh, staring at the bigger context, I assume we locked the folios via migrate_device_range(), correct?
Hi, On 6.6.2023 10.46, David Hildenbrand wrote: > On 06.06.23 09:44, David Hildenbrand wrote: >> On 06.06.23 07:01, mpenttil@redhat.com wrote: >>> From: Mika Penttilä <mpenttil@redhat.com> >>> >>> Migrating file pages and swapcache pages into device memory is not >>> supported. >>> The decision is done based on page_mapping(). For now, swapcache >>> pages are not migrated. >>> >>> Things can however be improved, for swapcache pages. Try to get rid >>> of the swap cache, >>> and if successful, go ahead as with other anonymous pages. >>> >>> Cc: Alistair Popple <apopple@nvidia.com> >>> Cc: John Hubbard <jhubbard@nvidia.com> >>> Cc: Ralph Campbell <rcampbell@nvidia.com> >>> Cc: "Huang, Ying" <ying.huang@intel.com> >>> Reviewed-by: "Huang, Ying" <ying.huang@intel.com> >>> Reviewed-by: Alistair Popple <apopple@nvidia.com> >>> Signed-off-by: Mika Penttilä <mpenttil@redhat.com> >>> --- >>> >>> v3: >>> - Adjust comments >>> - Add Reviewed-bys >>> >>> v2: >>> - use folio_test_anon() (Huang, Ying) >>> >>> mm/migrate_device.c | 22 ++++++++++++++++------ >>> 1 file changed, 16 insertions(+), 6 deletions(-) >>> >>> diff --git a/mm/migrate_device.c b/mm/migrate_device.c >>> index d30c9de60b0d..f76ebccfe067 100644 >>> --- a/mm/migrate_device.c >>> +++ b/mm/migrate_device.c >>> @@ -747,13 +747,23 @@ static void __migrate_device_pages(unsigned >>> long *src_pfns, >>> if (is_device_private_page(newpage) || >>> is_device_coherent_page(newpage)) { >>> - /* >>> - * For now only support anonymous memory migrating to >>> - * device private or coherent memory. >>> - */ >>> + >>> if (mapping) { >>> - src_pfns[i] &= ~MIGRATE_PFN_MIGRATE; >>> - continue; >>> + struct folio *folio; >>> + >>> + folio = page_folio(page); >>> + >>> + /* >>> + * For now only support anonymous memory migrating to >>> + * device private or coherent memory. >>> + * >>> + * Try to get rid of swap cache if possible. >>> + * >>> + */ >>> + if (!folio_test_anon(folio) || >>> !folio_free_swap(folio)) { >>> + src_pfns[i] &= ~MIGRATE_PFN_MIGRATE; >>> + continue; >> >> I'm pretty sure the folio has to be locked in order to call >> folio_free_swap(). >> > > Oh, staring at the bigger context, I assume we locked the folios via > migrate_device_range(), correct? > Yes either that, or when migrating via virtual addresses migrate_vma_collect_pmd() has trylock_page() and we migrate only pages which succeed locking. --Mika
On Tue, Jun 06, 2023 at 08:01:49AM +0300, mpenttil@redhat.com wrote: > From: Mika Penttilä <mpenttil@redhat.com> > > Migrating file pages and swapcache pages into device memory is not supported. > The decision is done based on page_mapping(). For now, swapcache pages are not migrated. Please fix the commit log formatting, it should not exceed 7 lines. > if (is_device_private_page(newpage) || > is_device_coherent_page(newpage)) { > - /* > - * For now only support anonymous memory migrating to > - * device private or coherent memory. > - */ > + > if (mapping) { Very nitpicky, but this empty line looks odd. Also isn't the comment still (mostly) correct given that file backed memory is still not supported? > + /* > + * For now only support anonymous memory migrating to > + * device private or coherent memory. > + * > + * Try to get rid of swap cache if possible. > + * > + */ > + if (!folio_test_anon(folio) || !folio_free_swap(folio)) { Please avoid the overly long lines.
Hi, On 7.6.2023 17.10, Christoph Hellwig wrote: > On Tue, Jun 06, 2023 at 08:01:49AM +0300, mpenttil@redhat.com wrote: >> From: Mika Penttilä <mpenttil@redhat.com> >> >> Migrating file pages and swapcache pages into device memory is not supported. >> The decision is done based on page_mapping(). For now, swapcache pages are not migrated. > > Please fix the commit log formatting, it should not exceed 7 lines. > >> if (is_device_private_page(newpage) || >> is_device_coherent_page(newpage)) { >> - /* >> - * For now only support anonymous memory migrating to >> - * device private or coherent memory. >> - */ >> + >> if (mapping) { > > Very nitpicky, but this empty line looks odd. Also isn't the comment > still (mostly) correct given that file backed memory is still not > supported? Yes the comment is mostly correct and moved a few lines lower, complemented with a comment about the swap cache. > >> + /* >> + * For now only support anonymous memory migrating to >> + * device private or coherent memory. >> + * >> + * Try to get rid of swap cache if possible. >> + * >> + */ >> + if (!folio_test_anon(folio) || !folio_free_swap(folio)) { > > Please avoid the overly long lines. > Thanks, Mika
On 7.6.2023 17.10, Christoph Hellwig wrote: > On Tue, Jun 06, 2023 at 08:01:49AM +0300, mpenttil@redhat.com wrote: >> From: Mika Penttilä <mpenttil@redhat.com> >> >> Migrating file pages and swapcache pages into device memory is not supported. >> The decision is done based on page_mapping(). For now, swapcache pages are not migrated. > > Please fix the commit log formatting, it should not exceed 7 lines. Not sure what you mean should not exceed 7 lines..?
On Wed, Jun 07, 2023 at 07:06:06PM +0300, Mika Penttilä wrote: > > > On 7.6.2023 17.10, Christoph Hellwig wrote: > > On Tue, Jun 06, 2023 at 08:01:49AM +0300, mpenttil@redhat.com wrote: > > > From: Mika Penttilä <mpenttil@redhat.com> > > > > > > Migrating file pages and swapcache pages into device memory is not supported. > > > The decision is done based on page_mapping(). For now, swapcache pages are not migrated. > > > > Please fix the commit log formatting, it should not exceed 7 lines. > > Not sure what you mean should not exceed 7 lines..? Sorry, this should be 73.
diff --git a/mm/migrate_device.c b/mm/migrate_device.c index d30c9de60b0d..f76ebccfe067 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -747,13 +747,23 @@ static void __migrate_device_pages(unsigned long *src_pfns, if (is_device_private_page(newpage) || is_device_coherent_page(newpage)) { - /* - * For now only support anonymous memory migrating to - * device private or coherent memory. - */ + if (mapping) { - src_pfns[i] &= ~MIGRATE_PFN_MIGRATE; - continue; + struct folio *folio; + + folio = page_folio(page); + + /* + * For now only support anonymous memory migrating to + * device private or coherent memory. + * + * Try to get rid of swap cache if possible. + * + */ + if (!folio_test_anon(folio) || !folio_free_swap(folio)) { + src_pfns[i] &= ~MIGRATE_PFN_MIGRATE; + continue; + } } } else if (is_zone_device_page(newpage)) { /*