From patchwork Fri Feb 26 09:17:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 12106191 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1DF8C433E6 for ; Fri, 26 Feb 2021 09:17:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3406964EE7 for ; Fri, 26 Feb 2021 09:17:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3406964EE7 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AFE716B0072; Fri, 26 Feb 2021 04:17:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AD2C78D0002; Fri, 26 Feb 2021 04:17:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C18F8D0001; Fri, 26 Feb 2021 04:17:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0181.hostedemail.com [216.40.44.181]) by kanga.kvack.org (Postfix) with ESMTP id 862476B0072 for ; Fri, 26 Feb 2021 04:17:39 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 4CFAF183605FF for ; Fri, 26 Feb 2021 09:17:39 +0000 (UTC) X-FDA: 77859866238.15.B5F3BD3 Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) by imf22.hostedemail.com (Postfix) with ESMTP id 49CAAC0007CE for ; Fri, 26 Feb 2021 09:17:35 +0000 (UTC) Received: by mail-qt1-f202.google.com with SMTP id d10so6123907qtx.8 for ; Fri, 26 Feb 2021 01:17:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=0x/I6VizqDyhm0WRlAzYBf6vGqHgQIhvNWl/lQMoOjU=; b=ufifuNchyUu2Nt42yOFNtvE/0fxr6qejoIo4Dev4JvqNYsjyp0xq7qZdQrLXSib3Li SlXaXsyXqwvxynIi718qmiG/z2vXsv+d0yTBbaVvGpvzSXg70ChdMtwM2sJR5AYucgsF QBFvSAWneW8HKhkJBK0wYqaLwHkm0pwr4RTSg7IUnDogznC/HmPLCYeM4g0lb2Jx3jI+ pHoNnLMV0w3KiEjAQ0gj5pMP1TG8Hc0UqODqK2b4Oymszu7WiJWR/NvTvPnf7Dou+PSl M46fxIkgoMQjQbRTIDmyyQvXAnGgh891FKyfxRYZMoKfVV8EMNGllFaiX3SBpQcwF5dR qtXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=0x/I6VizqDyhm0WRlAzYBf6vGqHgQIhvNWl/lQMoOjU=; b=mC1O0f2NBVOMZgjk8NjZJk48/sIy8VDALjjuEUQB+TFX0KKGnibqpijyVV6z2qIpNR SDzvxI0xukhMajtKrP4iakZyH9rvSSKZZVZE/Gzd1J6sP1jGQujhFNhivvJX+ycnPbjc 4PLQ4xM3Rpt7qfIiXQzqLuUSBwjr2RjqQsnnegLqk6jgoT+GudGbOAHMx3zeR6Z82sZp Rf9KJtQLpupq2wNSZeqimsWA0t0a54XSDku0o22rlWYBW9BTqYMc6hryhg1Y2TxAubSo VXw1F2HzDcrwttAaCbU7uSeHdKSg5ryiVb5CNvyQpF8H0nhnv+1WMnthpzqwG4iVeTVc 2GoQ== X-Gm-Message-State: AOAM532dUqwrofATlnEcY2pinwdDqevypL0yKaMQl/MOSFwLLGo7DOH/ AADxH/05wpE2wc69U31b2hK8A4GCuMA= X-Google-Smtp-Source: ABdhPJw/aX/0da6jr3fSWHl1QzaFZ7UomaCtvoWaPyk2ZmV0Zmb1C1s8a8/tVeafRVV6AkPSlq9+KbqfxQ4= X-Received: from yuzhao.bld.corp.google.com ([2620:15c:183:200:69b6:2618:c96a:ceba]) (user=yuzhao job=sendgmr) by 2002:ad4:50c7:: with SMTP id e7mr1843885qvq.58.1614331058054; Fri, 26 Feb 2021 01:17:38 -0800 (PST) Date: Fri, 26 Feb 2021 02:17:16 -0700 In-Reply-To: <20210226091718.2927291-1-yuzhao@google.com> Message-Id: <20210226091718.2927291-2-yuzhao@google.com> Mime-Version: 1.0 References: <20210224084807.2179942-1-yuzhao@google.com> <20210226091718.2927291-1-yuzhao@google.com> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH v2 1/3] mm: bypass compound_head() for PF_NO_TAIL when enforce=1 From: Yu Zhao To: akpm@linux-foundation.org, alex.shi@linux.alibaba.com, vbabka@suse.cz, willy@infradead.org Cc: guro@fb.com, hannes@cmpxchg.org, hughd@google.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhocko@kernel.org, vdavydov.dev@gmail.com, Yu Zhao X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 49CAAC0007CE X-Stat-Signature: 7gqrk6rw7zwgw78ryt181it8r4r651kq Received-SPF: none (flex--yuzhao.bounces.google.com>: No applicable sender policy available) receiver=imf22; identity=mailfrom; envelope-from="<3srw4YAYKCBcLHM4xB3BB381.zB985AHK-997Ixz7.BE3@flex--yuzhao.bounces.google.com>"; helo=mail-qt1-f202.google.com; client-ip=209.85.160.202 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614331055-848099 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: When testing page flags with PF_NO_TAIL (enforce=0), tail pages are legit and they are converted by compound_head(). When modifying page flags (enforce=1), tail pages are not legit and they either trigger VM_BUG_ON_PGFLAGS() or are "corrected" by compound_head(). There is no evidence such "correction" is beneficial in terms of preventing a buggy kernel from crashing. But there is clear evidence it's detrimental to the size of vmlinux because compound_head() is redundantly inlined for all modifications of small and head page flags using PF_NO_TAIL. This patch makes PF_NO_TAIL skip compound_head() when modifying page flags. There won't be any behavior change unless a piece of buggy code tries to modify tail page flags using PF_NO_TAIL. Such code won't be "corrected", if VM_BUG_ON_PGFLAGS() isn't there to catch it. Again, there is no evidence such "correction" is beneficial. bloat-o-meter result: add/remove: 0/0 grow/shrink: 4/62 up/down: 309/-2851 (-2542) Signed-off-by: Yu Zhao --- include/linux/page-flags.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index db914477057b..1995208a3763 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -248,7 +248,7 @@ static inline void page_init_poison(struct page *page, size_t size) PF_POISONED_CHECK(page); }) #define PF_NO_TAIL(page, enforce) ({ \ VM_BUG_ON_PGFLAGS(enforce && PageTail(page), page); \ - PF_POISONED_CHECK(compound_head(page)); }) + PF_POISONED_CHECK((enforce) ? (page) : compound_head(page)); }) #define PF_NO_COMPOUND(page, enforce) ({ \ VM_BUG_ON_PGFLAGS(enforce && PageCompound(page), page); \ PF_POISONED_CHECK(page); })