From patchwork Sat Aug 7 03:25:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12424097 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D437C4338F for ; Sat, 7 Aug 2021 03:25:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D187760F01 for ; Sat, 7 Aug 2021 03:25:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D187760F01 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id D1D976B006C; Fri, 6 Aug 2021 23:25:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CCDD36B0071; Fri, 6 Aug 2021 23:25:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B94AB6B0073; Fri, 6 Aug 2021 23:25:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0073.hostedemail.com [216.40.44.73]) by kanga.kvack.org (Postfix) with ESMTP id 9A1416B006C for ; Fri, 6 Aug 2021 23:25:28 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 4C45C18043080 for ; Sat, 7 Aug 2021 03:25:28 +0000 (UTC) X-FDA: 78446844336.01.BC4D6FB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id C57298020868 for ; Sat, 7 Aug 2021 03:25:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628306727; 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: in-reply-to:in-reply-to:references:references; bh=M89IpDmqpLb2E2sKYTfviaRjvA8qgBHjWuv99Q1xOu4=; b=Vyk3S7QeXj071n18qAuSnV+1RYiay25kRAzJjqDbeb+h08mf6rasViWowsj/EtvpIiLKaz 0RqKIXDmQnlh8s5KvuQgIMD9ZYXwqYiSAYnyGOXy/f0EZC5uWB8oa7IEOz695wEz1qnW1v rNNDRkYT7DxfLz5Wc+7sGq22R3rKYHI= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-354-c15-zlUsO_GKe0G0mJXnIw-1; Fri, 06 Aug 2021 23:25:26 -0400 X-MC-Unique: c15-zlUsO_GKe0G0mJXnIw-1 Received: by mail-qv1-f70.google.com with SMTP id g2-20020a0cdf020000b029033bc8be6d4aso1192928qvl.9 for ; Fri, 06 Aug 2021 20:25:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M89IpDmqpLb2E2sKYTfviaRjvA8qgBHjWuv99Q1xOu4=; b=RNAtdQIIM3OgcBf13UrjvcnRqtKDF5ZmqjIhSZMzPBz0Z0UxUnKaXru5z5date5z6/ 56o+Vo84SdTqIGCikc5V7XhnQJNXeWJKHILa1shRAOakAxMcmhx0N9fxA7JMjyzZ+bVm BtaY5mxnnHEA5urwgrf6OkYZWvl9/VVAt2pogTFHGdyhX+KpENfhkO7BURGVNgNUbb3n HP4thgZL6wCWG9uCRg7/SYPpPlVORPyMcDj0WPaLV7+S0dKqCVlLXvAutST3Z0qvkYfP tYxCawyM7TTE22l5w7Z3jpEV/Xz46XXd+hmOwp4ZmvFL5Rj+Fzega3q7aFfIYvL15scL RpTA== X-Gm-Message-State: AOAM533pDveZM2jk9VuScLETHC4MhvnilO58MKtLjSojd/RdgEF4c/CU LcrTsMoEulxq/7u+xPez7xpOrz/UFnwerCL1QlYtQVBi46NFtpQ2jwrJsKmBeXD5hi7yYgl7oZh kgtOK3JuwVhk= X-Received: by 2002:a05:620a:20d3:: with SMTP id f19mr13477922qka.304.1628306725766; Fri, 06 Aug 2021 20:25:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwudqdogHpREEXwWEO5+43wkxQbUYyM7tOd7/XM0TXNcdPIMwjzcLULEbq1V0TujbxiOXrmmw== X-Received: by 2002:a05:620a:20d3:: with SMTP id f19mr13477901qka.304.1628306725555; Fri, 06 Aug 2021 20:25:25 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-92-76-70-75-133.dsl.bell.ca. [76.70.75.133]) by smtp.gmail.com with ESMTPSA id a5sm5514875qkk.92.2021.08.06.20.25.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Aug 2021 20:25:25 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Alistair Popple , Tiberiu Georgescu , ivan.teterevkov@nutanix.com, Mike Rapoport , Hugh Dickins , peterx@redhat.com, Matthew Wilcox , Andrea Arcangeli , David Hildenbrand , "Kirill A . Shutemov" , Andrew Morton , Mike Kravetz Subject: [PATCH RFC 1/4] mm: Introduce PTE_MARKER swap entry Date: Fri, 6 Aug 2021 23:25:18 -0400 Message-Id: <20210807032521.7591-2-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807032521.7591-1-peterx@redhat.com> References: <20210807032521.7591-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Vyk3S7Qe; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf06.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com X-Stat-Signature: 51zxy1553echrur116ssuz9a5ii4nrbh X-Rspamd-Queue-Id: C57298020868 X-Rspamd-Server: rspam01 X-HE-Tag: 1628306727-289993 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: This patch introduces a new swap entry type called PTE_MARKER. It can be installed for any pte that maps a file-backed memory when the pte is temporarily zapped, so as to maintain per-pte information. The information that kept in the pte is called a "marker". Here we define the marker as "unsigned long" just to match pgoff_t, however it will only work if it still fits in swp_offset(), which is e.g. currently 58 bits on x86_64. The first marker bit that is introduced together with the new swap pte is the PAGEOUT marker. When that bit is set, it means this pte used to point to a page which got swapped out. It's mostly a definition so the swap type is not totally nothing, however the functions are not implemented yet to handle the new swap type. A new config CONFIG_PTE_MARKER is introduced too; it's by default off. Signed-off-by: Peter Xu --- include/linux/swap.h | 14 ++++++++++++- include/linux/swapops.h | 45 +++++++++++++++++++++++++++++++++++++++++ mm/Kconfig | 17 ++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 6f5a43251593..545dc8e0b0fb 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -55,6 +55,18 @@ static inline int current_is_kswapd(void) * actions on faults. */ +/* + * PTE markers are used to persist information onto PTEs that are mapped with + * file-backed memories. + */ +#ifdef CONFIG_PTE_MARKER +#define SWP_PTE_MARKER_NUM 1 +#define SWP_PTE_MARKER (MAX_SWAPFILES + SWP_HWPOISON_NUM + \ + SWP_MIGRATION_NUM + SWP_DEVICE_NUM) +#else +#define SWP_PTE_MARKER_NUM 0 +#endif + /* * Unaddressable device memory support. See include/linux/hmm.h and * Documentation/vm/hmm.rst. Short description is we need struct pages for @@ -100,7 +112,7 @@ static inline int current_is_kswapd(void) #define MAX_SWAPFILES \ ((1 << MAX_SWAPFILES_SHIFT) - SWP_DEVICE_NUM - \ - SWP_MIGRATION_NUM - SWP_HWPOISON_NUM) + SWP_MIGRATION_NUM - SWP_HWPOISON_NUM - SWP_PTE_MARKER_NUM) /* * Magic header for a swap area. The first part of the union is diff --git a/include/linux/swapops.h b/include/linux/swapops.h index d356ab4047f7..3fec83449e1e 100644 --- a/include/linux/swapops.h +++ b/include/linux/swapops.h @@ -247,6 +247,51 @@ static inline int is_writable_migration_entry(swp_entry_t entry) #endif +#ifdef CONFIG_PTE_MARKER + +#ifdef CONFIG_PTE_MARKER_PAGEOUT +/* When this bit is set, it means this page is swapped out previously */ +#define PTE_MARKER_PAGEOUT (1UL << 0) +#else +#define PTE_MARKER_PAGEOUT 0 +#endif + +#define PTE_MARKER_MASK (PTE_MARKER_PAGEOUT) + +static inline swp_entry_t make_pte_marker_entry(unsigned long marker) +{ + return swp_entry(SWP_PTE_MARKER, marker); +} + +static inline bool is_pte_marker_entry(swp_entry_t entry) +{ + return swp_type(entry) == SWP_PTE_MARKER; +} + +static inline unsigned long pte_marker_get(swp_entry_t entry) +{ + return swp_offset(entry) & PTE_MARKER_MASK; +} + +#else /* CONFIG_PTE_MARKER */ + +static inline swp_entry_t make_pte_marker_entry(unsigned long marker) +{ + return swp_entry(0, 0); +} + +static inline bool is_pte_marker_entry(swp_entry_t entry) +{ + return false; +} + +static inline unsigned long pte_marker_get(swp_entry_t entry) +{ + return 0; +} + +#endif /* CONFIG_PTE_MARKER */ + static inline struct page *pfn_swap_entry_to_page(swp_entry_t entry) { struct page *p = pfn_to_page(swp_offset(entry)); diff --git a/mm/Kconfig b/mm/Kconfig index 40a9bfcd5062..6043d8f1c066 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -889,4 +889,21 @@ config IO_MAPPING config SECRETMEM def_bool ARCH_HAS_SET_DIRECT_MAP && !EMBEDDED +config PTE_MARKER + def_bool n + bool "Marker PTEs support" + + help + Allows to create marker PTEs for file-backed memory. + +config PTE_MARKER_PAGEOUT + def_bool n + depends on PTE_MARKER + bool "Shmem pagemap PM_SWAP support" + + help + Allows to create marker PTEs for file-backed memory when the page is + swapped out. It's required for pagemap to work correctly with shmem + on page swapping. + endmenu