Skip to contentSkip to conversation

z3fold: limit first_num to the actual range of possible buddy indexes

PATCH Applied zhongjiang 3 participants 3 messages Oct 18, 2016 Memory management

lore
Share & tools
lore

zhongjiang

author
#0 lore raw

PATCH 1/1 z3fold: limit first_num to the actual range of possible buddy indexes

From: zhong jiang <[email protected]>

At present, Tying the first_num size to NCHUNKS_ORDER is confusing. the number of chunks is completely unrelated to the number of buddies.

The patch limit the first_num to actual range of possible buddy indexes. and that is more reasonable and obvious without functional change.

---
 mm/z3fold.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
mm/z3fold.c +7 -3
index 8f9e89c..207e5dd 100644
@@ -50,7 +50,7 @@
 #define ZHDR_SIZE_ALIGNED CHUNK_SIZE
 #define NCHUNKS		((PAGE_SIZE - ZHDR_SIZE_ALIGNED) >> CHUNK_SHIFT)
 
-#define BUDDY_MASK	((1 << NCHUNKS_ORDER) - 1)
+#define BUDDY_MASK	(0x3)
 
 struct z3fold_pool;
 struct z3fold_ops {
@@ -109,7 +109,7 @@ struct z3fold_header {
 	unsigned short middle_chunks;
 	unsigned short last_chunks;
 	unsigned short start_middle;
-	unsigned short first_num:NCHUNKS_ORDER;
+	unsigned short first_num:2;
 };
 
 /*
@@ -179,7 +179,11 @@ static struct z3fold_header *handle_to_z3fold_header(unsigned long handle)
 	return (struct z3fold_header *)(handle & PAGE_MASK);
 }
 
-/* Returns buddy number */
+/*
+ * (handle & BUDDY_MASK) < zhdr->first_num is possible in encode_handle
+ *  but that doesn't matter. because the masking will result in the
+ *  correct buddy number.
+ */
 static enum buddy handle_to_buddy(unsigned long handle)
 {
 	struct z3fold_header *zhdr = handle_to_z3fold_header(handle);
Signature · 1 line
1.8.3.1
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · zhongjiang

From: zhong jiang <[email protected]>

At present, Tying the first_num size to NCHUNKS_ORDER is confusing. the number of chunks is completely unrelated to the number of buddies.

The patch limit the first_num to actual range of possible buddy indexes. and that is more reasonable and obvious without functional change.

Quoted 39 lines

---> mm/z3fold.c | 10 +++++++---

 1 file changed, 7 insertions(+), 3 deletions(-)
mm/z3fold.c +7 -4
index 8f9e89c..207e5dd 100644
@@ -50,7 +50,7 @@
 #define ZHDR_SIZE_ALIGNED CHUNK_SIZE
 #define NCHUNKS                ((PAGE_SIZE - ZHDR_SIZE_ALIGNED) >> CHUNK_SHIFT)
 
-#define BUDDY_MASK     ((1 << NCHUNKS_ORDER) - 1)
+#define BUDDY_MASK     (0x3)
 
 struct z3fold_pool;
 struct z3fold_ops {
@@ -109,7 +109,7 @@ struct z3fold_header {
        unsigned short middle_chunks;
        unsigned short last_chunks;
        unsigned short start_middle;
-       unsigned short first_num:NCHUNKS_ORDER;
+       unsigned short first_num:2;
 };
 
 /*
@@ -179,7 +179,11 @@ static struct z3fold_header *handle_to_z3fold_header(unsigned long handle)
        return (struct z3fold_header *)(handle & PAGE_MASK);
 }
 
-/* Returns buddy number */
+/*
+ * (handle & BUDDY_MASK) < zhdr->first_num is possible in encode_handle
+ *  but that doesn't matter. because the masking will result in the
+ *  correct buddy number.
+ */
 static enum buddy handle_to_buddy(unsigned long handle)
 {
        struct z3fold_header *zhdr = handle_to_z3fold_header(handle);
--
Quoted 2 lines

1.8.3.1

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Acked-by
#2 lore raw
Quoted 6 lines · Dan Streetman
Quoted 5 lines · zhongjiang

From: zhong jiang <[email protected]>

At present, Tying the first_num size to NCHUNKS_ORDER is confusing. the number of chunks is completely unrelated to the number of buddies.

Quoted 7 lines
Quoted 5 lines

The patch limit the first_num to actual range of possible buddy indexes. and that is more reasonable and obvious without functional change.

Quoted 29 lines
Quoted 29 lines

---> mm/z3fold.c | 10 +++++++---

 1 file changed, 7 insertions(+), 3 deletions(-)
mm/z3fold.c +2 -2
index 8f9e89c..207e5dd 100644
@@ -50,7 +50,7 @@
 #define ZHDR_SIZE_ALIGNED CHUNK_SIZE
 #define NCHUNKS                ((PAGE_SIZE - ZHDR_SIZE_ALIGNED) >> CHUNK_SHIFT)
 
-#define BUDDY_MASK     ((1 << NCHUNKS_ORDER) - 1)
+#define BUDDY_MASK     (0x3)
 
 struct z3fold_pool;
 struct z3fold_ops {
@@ -109,7 +109,7 @@ struct z3fold_header {
        unsigned short middle_chunks;
        unsigned short last_chunks;
        unsigned short start_middle;
-       unsigned short first_num:NCHUNKS_ORDER;
+       unsigned short first_num:2;
 };
 
 /*
@@ -179,7 +179,11 @@ static struct z3fold_header *handle_to_z3fold_header(unsigned long handle)
        return (struct z3fold_header *)(handle & PAGE_MASK);
 }
 
Quoted 12 lines
Quoted 10 lines
mm/z3fold.c +5 -2
-/* Returns buddy number */
+/*
+ * (handle & BUDDY_MASK) < zhdr->first_num is possible in encode_handle
+ *  but that doesn't matter. because the masking will result in the
+ *  correct buddy number.
+ */
 static enum buddy handle_to_buddy(unsigned long handle)
 {
        struct z3fold_header *zhdr = handle_to_z3fold_header(handle);
--
Quoted 2 lines

1.8.3.1

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>