Skip to content

Commit 97e9c3e

Browse files
committed
mm: always compile in pte markers
jira LE-4335 commit-author Peter Xu <peterx@redhat.com> commit ca92ea3 Patch series "mm: Use pte marker for swapin errors". This series uses the pte marker to replace the swapin error swap entry, then we save one more swap entry slot for swap devices. A new pte marker bit is defined. This patch (of 2): The PTE markers code is tiny and now it's enabled for most of the distributions. It's fine to keep it as-is, but to make a broader use of it (e.g. replacing read error swap entry) it needs to be there always otherwise we need special code path to take care of !PTE_MARKER case. It'll be easier just make pte marker always exist. Use this chance to extend its usage to anonymous too by simply touching up some of the old comments, because it'll be used for anonymous pages in the follow up patches. Link: https://lkml.kernel.org/r/20221030214151.402274-1-peterx@redhat.com Link: https://lkml.kernel.org/r/20221030214151.402274-2-peterx@redhat.com Signed-off-by: Peter Xu <peterx@redhat.com> Reviewed-by: Huang Ying <ying.huang@intel.com> Reviewed-by: Miaohe Lin <linmiaohe@huawei.com> Acked-by: David Hildenbrand <david@redhat.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Naoya Horiguchi <naoya.horiguchi@nec.com> Cc: Peter Xu <peterx@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit ca92ea3) Signed-off-by: Brett Mastbergen <bmastbergen@ciq.com>
1 parent 18afd09 commit 97e9c3e

File tree

4 files changed

+6
-49
lines changed

4 files changed

+6
-49
lines changed

include/linux/swap.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,13 @@ static inline int current_is_kswapd(void)
5656
*/
5757

5858
/*
59-
* PTE markers are used to persist information onto PTEs that are mapped with
60-
* file-backed memories. As its name "PTE" hints, it should only be applied to
61-
* the leaves of pgtables.
59+
* PTE markers are used to persist information onto PTEs that otherwise
60+
* should be a none pte. As its name "PTE" hints, it should only be
61+
* applied to the leaves of pgtables.
6262
*/
63-
#ifdef CONFIG_PTE_MARKER
6463
#define SWP_PTE_MARKER_NUM 1
6564
#define SWP_PTE_MARKER (MAX_SWAPFILES + SWP_HWPOISON_NUM + \
6665
SWP_MIGRATION_NUM + SWP_DEVICE_NUM)
67-
#else
68-
#define SWP_PTE_MARKER_NUM 0
69-
#endif
7066

7167
/*
7268
* Unaddressable device memory support. See include/linux/hmm.h and

include/linux/swapops.h

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,6 @@ typedef unsigned long pte_marker;
396396
#define PTE_MARKER_SWAPIN_ERROR BIT(1)
397397
#define PTE_MARKER_MASK (BIT(2) - 1)
398398

399-
#ifdef CONFIG_PTE_MARKER
400-
401399
static inline swp_entry_t make_pte_marker_entry(pte_marker marker)
402400
{
403401
return swp_entry(SWP_PTE_MARKER, marker);
@@ -418,32 +416,6 @@ static inline bool is_pte_marker(pte_t pte)
418416
return is_swap_pte(pte) && is_pte_marker_entry(pte_to_swp_entry(pte));
419417
}
420418

421-
#else /* CONFIG_PTE_MARKER */
422-
423-
static inline swp_entry_t make_pte_marker_entry(pte_marker marker)
424-
{
425-
/* This should never be called if !CONFIG_PTE_MARKER */
426-
WARN_ON_ONCE(1);
427-
return swp_entry(0, 0);
428-
}
429-
430-
static inline bool is_pte_marker_entry(swp_entry_t entry)
431-
{
432-
return false;
433-
}
434-
435-
static inline pte_marker pte_marker_get(swp_entry_t entry)
436-
{
437-
return 0;
438-
}
439-
440-
static inline bool is_pte_marker(pte_t pte)
441-
{
442-
return false;
443-
}
444-
445-
#endif /* CONFIG_PTE_MARKER */
446-
447419
static inline pte_t make_pte_marker(pte_marker marker)
448420
{
449421
return swp_entry_to_pte(make_pte_marker_entry(marker));
@@ -472,9 +444,6 @@ static inline int is_swapin_error_entry(swp_entry_t entry)
472444
* memory, kernel-only memory (including when the system is during-boot),
473445
* non-ram based generic file-system. It's fine to be used even there, but the
474446
* extra pte marker check will be pure overhead.
475-
*
476-
* For systems configured with !CONFIG_PTE_MARKER this will be automatically
477-
* optimized to pte_none().
478447
*/
479448
static inline int pte_none_mostly(pte_t pte)
480449
{

mm/Kconfig

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,17 +1123,10 @@ config HAVE_ARCH_USERFAULTFD_MINOR
11231123
help
11241124
Arch has userfaultfd minor fault support
11251125

1126-
config PTE_MARKER
1127-
bool
1128-
1129-
help
1130-
Allows to create marker PTEs for file-backed memory.
1131-
11321126
config PTE_MARKER_UFFD_WP
11331127
bool "Userfaultfd write protection support for shmem/hugetlbfs"
11341128
default y
11351129
depends on HAVE_ARCH_USERFAULTFD_WP
1136-
select PTE_MARKER
11371130

11381131
help
11391132
Allows to create marker PTEs for userfaultfd write protection

mm/memory.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3704,11 +3704,10 @@ static vm_fault_t handle_pte_marker(struct vm_fault *vmf)
37043704
unsigned long marker = pte_marker_get(entry);
37053705

37063706
/*
3707-
* PTE markers should always be with file-backed memories, and the
3708-
* marker should never be empty. If anything weird happened, the best
3709-
* thing to do is to kill the process along with its mm.
3707+
* PTE markers should never be empty. If anything weird happened,
3708+
* the best thing to do is to kill the process along with its mm.
37103709
*/
3711-
if (WARN_ON_ONCE(vma_is_anonymous(vmf->vma) || !marker))
3710+
if (WARN_ON_ONCE(!marker))
37123711
return VM_FAULT_SIGBUS;
37133712

37143713
/* Higher priority than uffd-wp when data corrupted */

0 commit comments

Comments
 (0)