Commit f201ebd8 authored by zhong jiang's avatar zhong jiang Committed by Linus Torvalds

mm/z3fold.c: limit first_num to the actual range of possible buddy indexes

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 limits the first_num to actual range of possible buddy indexes.
and that is more reasonable and obvious without functional change.

Link: http://lkml.kernel.org/r/1476776569-29504-1-git-send-email-zhongjiang@huawei.comSigned-off-by: default avatarzhong jiang <zhongjiang@huawei.com>
Suggested-by: default avatarDan Streetman <ddstreet@ieee.org>
Acked-by: default avatarDan Streetman <ddstreet@ieee.org>
Acked-by: default avatarVitaly Wool <vitalywool@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 083fb8ed
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
#define ZHDR_SIZE_ALIGNED CHUNK_SIZE #define ZHDR_SIZE_ALIGNED CHUNK_SIZE
#define NCHUNKS ((PAGE_SIZE - ZHDR_SIZE_ALIGNED) >> CHUNK_SHIFT) #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_pool;
struct z3fold_ops { struct z3fold_ops {
...@@ -109,7 +109,7 @@ struct z3fold_header { ...@@ -109,7 +109,7 @@ struct z3fold_header {
unsigned short middle_chunks; unsigned short middle_chunks;
unsigned short last_chunks; unsigned short last_chunks;
unsigned short start_middle; 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) ...@@ -179,7 +179,11 @@ static struct z3fold_header *handle_to_z3fold_header(unsigned long handle)
return (struct z3fold_header *)(handle & PAGE_MASK); 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) static enum buddy handle_to_buddy(unsigned long handle)
{ {
struct z3fold_header *zhdr = handle_to_z3fold_header(handle); struct z3fold_header *zhdr = handle_to_z3fold_header(handle);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment