Skip to contentSkip to conversation

mm: simplify free_highmem_page() and free_reserved_page()

PATCH Applied David Hildenbrand 4 participants 9 messages Jan 26, 2021 – Jan 28, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover mm: simplify free_highmem_page() and free_reserved_page()

Let's simplify and unify free_highmem_page() and free_reserved_page().

Gave it a quick test in i386 QEMU with 4G of RAM - seems to work just fine.

David Hildenbrand (2):
video: fbdev: acornfb: remove free_unused_pages()
mm: simplify free_highmem_page() and free_reserved_page()

 drivers/video/fbdev/acornfb.c    | 34 --------------------------------
 include/linux/highmem-internal.h |  5 -----
 include/linux/mm.h               | 16 ++-------------
 mm/page_alloc.c                  | 11 -----------
 4 files changed, 2 insertions(+), 64 deletions(-)
Signature · 1 line
2.29.2
#1 lore raw

PATCH 1/2 video: fbdev: acornfb: remove free_unused_pages()

This function is never used and it is one of the last remaining user of __free_reserved_page(). Let's just drop it.

Cc Andrew Morton <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc "Peter Zijlstra (Intel)" <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Wei Yang <[email protected]>
Cc "Gustavo A. R. Silva" <[email protected]>
Cc Sam Ravnborg <[email protected]>
---
 drivers/video/fbdev/acornfb.c | 34 ----------------------------------
 1 file changed, 34 deletions(-)
drivers/video/fbdev/acornfb.c +0 -34
index bcc92aecf666..1b72edc01cfb 100644
@@ -921,40 +921,6 @@ static int acornfb_detect_monitortype(void)
 	return 4;
 }
 
-/*
- * This enables the unused memory to be freed on older Acorn machines.
- * We are freeing memory on behalf of the architecture initialisation
- * code here.
- */
-static inline void
-free_unused_pages(unsigned int virtual_start, unsigned int virtual_end)
-{
-	int mb_freed = 0;
-
-	/*
-	 * Align addresses
-	 */
-	virtual_start = PAGE_ALIGN(virtual_start);
-	virtual_end = PAGE_ALIGN(virtual_end);
-
-	while (virtual_start < virtual_end) {
-		struct page *page;
-
-		/*
-		 * Clear page reserved bit,
-		 * set count to 1, and free
-		 * the page.
-		 */
-		page = virt_to_page(virtual_start);
-		__free_reserved_page(page);
-
-		virtual_start += PAGE_SIZE;
-		mb_freed += PAGE_SIZE / 1024;
-	}
-
-	printk("acornfb: freed %dK memory\n", mb_freed);
-}
-
 static int acornfb_probe(struct platform_device *dev)
 {
 	unsigned long size;
Signature · 1 line
2.29.2
#2 lore raw

Re: [PATCH v1 1/2] video: fbdev: acornfb: remove free_unused_pages()

Quoted 13 lines · David Hildenbrand

This function is never used and it is one of the last remaining user of __free_reserved_page(). Let's just drop it.

Cc Andrew Morton <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc "Peter Zijlstra (Intel)" <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Wei Yang <[email protected]>
Cc "Gustavo A. R. Silva" <[email protected]>
Cc Sam Ravnborg <[email protected]>
Fixes ffd29195ed720188 ("drivers/video/acornfb.c: remove dead code")

Gr{oetje,eeting}s,

Geert

Signature · 9 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH v1 1/2] video: fbdev: acornfb: remove free_unused_pages()

In reply to David Hildenbrand
Quoted 13 lines · David Hildenbrand

This function is never used and it is one of the last remaining user of __free_reserved_page(). Let's just drop it.

Cc Andrew Morton <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc "Peter Zijlstra (Intel)" <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Wei Yang <[email protected]>
Cc "Gustavo A. R. Silva" <[email protected]>
Cc Sam Ravnborg <[email protected]>
Quoted 52 lines
---
 drivers/video/fbdev/acornfb.c | 34 ----------------------------------
 1 file changed, 34 deletions(-)
drivers/video/fbdev/acornfb.c +0 -34
index bcc92aecf666..1b72edc01cfb 100644
@@ -921,40 +921,6 @@ static int acornfb_detect_monitortype(void)
 	return 4;
 }
 
-/*
- * This enables the unused memory to be freed on older Acorn machines.
- * We are freeing memory on behalf of the architecture initialisation
- * code here.
- */
-static inline void
-free_unused_pages(unsigned int virtual_start, unsigned int virtual_end)
-{
-	int mb_freed = 0;
-
-	/*
-	 * Align addresses
-	 */
-	virtual_start = PAGE_ALIGN(virtual_start);
-	virtual_end = PAGE_ALIGN(virtual_end);
-
-	while (virtual_start < virtual_end) {
-		struct page *page;
-
-		/*
-		 * Clear page reserved bit,
-		 * set count to 1, and free
-		 * the page.
-		 */
-		page = virt_to_page(virtual_start);
-		__free_reserved_page(page);
-
-		virtual_start += PAGE_SIZE;
-		mb_freed += PAGE_SIZE / 1024;
-	}
-
-	printk("acornfb: freed %dK memory\n", mb_freed);
-}
-
 static int acornfb_probe(struct platform_device *dev)
 {
 	unsigned long size;
Signature · 1 line
2.29.2
Signature · 2 lines
Oscar Salvador
SUSE L3
Reviewed-by on v1 1/2
#4 lore raw

Re: [PATCH v1 1/2] video: fbdev: acornfb: remove free_unused_pages()

In reply to David Hildenbrand
Quoted 13 lines · David Hildenbrand

This function is never used and it is one of the last remaining user of __free_reserved_page(). Let's just drop it.

Cc Andrew Morton <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc "Peter Zijlstra (Intel)" <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Wei Yang <[email protected]>
Cc "Gustavo A. R. Silva" <[email protected]>
Cc Sam Ravnborg <[email protected]>

There is no other reference for free_unused_pages() in the tree.

Quoted 50 lines
---
 drivers/video/fbdev/acornfb.c | 34 ----------------------------------
 1 file changed, 34 deletions(-)
drivers/video/fbdev/acornfb.c +0 -34
index bcc92aecf666..1b72edc01cfb 100644
@@ -921,40 +921,6 @@ static int acornfb_detect_monitortype(void)
 	return 4;
 }
 
-/*
- * This enables the unused memory to be freed on older Acorn machines.
- * We are freeing memory on behalf of the architecture initialisation
- * code here.
- */
-static inline void
-free_unused_pages(unsigned int virtual_start, unsigned int virtual_end)
-{
-	int mb_freed = 0;
-
-	/*
-	 * Align addresses
-	 */
-	virtual_start = PAGE_ALIGN(virtual_start);
-	virtual_end = PAGE_ALIGN(virtual_end);
-
-	while (virtual_start < virtual_end) {
-		struct page *page;
-
-		/*
-		 * Clear page reserved bit,
-		 * set count to 1, and free
-		 * the page.
-		 */
-		page = virt_to_page(virtual_start);
-		__free_reserved_page(page);
-
-		virtual_start += PAGE_SIZE;
-		mb_freed += PAGE_SIZE / 1024;
-	}
-
-	printk("acornfb: freed %dK memory\n", mb_freed);
-}
-
 static int acornfb_probe(struct platform_device *dev)
 {
 	unsigned long size;
#5 lore raw

PATCH 2/2 mm: simplify free_highmem_page() and free_reserved_page()

In reply to David Hildenbrand

adjust_managed_page_count() as called by free_reserved_page() properly handles pages in a highmem zone, so we can reuse it for free_highmem_page().

We can now get rid of totalhigh_pages_inc() and simplify free_reserved_page().

Cc Andrew Morton <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc "Peter Zijlstra (Intel)" <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Wei Yang <[email protected]>
---
 include/linux/highmem-internal.h |  5 -----
 include/linux/mm.h               | 16 ++--------------
 mm/page_alloc.c                  | 11 -----------
 3 files changed, 2 insertions(+), 30 deletions(-)
include/linux/highmem-internal.h +0 -5
index 1bbe96dc8be6..7902c7d8b55f 100644
@@ -127,11 +127,6 @@ static inline unsigned long totalhigh_pages(void)
 	return (unsigned long)atomic_long_read(&_totalhigh_pages);
 }
 
-static inline void totalhigh_pages_inc(void)
-{
-	atomic_long_inc(&_totalhigh_pages);
-}
-
 static inline void totalhigh_pages_add(long count)
 {
 	atomic_long_add(count, &_totalhigh_pages);
include/linux/mm.h +2 -14
index a5d618d08506..494c69433a34 100644
@@ -2303,32 +2303,20 @@ extern void free_initmem(void);
 extern unsigned long free_reserved_area(void *start, void *end,
 					int poison, const char *s);
 
-#ifdef	CONFIG_HIGHMEM
-/*
- * Free a highmem page into the buddy system, adjusting totalhigh_pages
- * and totalram_pages.
- */
-extern void free_highmem_page(struct page *page);
-#endif
-
 extern void adjust_managed_page_count(struct page *page, long count);
 extern void mem_init_print_info(const char *str);
 
 extern void reserve_bootmem_region(phys_addr_t start, phys_addr_t end);
 
 /* Free the reserved page into the buddy system, so it gets managed. */
-static inline void __free_reserved_page(struct page *page)
+static inline void free_reserved_page(struct page *page)
 {
 	ClearPageReserved(page);
 	init_page_count(page);
 	__free_page(page);
-}
-
-static inline void free_reserved_page(struct page *page)
-{
-	__free_reserved_page(page);
 	adjust_managed_page_count(page, 1);
 }
+#define free_highmem_page(page) free_reserved_page(page)
 
 static inline void mark_page_reserved(struct page *page)
 {
mm/page_alloc.c +0 -11
index b031a5ae0bd5..b2e42f10d4d4 100644
@@ -7711,17 +7711,6 @@ unsigned long free_reserved_area(void *start, void *end, int poison, const char
 	return pages;
 }
 
-#ifdef	CONFIG_HIGHMEM
-void free_highmem_page(struct page *page)
-{
-	__free_reserved_page(page);
-	totalram_pages_inc();
-	atomic_long_inc(&page_zone(page)->managed_pages);
-	totalhigh_pages_inc();
-}
-#endif
-
-
 void __init mem_init_print_info(const char *str)
 {
 	unsigned long physpages, codesize, datasize, rosize, bss_size;
Signature · 6 lines
2.29.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 2/2
#6 lore raw
Quoted 7 lines · David Hildenbrand

adjust_managed_page_count() as called by free_reserved_page() properly handles pages in a highmem zone, so we can reuse it for free_highmem_page().

We can now get rid of totalhigh_pages_inc() and simplify free_reserved_page().

Quoted 8 lines
Cc Andrew Morton <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc "Peter Zijlstra (Intel)" <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Wei Yang <[email protected]>
Quoted 1 line

+#define free_highmem_page(page) free_reserved_page(page)

Should we place that under #ifdef CONFIG_HIGHMEM to make clear that it is only used on that config?
Maybe the #ifdefery ugliness does not pay off.

Signature · 2 lines
Oscar Salvador
SUSE L3
#7 lore raw
Quoted 17 lines · Oscar Salvador
Quoted 7 lines · David Hildenbrand

adjust_managed_page_count() as called by free_reserved_page() properly handles pages in a highmem zone, so we can reuse it for free_highmem_page().

We can now get rid of totalhigh_pages_inc() and simplify free_reserved_page().

Quoted 8 lines
Cc Andrew Morton <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc "Peter Zijlstra (Intel)" <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Wei Yang <[email protected]>
Quoted 7 lines
Quoted 1 line

+#define free_highmem_page(page) free_reserved_page(page)

Should we place that under #ifdef CONFIG_HIGHMEM to make clear that it is only used on that config?
Maybe the #ifdefery ugliness does not pay off.

Yeah, most probably not worth it.

Signature · 3 lines
Thanks,

David / dhildenb
Reviewed-by on v1 2/2
#8 lore raw
In reply to David Hildenbrand
Quoted 7 lines · David Hildenbrand

adjust_managed_page_count() as called by free_reserved_page() properly handles pages in a highmem zone, so we can reuse it for free_highmem_page().

We can now get rid of totalhigh_pages_inc() and simplify free_reserved_page().

Quoted 8 lines
Cc Andrew Morton <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc "Peter Zijlstra (Intel)" <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Wei Yang <[email protected]>
Quoted 84 lines
---
 include/linux/highmem-internal.h |  5 -----
 include/linux/mm.h               | 16 ++--------------
 mm/page_alloc.c                  | 11 -----------
 3 files changed, 2 insertions(+), 30 deletions(-)
include/linux/highmem-internal.h +0 -5
index 1bbe96dc8be6..7902c7d8b55f 100644
@@ -127,11 +127,6 @@ static inline unsigned long totalhigh_pages(void)
 	return (unsigned long)atomic_long_read(&_totalhigh_pages);
 }
 
-static inline void totalhigh_pages_inc(void)
-{
-	atomic_long_inc(&_totalhigh_pages);
-}
-
 static inline void totalhigh_pages_add(long count)
 {
 	atomic_long_add(count, &_totalhigh_pages);
include/linux/mm.h +2 -14
index a5d618d08506..494c69433a34 100644
@@ -2303,32 +2303,20 @@ extern void free_initmem(void);
 extern unsigned long free_reserved_area(void *start, void *end,
 					int poison, const char *s);
 
-#ifdef	CONFIG_HIGHMEM
-/*
- * Free a highmem page into the buddy system, adjusting totalhigh_pages
- * and totalram_pages.
- */
-extern void free_highmem_page(struct page *page);
-#endif
-
 extern void adjust_managed_page_count(struct page *page, long count);
 extern void mem_init_print_info(const char *str);
 
 extern void reserve_bootmem_region(phys_addr_t start, phys_addr_t end);
 
 /* Free the reserved page into the buddy system, so it gets managed. */
-static inline void __free_reserved_page(struct page *page)
+static inline void free_reserved_page(struct page *page)
 {
 	ClearPageReserved(page);
 	init_page_count(page);
 	__free_page(page);
-}
-
-static inline void free_reserved_page(struct page *page)
-{
-	__free_reserved_page(page);
 	adjust_managed_page_count(page, 1);
 }
+#define free_highmem_page(page) free_reserved_page(page)
 
 static inline void mark_page_reserved(struct page *page)
 {
mm/page_alloc.c +0 -11
index b031a5ae0bd5..b2e42f10d4d4 100644
@@ -7711,17 +7711,6 @@ unsigned long free_reserved_area(void *start, void *end, int poison, const char
 	return pages;
 }
 
-#ifdef	CONFIG_HIGHMEM
-void free_highmem_page(struct page *page)
-{
-	__free_reserved_page(page);
-	totalram_pages_inc();
-	atomic_long_inc(&page_zone(page)->managed_pages);
-	totalhigh_pages_inc();
-}
-#endif
-
-
 void __init mem_init_print_info(const char *str)
 {
 	unsigned long physpages, codesize, datasize, rosize, bss_size;