Skip to content

Commit 43afc19

Browse files
vwooltorvalds
authored andcommitted
mm/z3fold.c: avoid modifying HEADLESS page and minor cleanup
Fix erroneous z3fold header access in a HEADLESS page in reclaim function, and change one remaining direct handle-to-buddy conversion to use the appropriate helper. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Vitaly Wool <[email protected]> Reviewed-by: Dan Streetman <[email protected]> Cc: Seth Jennings <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 3a06bb7 commit 43afc19

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

mm/z3fold.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle)
412412
/* HEADLESS page stored */
413413
bud = HEADLESS;
414414
} else {
415-
bud = (handle - zhdr->first_num) & BUDDY_MASK;
415+
bud = handle_to_buddy(handle);
416416

417417
switch (bud) {
418418
case FIRST:
@@ -572,15 +572,19 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries)
572572
pool->pages_nr--;
573573
spin_unlock(&pool->lock);
574574
return 0;
575-
} else if (zhdr->first_chunks != 0 &&
576-
zhdr->last_chunks != 0 && zhdr->middle_chunks != 0) {
577-
/* Full, add to buddied list */
578-
list_add(&zhdr->buddy, &pool->buddied);
579-
} else if (!test_bit(PAGE_HEADLESS, &page->private)) {
580-
z3fold_compact_page(zhdr);
581-
/* add to unbuddied list */
582-
freechunks = num_free_chunks(zhdr);
583-
list_add(&zhdr->buddy, &pool->unbuddied[freechunks]);
575+
} else if (!test_bit(PAGE_HEADLESS, &page->private)) {
576+
if (zhdr->first_chunks != 0 &&
577+
zhdr->last_chunks != 0 &&
578+
zhdr->middle_chunks != 0) {
579+
/* Full, add to buddied list */
580+
list_add(&zhdr->buddy, &pool->buddied);
581+
} else {
582+
z3fold_compact_page(zhdr);
583+
/* add to unbuddied list */
584+
freechunks = num_free_chunks(zhdr);
585+
list_add(&zhdr->buddy,
586+
&pool->unbuddied[freechunks]);
587+
}
584588
}
585589

586590
/* add to beginning of LRU */

0 commit comments

Comments
 (0)