From patchwork Tue Dec 11 06:11:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 10723119 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DD4E515A6 for ; Tue, 11 Dec 2018 06:12:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB1832A4D1 for ; Tue, 11 Dec 2018 06:12:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDE442A7D5; Tue, 11 Dec 2018 06:12:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 040EB2A4D1 for ; Tue, 11 Dec 2018 06:12:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E3F508E0057; Tue, 11 Dec 2018 01:12:13 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DEF1B8E004D; Tue, 11 Dec 2018 01:12:13 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D05FB8E0057; Tue, 11 Dec 2018 01:12:13 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by kanga.kvack.org (Postfix) with ESMTP id 8E1AB8E004D for ; Tue, 11 Dec 2018 01:12:13 -0500 (EST) Received: by mail-pl1-f200.google.com with SMTP id v11so9934618ply.4 for ; Mon, 10 Dec 2018 22:12:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id; bh=qg8hRWgdSTYO3H1TNp08JNHt12qVCyJ8eOXPaeNBZrU=; b=bgbb9ywJr75f4bb/fCWoC52d1U0JucMWIlJCYYUNehmW6aNofKMermXBRumDI/Gl4z LeAwhGGpTCRGE3K5pWOSPmomoWFXEQqVNgGhjI9khKcsXYSEWEXPkQMU2gHfq9zh4Jb4 IrPrES34dIV0Bppk6HdIgJhOUWMIcmNhCOADXZM7nBQR42t3lcjzFrU9Ym0dcXsLxHnE hMS4cNAMDKHtt/UJ66fCzJBgUEyM7Vs48Oz119v9PqPDNVGNZ+lWuURg2+aawR5dodBb mNAkJohoykLnRlVfz9u18MG4t+rnf1ecGCarNsZ9INyQnXH1OPKhJvVCyZMHigLUrQse CcXA== X-Gm-Message-State: AA+aEWbO2eEGVD9aVBYWDd6/b8pPoUjyih/h9YZsW7TnTaq51rbYnrDb nqTb0HuU0bQrGcFzu4b7gnj5LgXuozxEJXWHqZUYRoUBWQWMTjWJWB9/qlZLcVpmHcnNWdRiMBM Qb7TZvr06l/4GtLgUpYBLBPkIiegFKJcDLBdSJTnCDQ9OUcrptFnb4AxDRI/ZItaEEKoqw8uY1H TpspMHl8v+Xa8wpH5vVvHOHPx0tBmto3oTV19w9I+5dnyz1DqeZpghyETOcZPGj3ske+seopk+2 3yxVG1Trme8LxbesC3szZpQbpPGZSCB7/pr4uzPyZPYzJ2JCBirpWsNMKA/y6RF0hPhviOvumph h+AeLQsOR+WgSq4BB117i9OJj0ak2VJ/gVktDWETdV7oSm18vcRa5brHeqGuusAVh0ZqUIOFkC3 A X-Received: by 2002:a63:2946:: with SMTP id p67mr13738255pgp.317.1544508732992; Mon, 10 Dec 2018 22:12:12 -0800 (PST) X-Received: by 2002:a63:2946:: with SMTP id p67mr13738217pgp.317.1544508731674; Mon, 10 Dec 2018 22:12:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544508731; cv=none; d=google.com; s=arc-20160816; b=hxLQql85BScvy3YXWmoPqGYubq6fi8op6WNP1aHgXKQ/OSNtT0UoqHHf6je0t37/uS jskw5W3cwd9FE87iSrIHYdvpP7xEMfG7ZFRzLJ7ekI9/KLgVJWQLQvi77w55Akjcswy2 kq9cYP8y9a2gtyeA0He4ys7KJL+XWpK2krjFxaEuXHe48oY+U+J+CwOLXAZR0BQbtvii 5A0hipVqy9gmDsx5E3pNfIvFQxl+CbsB8o/zud/q9soIqtccO8/qN1mrwxHE4HlxGZTx BC2HW2U9DQ1lYM+8hLAP47Uy+9CPNHC6NMALVaZQLx8c000lfveZt9d/6wc7Rg7i01LQ 6D7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=qg8hRWgdSTYO3H1TNp08JNHt12qVCyJ8eOXPaeNBZrU=; b=pO9jzXH9fpGQQK48u3wHlqjZS6mw9y29+JvFlySAuOX3qo66tqXO+4SdCPmgifGmP0 2PA+Wbb4+maUh2ZfLrLjrOaHUUHD3PxXK2nTxc7JBrkXoS4wNUiId3GZb4bdTH7MeD6j 9V5aEb+WAyiWnSj1iXqyVuGky7KACS5wcy5P/q5LjO9Y4qzfHVcHfvQdtBJR5k8TJXc0 J5BIARYltUsBTKLZAHfEjNh5FIsDZNKDGH9itESjnML5gSAozzS4LBorYDR4HTYKAVHC CWB0eHtaAyosrGa3hAxk8YH0PKCriOgAn8903n5Lx2LNqhflmMV9HVgCJg/pnHWL7TqB FeDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WxL0fMyh; spf=pass (google.com: domain of kernelfans@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=kernelfans@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id d4sor19296713pls.69.2018.12.10.22.12.11 for (Google Transport Security); Mon, 10 Dec 2018 22:12:11 -0800 (PST) Received-SPF: pass (google.com: domain of kernelfans@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WxL0fMyh; spf=pass (google.com: domain of kernelfans@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=kernelfans@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=qg8hRWgdSTYO3H1TNp08JNHt12qVCyJ8eOXPaeNBZrU=; b=WxL0fMyhc2/Qq0IaIH7xIn95IF5mE2Bp//YduwX6Yl2VR5xcEnXK/2GOQeUBKh0Toh MLQtS1yVx3QiqU+YfZ9cX4m9R8hoi3q7WKi97wK0iUPaUT4zA8r9bebdLmBUf66Dpq7q 8TQ1SaY1h3ux8gt6CmtiVa9490gO33XPWcMeemtNp6N0bkVJ653mA7wOo7UUSpuyVytk 67NoCLXynVpJg1ZzaI4D6xEyu5MTZnxEOKKhDUJAXj0YRlr1vZQ0INxPY0Sn8Iwwr3TO JMKZt5NFpIVzrjh6IjljstBgxBCKx0ukiOmhAW/2skQDohccfaK/8lKvxfPsgWOtQioc AOTg== X-Google-Smtp-Source: AFSGD/XoCG2XLUdeyK/19lBI8WaNoEMEQlYCTJYrSojdk9gfbXHF0uQpGyBAIoCLXz+3wNZ/lsLVbg== X-Received: by 2002:a17:902:2dc3:: with SMTP id p61mr14533193plb.166.1544508731038; Mon, 10 Dec 2018 22:12:11 -0800 (PST) Received: from mylaptop.pek2.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id o66sm50572464pgo.75.2018.12.10.22.12.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Dec 2018 22:12:10 -0800 (PST) From: Pingfan Liu To: linux-mm@kvack.org Cc: Pingfan Liu , Andrew Morton , Michal Hocko , Pavel Tatashin , Vlastimil Babka , Oscar Salvador , Mike Rapoport , Joonsoo Kim , Alexander Duyck Subject: [PATCHv3] mm/pageblock: throw compiling time error if pageblock_bits can not hold MIGRATE_TYPES Date: Tue, 11 Dec 2018 14:11:49 +0800 Message-Id: <1544508709-11358-1-git-send-email-kernelfans@gmail.com> X-Mailer: git-send-email 2.7.4 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Currently, NR_PAGEBLOCK_BITS and MIGRATE_TYPES are not associated by code. If someone adds extra migrate type, then he may forget to enlarge the NR_PAGEBLOCK_BITS. Hence it requires some way to fix. NR_PAGEBLOCK_BITS depends on MIGRATE_TYPES, while these macro spread on two different .h file with reverse dependency, it is a little hard to refer to MIGRATE_TYPES in pageblock-flag.h. This patch tries to remind such relation in compiling-time. Signed-off-by: Pingfan Liu Cc: Andrew Morton Cc: Michal Hocko Cc: Pavel Tatashin Cc: Vlastimil Babka Cc: Oscar Salvador Cc: Mike Rapoport Cc: Joonsoo Kim Cc: Alexander Duyck Acked-by: Vlastimil Babka --- v2->v3: using '>' instead of "==" option since NR_PAGEBLOCK_BITS allows wasted bits include/linux/pageblock-flags.h | 3 ++- mm/page_alloc.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/linux/pageblock-flags.h b/include/linux/pageblock-flags.h index 9132c5c..06a6632 100644 --- a/include/linux/pageblock-flags.h +++ b/include/linux/pageblock-flags.h @@ -25,10 +25,11 @@ #include +#define PB_migratetype_bits 3 /* Bit indices that affect a whole block of pages */ enum pageblock_bits { PB_migrate, - PB_migrate_end = PB_migrate + 3 - 1, + PB_migrate_end = PB_migrate + PB_migratetype_bits - 1, /* 3 bits required for migrate types */ PB_migrate_skip,/* If set the block is skipped by compaction */ diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 2ec9cc4..29ee87e 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -426,6 +426,7 @@ void set_pfnblock_flags_mask(struct page *page, unsigned long flags, unsigned long old_word, word; BUILD_BUG_ON(NR_PAGEBLOCK_BITS != 4); + BUILD_BUG_ON(MIGRATE_TYPES > (1 << PB_migratetype_bits)); bitmap = get_pageblock_bitmap(page, pfn); bitidx = pfn_to_bitidx(page, pfn);