Skip to content

Commit 1b096e5

Browse files
vwooltorvalds
authored andcommitted
z3fold: extend compaction function
z3fold_compact_page() currently only handles the situation when there's a single middle chunk within the z3fold page. However it may be worth it to move middle chunk closer to either first or last chunk, whichever is there, if the gap between them is big enough. This patch adds the relevant code, using BIG_CHUNK_GAP define as a threshold for middle chunk to be worth moving. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Vitaly Wool <[email protected]> Reviewed-by: Dan Streetman <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent ede9321 commit 1b096e5

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

mm/z3fold.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ static inline void *mchunk_memmove(struct z3fold_header *zhdr,
268268
zhdr->middle_chunks << CHUNK_SHIFT);
269269
}
270270

271+
#define BIG_CHUNK_GAP 3
271272
/* Has to be called with lock held */
272273
static int z3fold_compact_page(struct z3fold_header *zhdr)
273274
{
@@ -286,8 +287,31 @@ static int z3fold_compact_page(struct z3fold_header *zhdr)
286287
zhdr->middle_chunks = 0;
287288
zhdr->start_middle = 0;
288289
zhdr->first_num++;
290+
return 1;
289291
}
290-
return 1;
292+
293+
/*
294+
* moving data is expensive, so let's only do that if
295+
* there's substantial gain (at least BIG_CHUNK_GAP chunks)
296+
*/
297+
if (zhdr->first_chunks != 0 && zhdr->last_chunks == 0 &&
298+
zhdr->start_middle - (zhdr->first_chunks + ZHDR_CHUNKS) >=
299+
BIG_CHUNK_GAP) {
300+
mchunk_memmove(zhdr, zhdr->first_chunks + ZHDR_CHUNKS);
301+
zhdr->start_middle = zhdr->first_chunks + ZHDR_CHUNKS;
302+
return 1;
303+
} else if (zhdr->last_chunks != 0 && zhdr->first_chunks == 0 &&
304+
TOTAL_CHUNKS - (zhdr->last_chunks + zhdr->start_middle
305+
+ zhdr->middle_chunks) >=
306+
BIG_CHUNK_GAP) {
307+
unsigned short new_start = TOTAL_CHUNKS - zhdr->last_chunks -
308+
zhdr->middle_chunks;
309+
mchunk_memmove(zhdr, new_start);
310+
zhdr->start_middle = new_start;
311+
return 1;
312+
}
313+
314+
return 0;
291315
}
292316

293317
/**

0 commit comments

Comments
 (0)