From patchwork Wed Jun 7 17:29:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Mika_Penttil=C3=A4?= X-Patchwork-Id: 13271040 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 833DBC7EE23 for ; Wed, 7 Jun 2023 17:30:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 004F68E0003; Wed, 7 Jun 2023 13:30:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF7878E0001; Wed, 7 Jun 2023 13:30:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC0278E0003; Wed, 7 Jun 2023 13:30:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C95C38E0001 for ; Wed, 7 Jun 2023 13:30:27 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 73589160466 for ; Wed, 7 Jun 2023 17:30:27 +0000 (UTC) X-FDA: 80876640894.15.C29BD2F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 6B2AA40015 for ; Wed, 7 Jun 2023 17:30:25 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LuzGSP3S; spf=pass (imf07.hostedemail.com: domain of mpenttil@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mpenttil@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=1686159025; 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: references:dkim-signature; bh=wYhf2D6abemq4eB8JjKJoDoUTpBsFesDL05ay5uU6iQ=; b=AWGgxz82y9fRHDFI1wpLzcY8+Ru6EZLp2TNvgj78p134+CHkDThjmRPRwhZZwz5kuPJsrv nG/93cVE55qrEsnSU2A+L0iTDxHsoI1jlVyLusxpE/D7YiIcDlnhWLI4YwrwflAPqW2vLf G3ICwndYk4lRYiaJOdR06BLm00SWzX4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686159025; a=rsa-sha256; cv=none; b=4cyhTCfd5JpeqtBCE9IJ1Ro5NV21eF28BqmOlbUXyiA3D2os5yBBewv92RjU+vez2Y/crX HVX2twwyabF0+WynTGu/ciNOiGn5TYClN/Vh0Sz4wjQOaf3XBXA/qeeBVExD8Ne8LHN4rN UznHNdVl9H8fWyKsFKuCvi274N01Udg= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LuzGSP3S; spf=pass (imf07.hostedemail.com: domain of mpenttil@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mpenttil@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686159024; 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=wYhf2D6abemq4eB8JjKJoDoUTpBsFesDL05ay5uU6iQ=; b=LuzGSP3S+EM+7MwRYAWik0l/fw/EWMAJYU71n0FHYU2FCbOSMfAjtAYSnbSKg1MWzG1HNH kejCwoj+HNI/8W2xy5SnjSXUH202InvqnpDhBLAnHBkZkCO9iRZGGtZvl0jrpmy/c6vJqo SQ5WyiBIlFKr8EkG4KOc2eOzPClyiqo= Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-444--mt42iE6MiOLO0m_g3h38Q-1; Wed, 07 Jun 2023 13:30:23 -0400 X-MC-Unique: -mt42iE6MiOLO0m_g3h38Q-1 Received: by mail-lj1-f199.google.com with SMTP id 38308e7fff4ca-2b1abf3c513so35623231fa.0 for ; Wed, 07 Jun 2023 10:30:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686159021; x=1688751021; 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=wYhf2D6abemq4eB8JjKJoDoUTpBsFesDL05ay5uU6iQ=; b=DYXg7HNKnI3JEmzefIWomdySnw2r/uD0+8PsKzRTiuQ6DVS5nz6j86wgAo8VC7yH+j zlHduvxa3JpS7vXEWPKW3lj1CF0OlsqaC8OVpeud03iIxEe/fNb1F/OcbThS6j1HFZhk PUGUDSipUFrycH43LhhvtGYS1oBgUDENVhYA3BV4M3GSj9XQ0EatNWgHWJwj95qG+xmU WAqe2SLFXAF8WlMt3SYwj/GCXZf0LGfZ9538LOzNgQs77kWCPCz4uwKVeAkc3Ho+Z0Ur 0KBMP5H7uZ7XDpRrQ3+v1Glvlj49w5Zhb/0PCxXJfeDKmH0aG6ADLVVeBy1xtPl5owxq E3Eg== X-Gm-Message-State: AC+VfDyDKbXRjhrZN0jh4t49M/wvoH1xqFi8qbjUwUglvBG0EttdTyQK KEisVEr1jaO2gULPRuzxkdjZr8jIjB+PUtqa9SYT8/UQB7i36UdSBJJjHVz0lsF4QUhxYWLWAhK KA+L9Vq+vwA== X-Received: by 2002:a05:651c:113:b0:2b1:eab1:e083 with SMTP id a19-20020a05651c011300b002b1eab1e083mr2654404ljb.16.1686159021681; Wed, 07 Jun 2023 10:30:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5gYxsb+2CrIRddoITGZU6B2w46sQx8Ey+CtOc1kASJGB8EPHrFtDTw/Kp2btYnR6nNeu5KmA== X-Received: by 2002:a05:651c:113:b0:2b1:eab1:e083 with SMTP id a19-20020a05651c011300b002b1eab1e083mr2654397ljb.16.1686159021367; Wed, 07 Jun 2023 10:30:21 -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 e24-20020a2e8198000000b00295a96a0f6csm2262191ljg.102.2023.06.07.10.30.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 10:30:20 -0700 (PDT) From: mpenttil@redhat.com To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: =?utf-8?q?Mika_Penttil=C3=A4?= , Alistair Popple , John Hubbard , Ralph Campbell , "Huang, Ying" Subject: [PATCH v4] mm/migrate_device: Try to handle swapcache pages Date: Wed, 7 Jun 2023 20:29:44 +0300 Message-Id: <20230607172944.11713-1-mpenttil@redhat.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 6B2AA40015 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: ejqt4a11kww4bgqionsdno7ccjhgaamy X-HE-Tag: 1686159025-929372 X-HE-Meta: U2FsdGVkX1/Un+PrgVPxuCV30RTS1VBg7eop8eAivM2na0sFZrrQW5F77PRWfUdiaIJ2rc5C5dX3sU87MctvgTUGJ7+ndwksOHga7t+g0bIsEJ9NfDNzIdTbXA3WCwkaB+zuglmCcxTkrAzfcVNHo83sc/L9A0ECT+mjBnDw919rc8vQ1OFnrAvYXuBCkSmY2PVnVsNY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KG/evL7RpWeOMu60DF9QyRT8sefnCVUTDnIDtR7FwLHWUCjzi1mBZpr2Knjx/NVCE4DIbud2jvC7melJSJzipd3SGhzRlFOnAlzbjVP17NQatA3qMNNKm4UfImiZ6Etw4nM5y10JFqz46Y+JARanwDamnWiEzR2rRZ4B0hO5Zk9te9y4SsIVUamiLbyy7J 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: From: Mika Penttilä Migrating file pages and swapcache pages into device memory is not supported. Try to get rid of the swap cache, and if successful, go ahead as with other anonymous pages. Cc: Alistair Popple Cc: John Hubbard Cc: Ralph Campbell Cc: "Huang, Ying" Reviewed-by: "Huang, Ying" Reviewed-by: Alistair Popple Signed-off-by: Mika Penttilä --- v4: - fix commit log message - delete empty line v3: - adjust comments - add Reviewed-bys v2: - use folio_test_anon() (Huang, Ying) mm/migrate_device.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/mm/migrate_device.c b/mm/migrate_device.c index d30c9de60b0d..56411b063231 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -747,13 +747,22 @@ 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)) { /*