Message ID | 20230412003451.4018887-1-yosryahmed@google.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 41991C76196 for <linux-mm@archiver.kernel.org>; Wed, 12 Apr 2023 00:34:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B4C1E6B0075; Tue, 11 Apr 2023 20:34:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD4D4900003; Tue, 11 Apr 2023 20:34:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 974DE6B007B; Tue, 11 Apr 2023 20:34:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 8488B6B0075 for <linux-mm@kvack.org>; Tue, 11 Apr 2023 20:34:58 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 31A21120DBF for <linux-mm@kvack.org>; Wed, 12 Apr 2023 00:34:58 +0000 (UTC) X-FDA: 80670869076.08.DC3A1B7 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by imf21.hostedemail.com (Postfix) with ESMTP id 83CF91C0014 for <linux-mm@kvack.org>; Wed, 12 Apr 2023 00:34:56 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=DWINJdlL; spf=pass (imf21.hostedemail.com: domain of 3rvw1ZAoKCKcfVZYfHOTLKNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--yosryahmed.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3rvw1ZAoKCKcfVZYfHOTLKNVVNSL.JVTSPUbe-TTRcHJR.VYN@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=1681259696; 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=yIObXy3lJVLQ0GKopS+iRwrSvJGFvWWAFvhX3UspfPI=; b=boj09AjHEgouzhbDbj/rrLx4N+nOtl5HHN6HrKqLsI8QMKQ2/E0XMvLPI89cYlomymBV8P kvuSF41ecdJcNLSPMO0NBoH4ZVevGX1/LcfOx1QiRILBZdAwUwgtcnPhps/gHTbv7NWX/z RS1Zui4LDeVuOAUjNbPpYUVibnDtvEc= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=DWINJdlL; spf=pass (imf21.hostedemail.com: domain of 3rvw1ZAoKCKcfVZYfHOTLKNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--yosryahmed.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3rvw1ZAoKCKcfVZYfHOTLKNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681259696; a=rsa-sha256; cv=none; b=CQOm47wYvXflrpw5Na/AebB4jss/1Vr0OsghbCpu9Rh1pnb70FJo3qd47MNUU6Aklp1UFQ pGoRmgubSvGCgXGjngjPvIyZpzuFDCqyGo+enumWuNFGIMxbilVV/PM0zH0WkTApChs8ej 7I+9yLVPf2xcdG+SUQbZPPa1YdA/fRc= Received: by mail-pg1-f202.google.com with SMTP id x189-20020a6386c6000000b004fc1c14c9daso4273158pgd.23 for <linux-mm@kvack.org>; Tue, 11 Apr 2023 17:34:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681259695; x=1683851695; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=yIObXy3lJVLQ0GKopS+iRwrSvJGFvWWAFvhX3UspfPI=; b=DWINJdlLfA7bsA3GGGY3QqMkyHn4mFlvS/JIo4iW0TMLRVhU/gf7C1saDLJbgiMhyg 1THSZqOvBE7mYalurr5DpB+0FcS448x6UlzZq4LCxUvT+p2BGmyTy5YgE1NSEM0zIhIU 6wS+/+aKooKm7FQuVCzrBtZANDFi3UgfGVf65QRiGlph2U7sNmmMEdxB2T5rc3YOUyH9 a1aiSVB8pFxOvsKL9KHKoN8NmzVNyhvUSpVMDYIvCLA0wxF0ldBH57sG0T1+qRafWsYh RbheDirj59ekdDNu91/r2Fz5vIwhgUWTsLc5GdFJJ3XkuToj6EsUXeRczct0dZdBnYn6 +2ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681259695; x=1683851695; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=yIObXy3lJVLQ0GKopS+iRwrSvJGFvWWAFvhX3UspfPI=; b=xoO7/9aozLHLhhRw22ni81SeBTq+jwhUpqG4nqyFmSI8YQArVajDFQDpA+9e3HDIJF bENwv3NG0ZIe54H1FA0DNURPUQu/C5UZLhskNU5tjshAP0MyeeNUc/BMI61DVANmRZty 9dgk1nvBj6VFT+2Etk0N3K5eVHnXi2asiYZkdNSG3jnjpLVPrfNEMLLGhqI3cHl3hhb/ WtL1jrTnFqbVmTzjQVe+euHf5CjW9wdn3iFiA3grhQ63gMWEMNUK/l7ZBPZ5lPjsl2bN BtBwxR5XCUsk8MmXS9tZfeA/HzkZZ4+uOM+PkpYDIkFSa/6oAS+lP/GjyZxbrElw+6o9 tGwg== X-Gm-Message-State: AAQBX9c0Jtn6/TDXK99n4NoTvtBj7bhoWQHr/LbYLWAiVAFJUq2RtYMP zzAzOncI9kasZ0ji6NSoMjKtqIrRoovk0kUi X-Google-Smtp-Source: AKy350bMPGOuTtC/tLxXXEyVhUgKXAV7Whj3PXHOQqxTopMLnwLa+FPGHFw97ryFAaI88njczksy337TS65Hlll6 X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:90a:5a02:b0:246:69ca:85d6 with SMTP id b2-20020a17090a5a0200b0024669ca85d6mr4048479pjd.2.1681259694873; Tue, 11 Apr 2023 17:34:54 -0700 (PDT) Date: Wed, 12 Apr 2023 00:34:51 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog Message-ID: <20230412003451.4018887-1-yosryahmed@google.com> Subject: [PATCH] memcg: page_cgroup_ino() get memcg from the page's folio From: Yosry Ahmed <yosryahmed@google.com> To: Hugh Dickins <hughd@google.com>, Johannes Weiner <hannes@cmpxchg.org>, Michal Hocko <mhocko@kernel.org>, Roman Gushchin <roman.gushchin@linux.dev>, Shakeel Butt <shakeelb@google.com>, Muchun Song <muchun.song@linux.dev>, Andrew Morton <akpm@linux-foundation.org>, Naoya Horiguchi <naoya.horiguchi@nec.com>, Miaohe Lin <linmiaohe@huawei.com>, Vladimir Davydov <vdavydov.dev@gmail.com>, Matthew Wilcox <willy@infradead.org> Cc: linux-mm@kvack.org, cgroups@vger.kernel.org, Yosry Ahmed <yosryahmed@google.com> Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: sjhsjfx8jtmm3s96x1btamzmin4cym4z X-Rspam-User: X-Rspamd-Queue-Id: 83CF91C0014 X-Rspamd-Server: rspam06 X-HE-Tag: 1681259696-892124 X-HE-Meta: U2FsdGVkX1/6nhvL9s8Nq2tW7pzneo8lJ1VLSnTSCBWdDnpcPBti6F+8zz69YqnJgfPyRzyYp4fUJCbox+2204/E2Vy2Z9objCpk2F6hZKJ5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9jh2Rz7agwi9HrXZQocw3U9feGdLUG8VVGucLmS++6FenMrwQDUoDgbwk+Z4LuKDHZZno4SrYao45IG2SCyoWRwy0+ZCD3a3UxGlcyhDtN9jxy7SQQnHRB8/PMfyJY6TjkWjcgV99jWHe1PbrpZHcJxTbyBH5UKDo11ypcJ0AVohODJRlr33oR2MXq0t5RWZkapMu8mxAvLymqtbdbFm1s2z5ioSIdDC1R84BkT92VoMGN6UhqU4rzjD9+TU5igtGluZQPikG5djs3xzNdo3BEqNNziwpoQK8UUte5HkPCMb/CJ6NwG3qlJY2MTCTX9H+2N2ms6XNXeZSKsm7Odlyzmwa2Tl3Lcuj8Y/SWaMrybLb1QZ/owYYFgUEkcD5TCQymNd/QZITNPyXDDgiV3j/qxvrhexnH+U+dzv6K5gPWKYCBss2J9FYfPMUnmncW7zTzGmbr/4oqJ46i4XaXjthN1oJiSxwX7Mwk70XXG/CLPESG8WA5w4zPg2L1Uz6fv8N3NMoe2apqDU9dsc9iYYlnlQdakhh4SMlMVlpNqrzr4741yvVpQSNXTs+YkFFV2tSyjB3gfr2pR47/bJJ56G1u2ibTPq9Xs9L0u8JO0Bi4Lb33mS3lSoRP2jT1UZrI53XePJZ7OmuDp7xeJKS95ymsMDE= 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: <linux-mm.kvack.org> |
Series |
memcg: page_cgroup_ino() get memcg from the page's folio
|
expand
|
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 5abffe6f8389..fec3c4fd9c1c 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -395,7 +395,8 @@ ino_t page_cgroup_ino(struct page *page) unsigned long ino = 0; rcu_read_lock(); - memcg = page_memcg_check(page); + /* page_folio() is racy here, but the entire function is racy anyway */ + memcg = folio_memcg_check(page_folio(page)); while (memcg && !(memcg->css.flags & CSS_ONLINE)) memcg = parent_mem_cgroup(memcg);
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 the page's folio using folio_memcg_check(): that gives it the correct memcg for each page of a folio, so is the right fix. Note that page_folio() is racy, the page's folio can change from under us, but the entire function is racy and documented as such. 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: Yosry Ahmed <yosryahmed@google.com> --- This is based on a patch originally written by Hugh Dickins and retains most of the original commit log: https://lore.kernel.org/linux-mm/20230313083452.1319968-1-yosryahmed@google.com/ The patch was changed to use folio_memcg_check(page_folio(page)) instead of page_memcg_check(compound_head(page)) based on discussions with Matthew Wilcox; where he stated that callers of page_memcg_check() should stop using it due to the ambiguity around tail pages -- instead they should use folio_memcg_check() and handle tail pages themselves. I dropped Michal's Ack as the only line in the patch was changed, but the patch should be functionally the same. --- mm/memcontrol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)