Skip to content

Commit f201ebd

Browse files
xiongzhongjiangtorvalds
authored andcommitted
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/[email protected] Signed-off-by: zhong jiang <[email protected]> Suggested-by: Dan Streetman <[email protected]> Acked-by: Dan Streetman <[email protected]> Acked-by: Vitaly Wool <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 083fb8e commit f201ebd

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

mm/z3fold.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#define ZHDR_SIZE_ALIGNED CHUNK_SIZE
5151
#define NCHUNKS ((PAGE_SIZE - ZHDR_SIZE_ALIGNED) >> CHUNK_SHIFT)
5252

53-
#define BUDDY_MASK ((1 << NCHUNKS_ORDER) - 1)
53+
#define BUDDY_MASK (0x3)
5454

5555
struct z3fold_pool;
5656
struct z3fold_ops {
@@ -109,7 +109,7 @@ struct z3fold_header {
109109
unsigned short middle_chunks;
110110
unsigned short last_chunks;
111111
unsigned short start_middle;
112-
unsigned short first_num:NCHUNKS_ORDER;
112+
unsigned short first_num:2;
113113
};
114114

115115
/*
@@ -179,7 +179,11 @@ static struct z3fold_header *handle_to_z3fold_header(unsigned long handle)
179179
return (struct z3fold_header *)(handle & PAGE_MASK);
180180
}
181181

182-
/* Returns buddy number */
182+
/*
183+
* (handle & BUDDY_MASK) < zhdr->first_num is possible in encode_handle
184+
* but that doesn't matter. because the masking will result in the
185+
* correct buddy number.
186+
*/
183187
static enum buddy handle_to_buddy(unsigned long handle)
184188
{
185189
struct z3fold_header *zhdr = handle_to_z3fold_header(handle);

0 commit comments

Comments
 (0)