mm-rmap-convert-folio_add_file_rmap_range-into-folio_add_file_rmap_.patch removed from -mm tree
The quilt patch titled
Subject: mm/rmap: convert folio_add_file_rmap_range() into folio_add_file_rmap_[pte|ptes|pmd]()
has been removed from the -mm tree. Its filename was
mm-rmap-convert-folio_add_file_rmap_range-into-folio_add_file_rmap_.patch
This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: David Hildenbrand <[email protected]>
Subject: mm/rmap: convert folio_add_file_rmap_range() into folio_add_file_rmap_[pte|ptes|pmd]()
Date: Wed, 20 Dec 2023 23:44:31 +0100
Let's get rid of the compound parameter and instead define explicitly which mappings we're adding. That is more future proof, easier to read and harder to mess up.
Use an enum to express the granularity internally. Make the compiler always special-case on the granularity by using __always_inline. Replace the "compound" check by a switch-case that will be removed by the compiler completely.
Add plenty of sanity checks with CONFIG_DEBUG_VM. Replace the folio_test_pmd_mappable() check by a config check in the caller and sanity checks. Convert the single user of folio_add_file_rmap_range().
While at it, consistently use "int" instead of "unisgned int" in rmap code when dealing with mapcounts and the number of pages.
This function design can later easily be extended to PUDs and to batch PMDs. Note that for now we don't support anything bigger than PMD-sized folios (as we cleanly separated hugetlb handling). Sanity checks will catch if that ever changes.
Next up is removing page_remove_rmap() along with its "compound" parameter and smilarly converting all other rmap functions.
---
include/linux/rmap.h | 46 ++++++++++++++++++++++- mm/memory.c | 2 - mm/rmap.c | 79 +++++++++++++++++++++++++---------------- 3 files changed, 95 insertions(+), 32 deletions(-)
include/linux/rmap.h renamed from include/linux/rmap.h~mm-rmap-convert-folio_add_file_rmap_range-into-folio_add_file_rmap_ +44 -2
@@ -192,6 +192,44 @@ typedef int __bitwise rmap_t;#define RMAP_COMPOUND ((__force rmap_t)BIT(1))/* +* Internally, we're using an enum to specify the granularity. We make the +* compiler emit specialized code for each granularity. +*/ +enum rmap_level { +RMAP_LEVEL_PTE =0 , +RMAP_LEVEL_PMD , +}; + +static inline void __folio_rmap_sanity_checks (struct folio *folio, +struct page *page,int nr_pages,enum rmap_level level) +{ +/* hugetlb folios are handled separately. */ +VM_WARN_ON_FOLIO (folio_test_hugetlb (folio), folio); +VM_WARN_ON_FOLIO (folio_test_large (folio) && + !folio_test_large_rmappable (folio), folio); + +VM_WARN_ON_ONCE (nr_pages <=0 ); +VM_WARN_ON_FOLIO (page_folio (page) != folio, folio); +VM_WARN_ON_FOLIO (page_folio (page + nr_pages -1 ) != folio, folio); + +switch (level) { +case RMAP_LEVEL_PTE : +break ; +case RMAP_LEVEL_PMD : +/* +* We don't support folios larger than a single PMD yet. So +* when RMAP_LEVEL_PMD is set, we assume that we are creating +* a single "entire" mapping of the folio. +*/ +VM_WARN_ON_FOLIO (folio_nr_pages (folio) !=HPAGE_PMD_NR , folio); +VM_WARN_ON_FOLIO (nr_pages !=HPAGE_PMD_NR , folio); +break ; +default : +VM_WARN_ON_ONCE (true); + } +} + +/* * rmap interfaces called when adding or removing pte of page */ void folio_move_anon_rmap (struct folio *,struct vm_area_struct *);
@@ -201,8 +239,12 @@ void folio_add_new_anon_rmap(struct foli unsigned long address);void page_add_file_rmap (struct page *,struct vm_area_struct *,bool compound); -void folio_add_file_rmap_range (struct folio *,struct page *,unsigned int nr, -struct vm_area_struct *,bool compound); +void folio_add_file_rmap_ptes (struct folio *,struct page *,int nr_pages, +struct vm_area_struct *); +#define folio_add_file_rmap_pte (folio, page, vma) \ + folio_add_file_rmap_ptes(folio, page, 1, vma) +void folio_add_file_rmap_pmd (struct folio *,struct page *, +struct vm_area_struct *);void page_remove_rmap (struct page *,struct vm_area_struct *,bool compound);
mm/memory.c renamed from mm/memory.c~mm-rmap-convert-folio_add_file_rmap_range-into-folio_add_file_rmap_ +1 -1
@@ -4516,7 +4516,7 @@ void set_pte_range(struct vm_fault *vmf,folio_add_lru_vma (folio, vma); }else {add_mm_counter (vma->vm_mm,mm_counter_file (page), nr); -folio_add_file_rmap_range (folio, page, nr, vma, false); +folio_add_file_rmap_ptes (folio, page, nr, vma); }set_ptes (vma->vm_mm, addr, vmf->pte, entry, nr);
mm/rmap.c renamed from mm/rmap.c~mm-rmap-convert-folio_add_file_rmap_range-into-folio_add_file_rmap_ +50 -29
118 lines not on this page · raw message
_
Patches currently in -mm which might be from [email protected] are