Skip to contentSkip to conversation

staging: zsmalloc: remove SPARSEMEM dependency

PATCH In review Seth Jennings 2 participants 7 messages Mar 5, 2012

Subsystems (2)
lore
Share & tools
lore
#3 lore raw

PATCH 3/5 staging: zsmalloc: calculate MAX_PHYSMEM_BITS if not defined

In reply to Seth Jennings

This patch provides a way to determine or "set a reasonable value for" MAX_PHYSMEM_BITS in the case that it is not defined (i.e. !SPARSEMEM)

---
 drivers/staging/zsmalloc/zsmalloc_int.h |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
drivers/staging/zsmalloc/zsmalloc_int.h +14 -0
index 4d66d2d..ffb272f 100644
@@ -39,7 +39,21 @@
  * Note that object index <obj_idx> is relative to system
  * page <PFN> it is stored in, so for each sub-page belonging
  * to a zspage, obj_idx starts with 0.
+ *
+ * This is made more complicated by various memory models and PAE.
+ */
+
+#ifndef MAX_PHYSMEM_BITS
+#ifdef CONFIG_HIGHMEM64G
+#define MAX_PHYSMEM_BITS 36
+#else /* !CONFIG_HIGHMEM64G */
+/*
+ * If this definition of MAX_PHYSMEM_BITS is used, OBJ_INDEX_BITS will just
+ * be PAGE_SHIFT
  */
+#define MAX_PHYSMEM_BITS BITS_PER_LONG
+#endif
+#endif
 #define _PFN_BITS		(MAX_PHYSMEM_BITS - PAGE_SHIFT)
 #define OBJ_INDEX_BITS	(BITS_PER_LONG - _PFN_BITS)
 #define OBJ_INDEX_MASK	((_AC(1, UL) << OBJ_INDEX_BITS) - 1)
Signature · 8 lines
1.7.5.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

PATCH 1/5 staging: zsmalloc: move object/handle masking defines

In reply to Seth Jennings

This patch moves the definitions of _PFN_BITS, OBJ_INDEX_BITS and OBJ_INDEX_MASK from zsmalloc-main.c to zsmalloc_int.h

They will be needed to determine ZS_MIN_ALLOC_SIZE in the next patch

---
 drivers/staging/zsmalloc/zsmalloc-main.c |   12 ------------
 drivers/staging/zsmalloc/zsmalloc_int.h  |   12 ++++++++++++
 2 files changed, 12 insertions(+), 12 deletions(-)
drivers/staging/zsmalloc/zsmalloc-main.c +0 -12
index 455fc2f..240bcbf 100644
@@ -40,18 +40,6 @@
 #define CLASS_IDX_MASK	((1 << CLASS_IDX_BITS) - 1)
 #define FULLNESS_MASK	((1 << FULLNESS_BITS) - 1)
 
-/*
- * Object location (<PFN>, <obj_idx>) is encoded as
- * as single (void *) handle value.
- *
- * Note that object index <obj_idx> is relative to system
- * page <PFN> it is stored in, so for each sub-page belonging
- * to a zspage, obj_idx starts with 0.
- */
-#define _PFN_BITS		(MAX_PHYSMEM_BITS - PAGE_SHIFT)
-#define OBJ_INDEX_BITS	(BITS_PER_LONG - _PFN_BITS)
-#define OBJ_INDEX_MASK	((_AC(1, UL) << OBJ_INDEX_BITS) - 1)
-
 /* per-cpu VM mapping areas for zspage accesses that cross page boundaries */
 static DEFINE_PER_CPU(struct mapping_area, zs_map_area);
 
drivers/staging/zsmalloc/zsmalloc_int.h +12 -0
index 354a020..e06e142 100644
@@ -25,6 +25,18 @@
  */
 #define ZS_ALIGN		8
 
+/*
+ * Object location (<PFN>, <obj_idx>) is encoded as
+ * as single (void *) handle value.
+ *
+ * Note that object index <obj_idx> is relative to system
+ * page <PFN> it is stored in, so for each sub-page belonging
+ * to a zspage, obj_idx starts with 0.
+ */
+#define _PFN_BITS		(MAX_PHYSMEM_BITS - PAGE_SHIFT)
+#define OBJ_INDEX_BITS	(BITS_PER_LONG - _PFN_BITS)
+#define OBJ_INDEX_MASK	((_AC(1, UL) << OBJ_INDEX_BITS) - 1)
+
 /* ZS_MIN_ALLOC_SIZE must be multiple of ZS_ALIGN */
 #define ZS_MIN_ALLOC_SIZE	32
 #define ZS_MAX_ALLOC_SIZE	PAGE_SIZE
Signature · 8 lines
1.7.5.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#5 lore raw

PATCH 5/5 staging: zsmalloc: remove SPARSEMEM dep from Kconfig

In reply to Seth Jennings

This patch removes the SPARSEMEM from the zsmalloc Kconfig

---
 drivers/staging/zsmalloc/Kconfig |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/staging/zsmalloc/Kconfig +1 -1
index 8e2c6a0..a5ab720 100644
@@ -3,7 +3,7 @@ config ZSMALLOC
 	# X86 dependency is because of the use of __flush_tlb_one and set_pte
 	# in zsmalloc-main.c.
 	# TODO: convert these to portable functions
-	depends on SPARSEMEM && X86
+	depends on X86
 	default n
 	help
 	  zsmalloc is a slab-based memory allocator designed to store
Signature · 1 line
1.7.5.4
#2 lore raw

PATCH 2/5 staging: zsmalloc: add ZS_MAX_PAGES_PER_ZSPAGE

In reply to Seth Jennings

This patch moves where max_zspage_order is declared and changes its meaning. "Order" typically implies 2^order
of something; however, it is currently being used as the "maximum number of single pages in a zspage". To add clarity, ZS_MAX_ZSPAGE_ORDER is now used to calculate ZS_MAX_PAGES_PER_ZSPAGE, which is 2^ZS_MAX_ZSPAGE_ORDER and is the upper bound on the number of pages in a zspage.

---
 drivers/staging/zsmalloc/zsmalloc-main.c |    2 +-
 drivers/staging/zsmalloc/zsmalloc_int.h  |   13 +++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)
drivers/staging/zsmalloc/zsmalloc-main.c +1 -1
index 240bcbf..09caa4f 100644
@@ -186,7 +186,7 @@ static int get_zspage_order(int class_size)
 	/* zspage order which gives maximum used size per KB */
 	int max_usedpc_order = 1;
 
-	for (i = 1; i <= max_zspage_order; i++) {
+	for (i = 1; i <= ZS_MAX_PAGES_PER_ZSPAGE; i++) {
 		int zspage_size;
 		int waste, usedpc;
 
drivers/staging/zsmalloc/zsmalloc_int.h +7 -6
index e06e142..4d66d2d 100644
@@ -26,6 +26,13 @@
 #define ZS_ALIGN		8
 
 /*
+ * A single 'zspage' is composed of up to 2^N discontiguous 0-order (single)
+ * pages. ZS_MAX_ZSPAGE_ORDER defines upper limit on N.
+ */
+#define ZS_MAX_ZSPAGE_ORDER 2
+#define ZS_MAX_PAGES_PER_ZSPAGE (_AC(1, UL) << ZS_MAX_ZSPAGE_ORDER)
+
+/*
  * Object location (<PFN>, <obj_idx>) is encoded as
  * as single (void *) handle value.
  *
@@ -59,12 +66,6 @@
 					ZS_SIZE_CLASS_DELTA + 1)
 
 /*
- * A single 'zspage' is composed of N discontiguous 0-order (single) pages.
- * This defines upper limit on N.
- */
-static const int max_zspage_order = 4;
-
-/*
  * We do not maintain any list for completely empty or full pages
  */
 enum fullness_group {
Signature · 8 lines
1.7.5.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#4 lore raw

PATCH 4/5 staging: zsmalloc: change ZS_MIN_ALLOC_SIZE

In reply to Seth Jennings

This patch ensures that the value of ZS_MIN_ALLOC_SIZE, for the PAGE_SIZE and MAX_PHYSMEM_BITS on the system, allows for all possible object ids in the lowest storage class to be encoded in the object handle.

---
 drivers/staging/zsmalloc/zsmalloc_int.h |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/staging/zsmalloc/zsmalloc_int.h +3 -1
index ffb272f..92eefc6 100644
@@ -58,8 +58,10 @@
 #define OBJ_INDEX_BITS	(BITS_PER_LONG - _PFN_BITS)
 #define OBJ_INDEX_MASK	((_AC(1, UL) << OBJ_INDEX_BITS) - 1)
 
+#define MAX(a, b) ((a) >= (b) ? (a) : (b))
 /* ZS_MIN_ALLOC_SIZE must be multiple of ZS_ALIGN */
-#define ZS_MIN_ALLOC_SIZE	32
+#define ZS_MIN_ALLOC_SIZE \
+	MAX(32, (ZS_MAX_PAGES_PER_ZSPAGE << PAGE_SHIFT >> OBJ_INDEX_BITS))
 #define ZS_MAX_ALLOC_SIZE	PAGE_SIZE
 
 /*
Signature · 8 lines
1.7.5.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#0 lore raw

cover staging: zsmalloc: remove SPARSEMEM dependency

This patch series removes the dependency zsmalloc has on SPARSEMEM; more specifically the assumption that MAX_PHYSMEM_BITS is defined.

Based on greg/staging-next.

Seth Jennings (5):
staging: zsmalloc: move object/handle masking defines
staging: zsmalloc: add ZS_MAX_PAGES_PER_ZSPAGE
staging: zsmalloc: calculate MAX_PHYSMEM_BITS if not defined
staging: zsmalloc: change ZS_MIN_ALLOC_SIZE
staging: zsmalloc: remove SPARSEMEM dep from Kconfig

 drivers/staging/zsmalloc/Kconfig         |    2 +-
 drivers/staging/zsmalloc/zsmalloc-main.c |   14 +---------
 drivers/staging/zsmalloc/zsmalloc_int.h  |   43 +++++++++++++++++++++++++-----
 3 files changed, 38 insertions(+), 21 deletions(-)
Signature · 8 lines
1.7.5.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by on the v1 series
#6 lore raw
Quoted 12 lines · Seth Jennings

This patch series removes the dependency zsmalloc has on SPARSEMEM; more specifically the assumption that MAX_PHYSMEM_BITS is defined.

Based on greg/staging-next.

Seth Jennings (5):
staging: zsmalloc: move object/handle masking defines
staging: zsmalloc: add ZS_MAX_PAGES_PER_ZSPAGE
staging: zsmalloc: calculate MAX_PHYSMEM_BITS if not defined
staging: zsmalloc: change ZS_MIN_ALLOC_SIZE
staging: zsmalloc: remove SPARSEMEM dep from Kconfig

Quoted 5 lines
 drivers/staging/zsmalloc/Kconfig         |    2 +-
 drivers/staging/zsmalloc/zsmalloc-main.c |   14 +---------
 drivers/staging/zsmalloc/zsmalloc_int.h  |   43 +++++++++++++++++++++++++-----
 3 files changed, 38 insertions(+), 21 deletions(-)

For the entire series:

Thanks for the fixes.
Nitin

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>