Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758768AbcJRHpQ (ORCPT ); Tue, 18 Oct 2016 03:45:16 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:4017 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757561AbcJRHpK (ORCPT ); Tue, 18 Oct 2016 03:45:10 -0400 From: zhongjiang To: , , CC: , , Subject: [PATCH] z3fold: limit first_num to the actual range of possible buddy indexes Date: Tue, 18 Oct 2016 15:42:49 +0800 Message-ID: <1476776569-29504-1-git-send-email-zhongjiang@huawei.com> X-Mailer: git-send-email 1.7.12.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.102.37] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: zhong jiang 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. Suggested-by: Dan Streetman Signed-off-by: zhong jiang --- mm/z3fold.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mm/z3fold.c b/mm/z3fold.c index 8f9e89c..207e5dd 100644 --- a/mm/z3fold.c +++ b/mm/z3fold.c @@ -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); -- 1.8.3.1