From patchwork Mon Mar 13 08:34:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13172066 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B0D9C6FD19 for ; Mon, 13 Mar 2023 08:34:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 81ACD6B0071; Mon, 13 Mar 2023 04:34:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A1B06B0072; Mon, 13 Mar 2023 04:34:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 61ADF6B0074; Mon, 13 Mar 2023 04:34:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4B8586B0071 for ; Mon, 13 Mar 2023 04:34:58 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id F0E111A0A3D for ; Mon, 13 Mar 2023 08:34:57 +0000 (UTC) X-FDA: 80563214634.30.C134462 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) by imf10.hostedemail.com (Postfix) with ESMTP id 3E9B7C0023 for ; Mon, 13 Mar 2023 08:34:56 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=VJLAMhtX; spf=pass (imf10.hostedemail.com: domain of 3LuAOZAoKCFEH7BAHt05xwz77z4x.v75416DG-553Etv3.7Az@flex--yosryahmed.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=3LuAOZAoKCFEH7BAHt05xwz77z4x.v75416DG-553Etv3.7Az@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678696496; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=zeDiTo83CJOPfROIycQGpKJpY/woSMBEn4wJ2l9Oc3A=; b=mR9Q8hiLqb7asXSfRB/eDCubKU6nVekYVZM3EFnl3kP9JNjTKND0q5TOChcynb/RTeThQu XWKZ3P69rvNPXjIayCf8Z9ZwaHW5+fxRSDWoorHun/U3J4ND0H3/1BhCIRAi0J96phDSwa G6sqwy0pcujEzZX1nAeZ94clFyaaoMM= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=VJLAMhtX; spf=pass (imf10.hostedemail.com: domain of 3LuAOZAoKCFEH7BAHt05xwz77z4x.v75416DG-553Etv3.7Az@flex--yosryahmed.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=3LuAOZAoKCFEH7BAHt05xwz77z4x.v75416DG-553Etv3.7Az@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678696496; a=rsa-sha256; cv=none; b=nvcl0pGe3M+RofBffzosCMJgQ6WkBFjn+YhWB7kGvvGt1VK+b7PztG7E+aJ3JF9rYCqDRS Y9vzRIHrXWoumSFN9UIfRV94yJQlrtsJ8c74w34rZiUTMi712v1XtTEIBv2wg0vyjd6zA1 iLdeHESUee1WirmQbM8GUY517BCCTIY= Received: by mail-pj1-f74.google.com with SMTP id q61-20020a17090a1b4300b00237d2fb8400so6890952pjq.0 for ; Mon, 13 Mar 2023 01:34:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678696495; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=zeDiTo83CJOPfROIycQGpKJpY/woSMBEn4wJ2l9Oc3A=; b=VJLAMhtXlqTwGgXDKCTVn6HNH8J7Yb49JpBXa71bKEU+b8UV7Pfw4XnV3NJlgObfWR dsMVPpiYzyL+5/bmZeKIlzocq5lZDLUEIdEzYQ+l+SjF9mGT9Pqh276648bG03w2Bf4L zwYel8rQA26f0lY3rYcJALEiOuEu8HsNuNgUPyCu7rrMjImD34V9QNoVfiGc4Pn4ZgnY BHyEoGPJcoEqbfOwQd0dGFuvXoVeikT40ffzVLYSDDPFqOOfwnu2rb9l7QedPR2tVVK9 JpY7HwxqXLi30xpw6Hyawjr8gHfVwVGmTu5K+o7/00SdSoYGb9i2i2o+s3cx6qjv9IAS Xcfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678696495; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=zeDiTo83CJOPfROIycQGpKJpY/woSMBEn4wJ2l9Oc3A=; b=HoX7a129Qef7TmvECp9qywmpi9qxii9lcDmuQHKXpzOv7N6X2LPcgRVHCKew/HGvbz ub/MUj2S+3AlBfUD9UUVb33IerlcwerCCzvcQKjENeEjSUEy5ZPDx1hjeVDZ7qE3rzaY RS/agGOP19E71TXKIoNBDYXWt0878XJv5XkqNaQzbek8QbV+B8ijRdSlafTVk4UjsZWs QxOm3vJjsiSQSFK7M7Av20IpGILbrOOVylKBwYt0l2jMxSQfEciX4uZmIgn6AXqaTYlU kW9NeFbqscfawnE9YYtkNHSdI4J9CkyXWhE4cZrRiQo85HNweYY3TMEm0HGgMx3Eylv/ 9ZyQ== X-Gm-Message-State: AO0yUKWfkDSGO477bzE13azMHYBXO35FtPfwzkkFLZvaf4wZ8xmMaoXw ST1ZEy/PEqYK5mdJHgfnAm/JOpS/23aCIf0N X-Google-Smtp-Source: AK7set9OUIQAsvRTAEvPqTliBW1Ilddgmbr1TQ3J16ta65gCass7E536/3xMeEut+bm9A05Eebs7dxH2HOAPck4r X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a62:8484:0:b0:5a9:d579:6902 with SMTP id k126-20020a628484000000b005a9d5796902mr3305591pfd.0.1678696494930; Mon, 13 Mar 2023 01:34:54 -0700 (PDT) Date: Mon, 13 Mar 2023 08:34:52 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog Message-ID: <20230313083452.1319968-1-yosryahmed@google.com> Subject: [PATCH] memcg: page_cgroup_ino() get memcg from compound_head(page) From: Yosry Ahmed To: Hugh Dickins , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , Naoya Horiguchi , Miaohe Lin , Vladimir Davydov Cc: linux-mm@kvack.org, cgroups@vger.kernel.org, Yosry Ahmed X-Rspamd-Queue-Id: 3E9B7C0023 X-Stat-Signature: na7553akztoopyoxow345u1iccf4sk7w X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1678696496-712877 X-HE-Meta: U2FsdGVkX19E73K5RXzUmeCp4gTPNIpso+5Ot448Z2T/RjPwgsv+zBHJxrY5s7CSUv/Z10zj02CzBWK3xd3+SVNtkivnZC9iZyJWMfOw6Wn7JB93RsiAQWkxNkksFkoAJPxerxRZKKeF06lZMbU6Y4dRUt0nmzkkeKPZGIwbDi9vVvKgImuMUQGuOdQqhsWyXJ9ZFdY+LOc5lTezFCMj6iesamCzS3DBgr/Fs/EJiAIBu3xszrdx9wMT4Sa/aXuG7rIeruWKV5zXdyYCSS2O73bZVMI27Rxa/ZEIgx8T7wqua+QAQG2/zDrEMYFfTiGMerjWhiw4+fIpT4syxpbse1g7ObqjzCGflGnBKuDxFwxruUCC+G+GlPelJy3ws/9xxYnpZ+fm2t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YvketsSF8xOWeoB/bbKMWz2T4TVdvsrlMS37ZAVj7JqXipiLPMi8zOp0MlgLjtoKKCDNVfiGiVrMU+ffnTLi7F+lfs5EG2D2f5gjYc95kVzQpwnQPbrg03/AGKmMN61kf2xEkhg6knhE2cQk1+u/9n9OtYBlCbd0nBIt3H6TTrD6eamZvN9rBLJgsUS+emoEP6wynuxvZv0FZHWTjGgCnW36kGDmzfyHW5jWhz9xtO9Hh/Q2lylJc4m7esTXKGmYSO0gq/gasUJ2+ZaA5z3L3XWnRUmDKCkoSW4Cr/dN63ELg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000022, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Hugh Dickins In a kernel with added WARN_ON_ONCE(PageTail) in page_memcg_check(), we observed a warning from page_cgroup_ino() when reading /proc/kpagecgroup. This warning was added to catch fragile reads of a page memcg. Make page_cgroup_ino() get memcg from compound_head(page): that gives it the correct memcg for each subpage of a compound page, so is the right fix. I dithered between the right fix and the safer "fix": it's unlikely but conceivable that some userspace has learnt that /proc/kpagecgroup gives no memcg on tail pages, and compensates for that in some (racy) way: so continuing to give no memcg on tails, without warning, might be safer. But hwpoison_filter_task(), the only other user of page_cgroup_ino(), persuaded me. It looks as if it currently leaves out tail pages of the selected memcg, by mistake: whereas hwpoison_inject() uses compound_head() and expects the tails to be included. So hwpoison testing coverage has probably been restricted by the wrong output from page_cgroup_ino() (if that memcg filter is used at all): in the short term, it might be safer not to enable wider coverage there, but long term we would regret that. Signed-off-by: Hugh Dickins Signed-off-by: Yosry Ahmed Acked-by: Michal Hocko Acked-by: Roman Gushchin . --- (Yosry: Alternatively, we could modify page_memcg_check() to do page_folio() like its sibling page_memcg(), as page_cgroup_ino() is the only remaining caller other than print_page_owner_memcg(); and it already excludes pages that have page->memcg_data = 0) --- mm/memcontrol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 5abffe6f8389..e3a55295725e 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -395,7 +395,7 @@ ino_t page_cgroup_ino(struct page *page) unsigned long ino = 0; rcu_read_lock(); - memcg = page_memcg_check(page); + memcg = page_memcg_check(compound_head(page)); while (memcg && !(memcg->css.flags & CSS_ONLINE)) memcg = parent_mem_cgroup(memcg);