From patchwork Sun May 7 06:17:26 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: 13233696 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 B458EC77B7C for ; Sun, 7 May 2023 06:18:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9CC486B0075; Sun, 7 May 2023 02:18:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 955706B0078; Sun, 7 May 2023 02:18:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7CE156B007B; Sun, 7 May 2023 02:18:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 69BE56B0075 for ; Sun, 7 May 2023 02:18:04 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 308BE40879 for ; Sun, 7 May 2023 06:18:04 +0000 (UTC) X-FDA: 80762453688.17.3F0127B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 52C1140002 for ; Sun, 7 May 2023 06:18:01 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eEXfy4EH; spf=pass (imf27.hostedemail.com: domain of mpenttil@redhat.com designates 170.10.129.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=1683440282; 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=/hRxrUUzRLvf8AVUqcmw5+jNN6/ijgKdT9lm3aojzhc=; b=YkUvcDC8HSVXid1v6SPfw9MWjL2o4mT61XtYOz2nwX1ewNW2bGuO5Z8ASNcdkdjQaUBBaU EU8YfJkg8LTFJEiXYOXxFuXX/hX8DeX29aH7WdsybE/1BcQr2fqmjueZy35KwCCWi8UYPa m1021NA56XQJaXYcr6MxAGHRFce3u40= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1683440282; a=rsa-sha256; cv=none; b=pWFSLqUdZykjZroV0OjSln8J0vnWCUh+7ZIOFgJN9Urqz+85dgL8wkDug3WproDZ8SVNIc 73844XVb2At/vxIC2kC+ElB0vzrvVFpjaKIn1Q0FyTkBjS0VpFdvuoagWf61PTpoRB6pk4 N4HSvi1S2pm7j/Cn7geS8KyDY5Exj9k= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eEXfy4EH; spf=pass (imf27.hostedemail.com: domain of mpenttil@redhat.com designates 170.10.129.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=1683440280; 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=/hRxrUUzRLvf8AVUqcmw5+jNN6/ijgKdT9lm3aojzhc=; b=eEXfy4EHAwhoq8yag72zdyDpm8K7qdnwhgJtA7C4fs3Qo8W1ucSfqgdAru+Zf9/Vggd3S1 6GB01LULhRGkRE1ElDrxQqevTv9vU3qRYwzQORNJMfLPKSkzHoQLRIlwGWxKlfZ/cvFfSd Zl46mTO//fzC0In5wrAstk0KkGoorBM= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-313-LuDs4yNpON-3ZR2dvkB_qQ-1; Sun, 07 May 2023 02:17:57 -0400 X-MC-Unique: LuDs4yNpON-3ZR2dvkB_qQ-1 Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-4edc7406cb5so1917891e87.3 for ; Sat, 06 May 2023 23:17:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683440275; x=1686032275; 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=/hRxrUUzRLvf8AVUqcmw5+jNN6/ijgKdT9lm3aojzhc=; b=IDeToRboAaOwAMMOviZ1WM0PqGJkzY5NfvCmTnnSFbSxCWw+IhjrBpA+XA8GZAK/EB LexzOAVaQ/QM6DMGh+5D5f7O3lxgMqgdWEa5q6AxVWLKxUOvfVzRQn7RcTaxx5AB1ynh lLoGeqAIwW/pPEPjnqmldptwiFp4vXTdSTncl31ecQDMNbRo9j4qZLqq36/97VoUpRgE rYdwdVx0LkPIbeGqDSrbGhFcLVALvmJG+MAW/lPF5DntAiDkHdEr2K5nM1D7M6QjRApf GMw5ZiyFvFNGCpHRMVo32fSLXzOnvYPgPV2pooloEK/YSri+7sMsejnA3RwBXC1i8KYW E5AA== X-Gm-Message-State: AC+VfDwHRL+kQ6Jqc13CJacRrr4Li31bRKbvhpWLmejEPMzqifzub8Wh X3YR7rgJCjVwvN5mM0NjSFtedD+ZPuOYFR9HMXuvYHB/dIsnIbhltAXSql2jlxCTx7dvVxjL2sd GczcIztLz6Q== X-Received: by 2002:ac2:44b8:0:b0:4ec:8a0e:64c8 with SMTP id c24-20020ac244b8000000b004ec8a0e64c8mr1753302lfm.11.1683440275619; Sat, 06 May 2023 23:17:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4962BgfRvaN1caA4kasC+PeBOW6jCTiIzFz5nVVdlPlB2W3RzrkFV/Xpy0TnZ9b8WLLocOhA== X-Received: by 2002:ac2:44b8:0:b0:4ec:8a0e:64c8 with SMTP id c24-20020ac244b8000000b004ec8a0e64c8mr1753298lfm.11.1683440275338; Sat, 06 May 2023 23:17:55 -0700 (PDT) Received: from mjp-Z390-AORUS-MASTER.redhat.com (85-23-48-202.bb.dnainternet.fi. [85.23.48.202]) by smtp.gmail.com with ESMTPSA id p2-20020a19f002000000b004eb07f5cde6sm870753lfc.297.2023.05.06.23.17.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 May 2023 23:17:54 -0700 (PDT) From: mpenttil@redhat.com To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: apopple@nvidia.com, jhubbard@nvidia.com, rcampbell@nvidia.com, =?utf-8?q?Mika_Penttil=C3=A4?= Subject: [PATCH] mm/migrate_device: Try to handle swapcache pages. Date: Sun, 7 May 2023 09:17:26 +0300 Message-Id: <20230507061726.13422-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-Server: rspam02 X-Rspamd-Queue-Id: 52C1140002 X-Stat-Signature: f97iueok8ndc3umz94jqwdey1kotj4sw X-Rspam-User: X-HE-Tag: 1683440281-535415 X-HE-Meta: U2FsdGVkX1/9SlNo/BXLgaO//7PhElNzzc+rURi2AHlfpcCNkFw6snCnT2GVXMNsMg5mLKGv7g2Q8ZO2a2dIPS5dXVXd4pVaLptzqpeZQJ95H6xBbWexjnTqdJ0fv/vKeqdW5HACN385V4flAqUELmU3yZzCXOz5NkZUyWqL37yLs0XLCXqeKGtzD/n/ukPUastUV4oe2eenjsamnKey2S1TyC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mzyWjga3ZAxvGuBCrw+dvRFzvqrGZSST3xlrfScJouWxWFb0ZthfQM+WwxxwNZ5jgWtHfBLXK69Efro1d7piWHxcirCK/YQADFQle8Dd6USRRVB0/YkMyVVPBlk8Yzl9+7V9S6rKu1VZtiGP5YydFhNV58= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000197, 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. 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. As a detail, do not mess with shmem pages, as they handle swap internally. Cc: Alistair Popple Cc: John Hubbard Cc: Ralph Campbell Signed-off-by: Mika Penttilä --- mm/migrate_device.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mm/migrate_device.c b/mm/migrate_device.c index d30c9de60b0d..e8169c58c341 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -750,10 +751,17 @@ static void __migrate_device_pages(unsigned long *src_pfns, /* * For now only support anonymous memory migrating to * device private or coherent memory. + * + * Try to get rid of swap cache if possible. + * Leave shmem pages alone, they handle swap internally + * */ if (mapping) { - src_pfns[i] &= ~MIGRATE_PFN_MIGRATE; - continue; + if (shmem_mapping(mapping) || + !folio_free_swap(page_folio(page))) { + src_pfns[i] &= ~MIGRATE_PFN_MIGRATE; + continue; + } } } else if (is_zone_device_page(newpage)) { /*