linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC/RFT PATCH v3 0/1] arc: add sparsemem support
@ 2020-08-31  6:47 Mike Rapoport
  2020-08-31  6:47 ` [RFC/RFT PATCH v3 1/1] " Mike Rapoport
  0 siblings, 1 reply; 2+ messages in thread
From: Mike Rapoport @ 2020-08-31  6:47 UTC (permalink / raw)
  To: Vineet Gupta
  Cc: Eugeniy Paltsev, Mike Rapoport, linux-snps-arc, linux-kernel,
	Mike Rapoport

From: Mike Rapoport <rppt@linux.ibm.com>

Hi,

This is yet another attempt to enable SPARSEMEM on ARC.

I've boot tested it on nSIM with haps_hs_defconfig with highmem and
sparsemem enabled.

With sparsemem the kernel text becomes a bit smaller, but bss and data are
slightly increased:

$ size discontig/vmlinux sparse/vmlinux
   text	   data	    bss	    dec	    hex	filename
4429390	 785456	 244580	5459426	 534de2	discontig/vmlinux
4415099	 786224	 244844	5446167	 531a17	sparse/vmlinux

I've also added a dummy global functions to wrap pfn_valid(), page_to_pfn()
and pfn_to_page(). Judging by objdump, sparsemem is a bit more efficient:

	DISCONTIGMEM			SPARSEMEM
<pfn_to_page>:
	seths	r2,0x3ffff,r0		lsr	r2,r0,0xe
	mpy	r2,r2,1896		mpy	r0,r0,0x24
	add	r3,r2,0x8050066c	add3	r2,0x80529d1c,r2
	add_s	r2,r2,0x80500668	ld_s	r2,[r2,0]
	ld_s	r3,[r3,0]		bmskn	r2,r2,0x3
	sub_s	r0,r0,r3		j_s.d	[blink]
	ld_s	r2,[r2,0]		add_s	r0,r0,r2
	mpy	r0,r0,0x24		nop_s
	j_s.d	[blink]
	add_s	r0,r0,r2

<page_to_pfn>:
	ld_s	r2,[r0,0]		ld_s	r2,[r0,0]
	lsr_s	r2,r2,0x1f	 	lsr_s	r2,r2,0x1b
	mpy	r2,r2,1896	 	add3	r2,0x80529d1c,r2
	add	r3,r2,0x80500668 	ld_s	r2,[r2,0]
	add_s	r2,r2,0x8050066c 	bmskn	r2,r2,0x3
	ld_s	r3,[r3,0]	 	sub_s	r0,r0,r2
	sub_s	r0,r0,r3	 	asr_s	r0,r0,0x2
	ld_s	r2,[r2,0]	 	mpy	r0,r0,0x38e38e39
	asr_s	r0,r0,0x2	 	j_s	[blink]
	mpy	r0,r0,0x38e38e39
	j_s.d	[blink]
	add_s	r0,r0,r2
	nop_s

<pfn_valid>:
	cmp_s	r0,0x3ffff		lsr_s	r0,r0,0xe
	mov_s	r2,0			brhs.nt	r0,0x20,24
	mov.ls	r2,0x768		add3	r0,0x80529d1c,r0
	add_s	r2,r2,0x80500814	breq_s	r0,0,12
	ld.as	r3,[r2,-106]		ld_s	r0,[r0,0]
	ld.as	r2,[r2,-104]		j_s.d	[blink]
	add_s	r2,r2,r3		xbfu	r0,r0,0x1
	j_s.d	[blink]			j_s.d	[blink]
	seths	r0,r2,r0		mov_s	r0,0
	nop_s

Still, SPARSEMEM has an issue with potentially wasted memory allocated for
the memory map. The memory maps are allocated for each present section,
which means that if part of the section is not populated we'll have a bunch
of unused 'struct page' objects. The smaller the section size, the smaller
is memory overhead, but the section size cannot be much smaller than the
physical address because 

	MAX_PHYSMEM_BITS - SECTION_SIZE_BITS

has to fit into page flags and the room there is limited.

There is yet another possibility to support separate banks. It is possible
to use FLATMEM and free the memmap allocated for the hole, like, for
instance, ARM does [1]. This will require ARC's override for pfn_valid()
that takes into account the actual memory configuration rather than relies
on the memmap.

[1] https://elixir.bootlin.com/linux/latest/source/arch/arm/mm/init.c#L305

Mike Rapoport (1):
  arc: add sparsemem support

 arch/arc/Kconfig                 | 10 ++++++++++
 arch/arc/include/asm/sparsemem.h | 13 +++++++++++++
 arch/arc/mm/init.c               |  6 +++++-
 3 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 arch/arc/include/asm/sparsemem.h

-- 
2.26.2


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

* [RFC/RFT PATCH v3 1/1] arc: add sparsemem support
  2020-08-31  6:47 [RFC/RFT PATCH v3 0/1] arc: add sparsemem support Mike Rapoport
@ 2020-08-31  6:47 ` Mike Rapoport
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Rapoport @ 2020-08-31  6:47 UTC (permalink / raw)
  To: Vineet Gupta
  Cc: Eugeniy Paltsev, Mike Rapoport, linux-snps-arc, linux-kernel,
	Mike Rapoport

From: Mike Rapoport <rppt@linux.ibm.com>

Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
---
 arch/arc/Kconfig                 | 10 ++++++++++
 arch/arc/include/asm/sparsemem.h | 13 +++++++++++++
 arch/arc/mm/init.c               |  6 +++++-
 3 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 arch/arc/include/asm/sparsemem.h

diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig
index ba00c4e1e1c2..2e3c02e9b657 100644
--- a/arch/arc/Kconfig
+++ b/arch/arc/Kconfig
@@ -48,6 +48,7 @@ config ARC
 	select PCI_SYSCALL if PCI
 	select PERF_USE_VMALLOC if ARC_CACHE_VIPT_ALIASING
 	select HAVE_ARCH_JUMP_LABEL if ISA_ARCV2 && !CPU_ENDIAN_BE32
+	select SPARSEMEM_STATIC if SPARSEMEM
 
 config ARCH_HAS_CACHE_LINE_SIZE
 	def_bool y
@@ -67,8 +68,15 @@ config GENERIC_CSUM
 config ARCH_DISCONTIGMEM_ENABLE
 	def_bool n
 
+config ARCH_SPARSEMEM_ENABLE
+	def_bool n
+
 config ARCH_FLATMEM_ENABLE
 	def_bool y
+	depends on !HIGHMEM
+
+config ARCH_SELECT_MEMORY_MODEL
+	def_bool n
 
 config MMU
 	def_bool y
@@ -508,6 +516,8 @@ config LINUX_RAM_BASE
 config HIGHMEM
 	bool "High Memory Support"
 	select ARCH_DISCONTIGMEM_ENABLE
+	select ARCH_SPARSEMEM_ENABLE
+	select ARCH_SELECT_MEMORY_MODEL
 	help
 	  With ARC 2G:2G address split, only upper 2G is directly addressable by
 	  kernel. Enable this to potentially allow access to rest of 2G and PAE
diff --git a/arch/arc/include/asm/sparsemem.h b/arch/arc/include/asm/sparsemem.h
new file mode 100644
index 000000000000..1156b9934c74
--- /dev/null
+++ b/arch/arc/include/asm/sparsemem.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_ARC_SPARSEMEM_H
+#define _ASM_ARC_SPARSEMEM_H
+
+#ifdef CONFIG_ARC_HAS_PAE40
+#define MAX_PHYSMEM_BITS	40
+#define SECTION_SIZE_BITS	32
+#else
+#define MAX_PHYSMEM_BITS	32
+#define SECTION_SIZE_BITS	27
+#endif
+
+#endif /* _ASM_ARC_SPARSEMEM_H */
diff --git a/arch/arc/mm/init.c b/arch/arc/mm/init.c
index 3a35b82a718e..60e3808a4e19 100644
--- a/arch/arc/mm/init.c
+++ b/arch/arc/mm/init.c
@@ -153,7 +153,11 @@ void __init setup_arch_memory(void)
 	 * DISCONTIGMEM in turns requires multiple nodes. node 0 above is
 	 * populated with normal memory zone while node 1 only has highmem
 	 */
+#ifdef CONFIG_DISCONTIGMEM
 	node_set_online(1);
+#elif defined(CONFIG_SPARSEMEM)
+	sparse_init();
+#endif
 
 	min_high_pfn = PFN_DOWN(high_mem_start);
 	max_high_pfn = PFN_DOWN(high_mem_start + high_mem_sz);
@@ -162,7 +166,7 @@ void __init setup_arch_memory(void)
 
 	high_memory = (void *)(min_high_pfn << PAGE_SHIFT);
 	kmap_init();
-#endif
+#endif /* CONFIG_HIGHMEM */
 
 	free_area_init(max_zone_pfn);
 }
-- 
2.26.2


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

end of thread, other threads:[~2020-08-31  6:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-31  6:47 [RFC/RFT PATCH v3 0/1] arc: add sparsemem support Mike Rapoport
2020-08-31  6:47 ` [RFC/RFT PATCH v3 1/1] " Mike Rapoport

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).