Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1906821ybb; Sat, 11 Apr 2020 15:06:40 -0700 (PDT) X-Google-Smtp-Source: APiQypKu25RGYLu9P9eex6G7zycpwppBMT8Uv0v74tylsNzaPPuvomAH/HH6GP2Jlb3AFbeMac6A X-Received: by 2002:aed:2142:: with SMTP id 60mr5263995qtc.177.1586642800051; Sat, 11 Apr 2020 15:06:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586642800; cv=none; d=google.com; s=arc-20160816; b=v8Rx2zapixdk4SBJU8ECUf9FyqakfU3Z/Q5RPXTlYYCmWzlNQJjAC5jc1n6YyzaVwF F6p18FKPsaoh0B7A3ZbUEQXReukxWOWPVWDXj+/uMslmVZYb5v1/EvKFaT/vMBJppD0s Zq5BpjxfrALhXERvbzHuvzkoFJW9InLYaeyLkr0reOuCrIR0/Z86tAf479TetA24Kzd5 SHuR5iy4jprgyb30BP4KWGchr8lh6GM9An5e9adwQs9/mHUdBGftp5okIK7G6oR3gOyz MgSh67Z5/cf5765DWk6BNQiz9O/fQpxsAIctz+sU4kAEmbFTmmHl9dJ56qdRHeLr4jh7 ppsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=6gEeOq1PpVccr4Ato7Vi1Z7FE4EOOe1QHjHjHnCaqcc=; b=Jfv4YxlgEkTC0j0z4PJQTll3ymVOmHNIAt1jBzSMBUcPS8qvHVBpoFEy8j9/954/W3 Vgr2cptV2WU3EcNlv0C1MLraNbpGolV63nJ0K+Bw61NC5KOmLmaEcmn1CAp+FvX/V8xO Lj7UyLQq+QnoIkomJgcl8wgpmq6GncdxAKf10vF6lNCCa7HdzgvdFccPhu3tmknSNeDP s9/NBXyqM304EKehXqDvKK6/bnzjqrTDjquPp8ePfGQljicpEoUvLR4kGepp64TaRUzb 4z82toZ3ImvEBUpwkzbXHXPnfYO+iXQ1nYljpnwxEa5vXqApthX45VjlPbdoe79zlJxK RvYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="c4MHe/3V"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 4si3730319qkb.260.2020.04.11.15.06.25; Sat, 11 Apr 2020 15:06:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="c4MHe/3V"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726891AbgDKWEi (ORCPT + 99 others); Sat, 11 Apr 2020 18:04:38 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:54443 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726873AbgDKWEf (ORCPT ); Sat, 11 Apr 2020 18:04:35 -0400 Received: by mail-wm1-f67.google.com with SMTP id h2so5879044wmb.4 for ; Sat, 11 Apr 2020 15:04:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6gEeOq1PpVccr4Ato7Vi1Z7FE4EOOe1QHjHjHnCaqcc=; b=c4MHe/3VZ7ToP2vIz7fdoLygs+mLdgRlTe9FV0TZUrGDmeZSSh1eBse+LrunRPTkln 5U4FTU3E7CRl8hU6Rdj53McU49Jo0NeTBmKaySQ+x3bKxMOQzciz7rsBIm9kBIp3yWOb 6CgCv/WRdo0sTnT7/NEcHNc6EQE9zxpPawBXSqjoLOmE/2vnuyjLgomsm2VF6Pc3AXfx 0FwDpAGl0/CzflsTE9JmN6aRrDyylcbbWTe76Nszk2RVBk2pz4Vpd5UKKtw4bRp+PuMa CTs+bo99R/SwsNu4XGOvmgg790dEzsuD+vPr8Vj5joBjiLDSmvyDSFMoRVYf8MiidnGP UeUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6gEeOq1PpVccr4Ato7Vi1Z7FE4EOOe1QHjHjHnCaqcc=; b=YDRkiQz4VmYJyHUY5q1R92Kcb/xB5Tt8AA1O8tEtVd9pqxkUfOFEUHnMuixvSouRuM dnMcVOuwneXNvw/9sL/OHSS1iDpSIXemyP4XO1wpKRYGQxJ+bCyhkoGosRlP7a+TWLXG g/ba80iarKM82aZgc8cEcPwnsb3VPujeB/E8k/FRp90M+DRP/LUMqgsjJ5vmkaRcibNG 7BgAT5623w+DRCKgIAlsqG3plxqNTISxxgf9DjcctkIDkF85JXF7CfwdSu6qczS8HMLm 7/nwivmevJ5w3gjuJ12/iNCYUSXemrDmuKEvC1BFCYZTdLarQLAD7XfrsTSYUOJ7xkYz m1Dw== X-Gm-Message-State: AGi0PuaPEX6Z9BCE51zxYGAp5f01T+JZaicIA27C4VxBzR70XFuhR0M4 0aEqOvkXRiUIzHOY9O0Ynrw= X-Received: by 2002:a1c:1b58:: with SMTP id b85mr10962459wmb.112.1586642667887; Sat, 11 Apr 2020 15:04:27 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id l26sm305258wrb.7.2020.04.11.15.04.27 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 11 Apr 2020 15:04:27 -0700 (PDT) From: Wei Yang To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, rientjes@google.com, anshuman.khandual@arm.com, david@redhat.com, Wei Yang Subject: [Patch v3 5/5] mm/page_alloc.c: extract check_[new|free]_page_bad() common part to page_bad_reason() Date: Sat, 11 Apr 2020 22:03:57 +0000 Message-Id: <20200411220357.9636-6-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200411220357.9636-1-richard.weiyang@gmail.com> References: <20200411220357.9636-1-richard.weiyang@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We share the similar code in check_[new|free]_page_bad() to get the page's bad reason. Let's extract it and reduce code duplication. Signed-off-by: Wei Yang --- mm/page_alloc.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index dfcf2682ed40..c12a5a9b79c8 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1013,7 +1013,7 @@ static inline bool page_expected_state(struct page *page, return true; } -static void check_free_page_bad(struct page *page) +static const char *page_bad_reason(struct page *page, unsigned long flags) { const char *bad_reason = NULL; @@ -1023,13 +1023,23 @@ static void check_free_page_bad(struct page *page) bad_reason = "non-NULL mapping"; if (unlikely(page_ref_count(page) != 0)) bad_reason = "nonzero _refcount"; - if (unlikely(page->flags & PAGE_FLAGS_CHECK_AT_FREE)) - bad_reason = "PAGE_FLAGS_CHECK_AT_FREE flag(s) set"; + if (unlikely(page->flags & flags)) { + if (flags == PAGE_FLAGS_CHECK_AT_PREP) + bad_reason = "PAGE_FLAGS_CHECK_AT_PREP flag(s) set"; + else + bad_reason = "PAGE_FLAGS_CHECK_AT_FREE flag(s) set"; + } #ifdef CONFIG_MEMCG if (unlikely(page->mem_cgroup)) bad_reason = "page still charged to cgroup"; #endif - bad_page(page, bad_reason); + return bad_reason; +} + +static void check_free_page_bad(struct page *page) +{ + bad_page(page, + page_bad_reason(page, PAGE_FLAGS_CHECK_AT_FREE)); } static inline int check_free_page(struct page *page) @@ -2023,26 +2033,14 @@ static inline void expand(struct zone *zone, struct page *page, static void check_new_page_bad(struct page *page) { - const char *bad_reason = NULL; - if (unlikely(page->flags & __PG_HWPOISON)) { /* Don't complain about hwpoisoned pages */ page_mapcount_reset(page); /* remove PageBuddy */ return; } - if (unlikely(atomic_read(&page->_mapcount) != -1)) - bad_reason = "nonzero mapcount"; - if (unlikely(page->mapping != NULL)) - bad_reason = "non-NULL mapping"; - if (unlikely(page_ref_count(page) != 0)) - bad_reason = "nonzero _refcount"; - if (unlikely(page->flags & PAGE_FLAGS_CHECK_AT_PREP)) - bad_reason = "PAGE_FLAGS_CHECK_AT_PREP flag set"; -#ifdef CONFIG_MEMCG - if (unlikely(page->mem_cgroup)) - bad_reason = "page still charged to cgroup"; -#endif - bad_page(page, bad_reason); + + bad_page(page, + page_bad_reason(page, PAGE_FLAGS_CHECK_AT_PREP)); } /* -- 2.23.0