From: "Alex Shi (tencent)" <[email protected]>
To replace pages_identical() func and further reduce the 'page' using in
try_to_merge_one_page function.
Signed-off-by: Alex Shi (tencent) <[email protected]>
---
include/linux/mm.h | 17 +++++++++++++++++
mm/ksm.c | 2 +-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 9849dfda44d4..2d1f16ffc6ac 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -4164,6 +4164,23 @@ static inline void setup_nr_node_ids(void) {}
extern int memcmp_pages(struct page *page1, struct page *page2);
+static inline int identical_folio(struct folio *folio1, struct folio *folio2)
+{
+ int i, nr1, nr2, ret = 0;
+
+ nr1 = folio_nr_pages(folio1);
+ nr2 = folio_nr_pages(folio2);
+ if (nr1 != nr2)
+ return 0;
+
+ for (i = 0; i < nr1; i++) {
+ ret = memcmp_pages(folio_page(folio1, i), folio_page(folio2, i));
+ if (ret)
+ break;
+ }
+
+ return !ret;
+}
static inline int pages_identical(struct page *page1, struct page *page2)
{
return !memcmp_pages(page1, page2);
diff --git a/mm/ksm.c b/mm/ksm.c
index 21bfa9bfb210..2e4790842515 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -1527,7 +1527,7 @@ static int try_to_merge_one_page(struct vm_area_struct *vma, struct folio *folio
if (!folio_test_dirty(folio))
folio_set_dirty(folio);
err = 0;
- } else if (pages_identical(page, kpage))
+ } else if (identical_folio(folio, kfolio))
err = replace_page(vma, page, kpage, orig_pte);
}
--
2.43.0
On 04.06.24 06:24, [email protected] wrote:
> From: "Alex Shi (tencent)" <[email protected]>
>
> To replace pages_identical() func and further reduce the 'page' using in
> try_to_merge_one_page function.
>
> Signed-off-by: Alex Shi (tencent) <[email protected]>
> ---
> include/linux/mm.h | 17 +++++++++++++++++
> mm/ksm.c | 2 +-
> 2 files changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 9849dfda44d4..2d1f16ffc6ac 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -4164,6 +4164,23 @@ static inline void setup_nr_node_ids(void) {}
>
> extern int memcmp_pages(struct page *page1, struct page *page2);
>
> +static inline int identical_folio(struct folio *folio1, struct folio *folio2)
> +{
> + int i, nr1, nr2, ret = 0;
> +
> + nr1 = folio_nr_pages(folio1);
> + nr2 = folio_nr_pages(folio2);
> + if (nr1 != nr2)
> + return 0;
> +
> + for (i = 0; i < nr1; i++) {
> + ret = memcmp_pages(folio_page(folio1, i), folio_page(folio2, i));
> + if (ret)
> + break;
> + }
> +
> + return !ret;
> +}
We never get there with large folios. So handling large folios is
completely unnecessary.
Keep it simple: either VM_WARN_ON_ONCE when a large folio is passed, or
simply return "false". Then, check only a single page.
--
Cheers,
David / dhildenb