From patchwork Sat Apr 11 22:03:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 11484249 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A7A7214DD for ; Sat, 11 Apr 2020 22:04:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6A70A21D79 for ; Sat, 11 Apr 2020 22:04:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c4MHe/3V" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6A70A21D79 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B58B68E00B8; Sat, 11 Apr 2020 18:04:29 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A96618E0007; Sat, 11 Apr 2020 18:04:29 -0400 (EDT) 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 90C028E00B8; Sat, 11 Apr 2020 18:04:29 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0224.hostedemail.com [216.40.44.224]) by kanga.kvack.org (Postfix) with ESMTP id 7A5BE8E0007 for ; Sat, 11 Apr 2020 18:04:29 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 3E484180AD801 for ; Sat, 11 Apr 2020 22:04:29 +0000 (UTC) X-FDA: 76696953858.18.actor39_6156cc7bf8959 X-Spam-Summary: 2,0,0,d3306a73b8cd45a9,d41d8cd98f00b204,richard.weiyang@gmail.com,,RULES_HIT:41:69:355:379:541:800:960:965:966:968:973:988:989:1260:1345:1359:1437:1535:1542:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:3138:3139:3140:3141:3142:3353:3865:3867:3868:3870:3872:4321:4385:4390:4395:5007:6261:6653:7514:8957:9413:9592:10004:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12683:12895:13255:14093:14096:14110:14181:14687:14721:21080:21222:21444:21451:21627:21666:21990:30012:30054:30070,0,RBL:209.85.128.68:@gmail.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: actor39_6156cc7bf8959 X-Filterd-Recvd-Size: 5459 Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by imf35.hostedemail.com (Postfix) with ESMTP for ; Sat, 11 Apr 2020 22:04:28 +0000 (UTC) Received: by mail-wm1-f68.google.com with SMTP id f20so6217306wmh.3 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=eP/9OeUKXYqsbNU/rm+5ueiGqVKpFM1FXG8eVt7soJRL8GBbpdU34y7C10QDcxjFoa vPDzaJSYKeevqARnPjlj/nNI7Iah6MpI61vcR+C0PZk9aErPRIU5fqhqfB7ZkIGFRf+s x2a8DJ4fv80t6YoC/a7ryP13Mx0psfQFsSCCmMGblDBNCuNfCPuIvjcPbVrkcaelMPoR kl7Tf9jFjKmdK5f5+IfipR6qSmIGZ7WwIlNUVMkHkycyDfgtn3EGEdc9uM2ntaw+2KlL /alGfS8gj7zO4wW6M7flfSH99BW8JtY77bXjZ+Y5VBYArnZDsdzKkQYeA5EUDT7AXl/A Jcnw== X-Gm-Message-State: AGi0PuZtfuvCS0oViJWoZdfuWS0Zvwja2BhYdA6ngngX15L5awCGcqZE hAWrlAYYMpRAevSstT6FG6r+wB70Pfg= X-Google-Smtp-Source: APiQypI222TDc/7riljzEcTyOWrUzl0NTTCsUhqcsSQ2EykVwBQyMmHvavDx9bauT0zEG/6MNvtgYA== 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> 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: 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)); } /*