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: 104647 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp377376vqr; Wed, 7 Jun 2023 10:50:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ725H3K+pB0ib24gOsjj+KR0wz6CUTYdmHwjWq8wM5rX8ppP0eVgq4IQfBaSWLKag3USxxk X-Received: by 2002:a17:902:e884:b0:1a1:dd2a:fe6c with SMTP id w4-20020a170902e88400b001a1dd2afe6cmr4802485plg.53.1686160215623; Wed, 07 Jun 2023 10:50:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686160215; cv=none; d=google.com; s=arc-20160816; b=i3qNaxemgBgj4nqze1VclO52mmPAwMxAFLBiMIK5cQNkJuyFiJ8bNusJnPPUU72oGE 5e2FPtTP+6LIEb5GztWEFXLUk4dZfgHD1ma/IDpTP8w98PuYAChERCJeqmMv8p7a50Ab 8RFJHglW4H32wXKFZoos4+n8IRrsLIdDJ9vuE3ZtQ/AyD191323gxF8kstAKc6i8gGfX ruwKpXaLM1RC9Suf/OeP6j4LJYPIJ9l+ri6G17CMKPNAJdIHFvVnMA1CloPPOfZiIWuI toN1ntD5fKQiMBpVQzMTIjLEfnj4xj8mEb66MNEboaUg4FVGfswtih+3rWDHSghSE2eB Hfow== 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=wYhf2D6abemq4eB8JjKJoDoUTpBsFesDL05ay5uU6iQ=; b=xvppFw06jJZecU2SoHCbaB4tZ30rPVCQdeM16MnkPWXjuXDoY/DZEevvKw7neNSh31 V0qqPjOt2JNItvDZWDk8JnaJwtssiarketwWs0L04huRdiU/AvwQ1uBJlO2xamUtuwUL 1kvqvGghq39hoJG8BaPC69QaYs+SmCJ3XjImpoATfoArY0ifJs9eJh3WX6qGwUzwNdL1 nSg3UbEzx+C6vE9MJu5pr0Q9PBH9e8YxqUi97E5oulyRQP8y96qipq/ZieNETvbd4y1q adKFSGX/+NFb0fMjm/g3OUA2N+nct9E+mudWnEcDRTwKayCS265saNEy9ZJqWRj6bQgD 2EbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=L+qpu7YF; 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 y12-20020a170903010c00b001b024ab08fbsi8975061plc.59.2023.06.07.10.49.59; Wed, 07 Jun 2023 10:50:15 -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=L+qpu7YF; 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 S231935AbjFGRbZ (ORCPT + 99 others); Wed, 7 Jun 2023 13:31:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232019AbjFGRbP (ORCPT ); Wed, 7 Jun 2023 13:31:15 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6329210B for ; Wed, 7 Jun 2023 10:30:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686159025; 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=L+qpu7YFJ1c38ly1/qYuKMIPql1E5Q7arMKZywO9vX5IaZatRfKjY16TiJcfMRuWbEw++c YbPd58VB3mge+l8diXIICnZnR3W7jE3Gek6KEsvQKYrG62AIroPIZFElOzqPxwzutdHXkz wfvveIUuqWLG3ZXD/9jWz4iwEshtGxw= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-647-y84JakWEMG-VbkWJCdQJDA-1; Wed, 07 Jun 2023 13:30:23 -0400 X-MC-Unique: y84JakWEMG-VbkWJCdQJDA-1 Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-2b1e6258204so20863921fa.3 for ; Wed, 07 Jun 2023 10:30:23 -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=aecUOQV7vu8XME071aqj5rskvDI3f8BMbdUlTfJC3fN6/9dGJ2xDe2c6Cd2m400qM+ 15AQI2q4JcXI9LKzIgmKxLhpHtIZ4SkPPR/hkfDtJuZjmKk1fzcz+Pb3foD3urEREVKV WyHUi90cJlKYzysUt4HJn11AxsosEyTQDCn/xpzdINJHAdyZiKne1wJr4gUihxPc8qz5 OhcvaJyPtb2F4VS30Bw2PVl5Kp7MX2218KXJ916frPXxseTMTV3sF6K+khlPMMWmQ71m TZ4aT4NLjGLVx5ch/Pyef/owKVwuSKhO3uLJHYaQgXy8rDNj9i8phPZ8SPJ3S61kSZNE oWHw== X-Gm-Message-State: AC+VfDyF1LViUc8ztV7T96DHlmqt0nf9t2MqLDF1x1kt9DnKle/bVmRB qYAW5vT+YNAWgZq/Z4Qgl7EnrMQNmkhHT/aa0D2NorCVVjPzY0+RR9M9kruI7GoNgBm75sA9jT9 U1mbIYYnswrjjL4MlmsXIMj+9MPxOCF2ovYBcg7TMq+CRXrwgzv2T+5tCQzbSkm41t9WjSLfx1D KOoR/bRI4= X-Received: by 2002:a05:651c:113:b0:2b1:eab1:e083 with SMTP id a19-20020a05651c011300b002b1eab1e083mr2654408ljb.16.1686159021726; Wed, 07 Jun 2023 10:30:21 -0700 (PDT) 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-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: 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?1768067134490749860?= 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)) { /*