linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RFC] mm/memory.c: Optimizing THP zeroing routine for !HIGHMEM cases
@ 2020-04-03  8:18 Prathu Baronia
  2020-04-03  8:52 ` Michal Hocko
  2020-04-10 18:54 ` Alexander Duyck
  0 siblings, 2 replies; 14+ messages in thread
From: Prathu Baronia @ 2020-04-03  8:18 UTC (permalink / raw)
  To: akpm, linux-mm
  Cc: gregkh, gthelen, jack, mhocko, ken.lin, gasine.xu, chintan.pandya

THP allocation for anon memory requires zeroing of the huge page. To do so,
we iterate over 2MB memory in 4KB chunks. Each iteration calls for kmap_atomic()
and kunmap_atomic(). This routine makes sense where we need temporary mapping of
the user page. In !HIGHMEM cases, specially in 64-bit architectures, we don't
need temp mapping. Hence, kmap_atomic() acts as nothing more than multiple
barrier() calls.

This called for optimization. Simply getting VADDR from page does the job for
us. So, implement another (optimized) routine for clear_huge_page() which
doesn't need temporary mapping of user space page.

While testing this patch on Qualcomm SM8150 SoC (kernel v4.14.117), we see 64%
Improvement in clear_huge_page().

Ftrace results:

Default profile:
 ------------------------------------------
 6) ! 473.802 us  |  clear_huge_page();
 ------------------------------------------

With this patch applied:
 ------------------------------------------
 5) ! 170.156 us  |  clear_huge_page();
 ------------------------------------------

Signed-off-by: Prathu Baronia <prathu.baronia@oneplus.com>
Reported-by: Chintan Pandya <chintan.pandya@oneplus.com>
---
 mm/memory.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/mm/memory.c b/mm/memory.c
index 3ee073d..3e120e8 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -5119,6 +5119,7 @@ EXPORT_SYMBOL(__might_fault);
 #endif
 
 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
+#ifdef CONFIG_HIGHMEM
 static void clear_gigantic_page(struct page *page,
 				unsigned long addr,
 				unsigned int pages_per_huge_page)
@@ -5183,6 +5184,16 @@ void clear_huge_page(struct page *page,
 				    addr + right_idx * PAGE_SIZE);
 	}
 }
+#else
+void clear_huge_page(struct page *page,
+		     unsigned long addr_hint, unsigned int pages_per_huge_page)
+{
+	void *addr;
+
+	addr = page_address(page);
+	memset(addr, 0, pages_per_huge_page*PAGE_SIZE);
+}
+#endif
 
 static void copy_user_gigantic_page(struct page *dst, struct page *src,
 				    unsigned long addr,
-- 
2.7.4


-- 
Prathu Baronia


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2020-04-14 17:33 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-03  8:18 [RFC] mm/memory.c: Optimizing THP zeroing routine for !HIGHMEM cases Prathu Baronia
2020-04-03  8:52 ` Michal Hocko
2020-04-09 15:29   ` Prathu Baronia
2020-04-09 15:45     ` Michal Hocko
     [not found]       ` <SG2PR04MB2921D2AAA8726318EF53D83691DE0@SG2PR04MB2921.apcprd04.prod.outlook.com>
2020-04-10  9:05         ` Huang, Ying
2020-04-11 15:40           ` Chintan Pandya
2020-04-11 20:47             ` Alexander Duyck
2020-04-13 15:33               ` Prathu Baronia
2020-04-13 16:24                 ` Alexander Duyck
2020-04-14  1:10                 ` Huang, Ying
2020-04-10 18:54 ` Alexander Duyck
2020-04-11  8:45   ` Chintan Pandya
2020-04-14 15:55     ` Daniel Jordan
2020-04-14 17:33       ` Chintan Pandya

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).