linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: hugetlb_vmemmap: simplify reset_struct_pages()
@ 2022-08-19  3:55 Muchun Song
  2022-08-19  7:43 ` Miaohe Lin
  0 siblings, 1 reply; 2+ messages in thread
From: Muchun Song @ 2022-08-19  3:55 UTC (permalink / raw)
  To: mike.kravetz, songmuchun, akpm; +Cc: linux-mm, linux-kernel, muchun.song

We can choose to copy three contiguous tail pages' content to the first three pages
instead of copying one by one to simplify the code and reduce code size from 229 bytes
to 63 bytes. The BUILD_BUG_ON() aims to avoid out-of-bounds accesses.

Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
 mm/hugetlb_vmemmap.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
index 76b2d03a0d8d..ba2a2596fb4e 100644
--- a/mm/hugetlb_vmemmap.c
+++ b/mm/hugetlb_vmemmap.c
@@ -265,11 +265,10 @@ static void vmemmap_remap_pte(pte_t *pte, unsigned long addr,
 
 static inline void reset_struct_pages(struct page *start)
 {
-	int i;
 	struct page *from = start + NR_RESET_STRUCT_PAGE;
 
-	for (i = 0; i < NR_RESET_STRUCT_PAGE; i++)
-		memcpy(start + i, from, sizeof(*from));
+	BUILD_BUG_ON(NR_RESET_STRUCT_PAGE * 2 > PAGE_SIZE / sizeof(struct page));
+	memcpy(start, from, sizeof(*from) * NR_RESET_STRUCT_PAGE);
 }
 
 static void vmemmap_restore_pte(pte_t *pte, unsigned long addr,
-- 
2.11.0



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

* Re: [PATCH] mm: hugetlb_vmemmap: simplify reset_struct_pages()
  2022-08-19  3:55 [PATCH] mm: hugetlb_vmemmap: simplify reset_struct_pages() Muchun Song
@ 2022-08-19  7:43 ` Miaohe Lin
  0 siblings, 0 replies; 2+ messages in thread
From: Miaohe Lin @ 2022-08-19  7:43 UTC (permalink / raw)
  To: Muchun Song
  Cc: linux-mm, linux-kernel, muchun.song, Mike Kravetz, Andrew Morton

On 2022/8/19 11:55, Muchun Song wrote:
> We can choose to copy three contiguous tail pages' content to the first three pages
> instead of copying one by one to simplify the code and reduce code size from 229 bytes
> to 63 bytes. The BUILD_BUG_ON() aims to avoid out-of-bounds accesses.
> 
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>

LGTM. Thanks.

Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>

Thanks,
Miaohe Lin


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

end of thread, other threads:[~2022-08-19  7:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-19  3:55 [PATCH] mm: hugetlb_vmemmap: simplify reset_struct_pages() Muchun Song
2022-08-19  7:43 ` Miaohe Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox