From patchwork Fri Dec 2 03:15:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13062110 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 390BAC4332F for ; Fri, 2 Dec 2022 03:15:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CC0D16B0073; Thu, 1 Dec 2022 22:15:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C70636B0074; Thu, 1 Dec 2022 22:15:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B119B6B0075; Thu, 1 Dec 2022 22:15:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9EB956B0073 for ; Thu, 1 Dec 2022 22:15:29 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 78DAD160B77 for ; Fri, 2 Dec 2022 03:15:29 +0000 (UTC) X-FDA: 80195900778.26.0A3BEC8 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf21.hostedemail.com (Postfix) with ESMTP id 1657F1C0007 for ; Fri, 2 Dec 2022 03:15:28 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=LXzuBlaI; spf=pass (imf21.hostedemail.com: domain of 3z22JYwoKCPIsimlsUbgYXaiiafY.Wigfchor-ggepUWe.ila@flex--yosryahmed.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3z22JYwoKCPIsimlsUbgYXaiiafY.Wigfchor-ggepUWe.ila@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=1669950929; 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=lkiKsrGghY1+tqWu87j/dNVPvsb88bb2RpuXGbm+/VA=; b=8hUaYBW8jbpjCzHsxDUhPRmwTtF6jrI+oBbVZlGf5wHQgOj2To28nF16XcbwZhPLM2hqte FUbnQw2PioaKhbvzM4huQR60X7ftgJYJMfXZqu/QlE2PUvj44ndZwLAeyOQ5YZaV33sYcK 2PUJT1ewmecjX2xb3SsBiYONoXmkTdI= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=LXzuBlaI; spf=pass (imf21.hostedemail.com: domain of 3z22JYwoKCPIsimlsUbgYXaiiafY.Wigfchor-ggepUWe.ila@flex--yosryahmed.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3z22JYwoKCPIsimlsUbgYXaiiafY.Wigfchor-ggepUWe.ila@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669950929; a=rsa-sha256; cv=none; b=RoWCVK529ZPIS0tOBePrgeDjUyiz3UM9OjIJ5lHvfiDj3QlHAkiPUnlXGYU8O+wulecBHr pD3mmRi5cmfbELt+wU3O/8hE1r94PW5Q8l217yLsyGDgNZ19wu7Ldgvp/GfkNDI2YHXc9d yK0gVbV1W7s2D+FweoPEoT1yPdkohmU= Received: by mail-pl1-f201.google.com with SMTP id x11-20020a170902ec8b00b00189986d9381so4696342plg.12 for ; Thu, 01 Dec 2022 19:15:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=lkiKsrGghY1+tqWu87j/dNVPvsb88bb2RpuXGbm+/VA=; b=LXzuBlaIaDeExqyOu2SdEI33qKVHVaAEa6EBq1XyrSfE3rPSCPGLQMVSyRpXtUvgsv rag+Aod0HZ1ICNfmgPf0FXBTk9sXmj6APzu29c5Vcz/J9gOfjBAozJ2PH+2isG/LYyXc Yp85TmDwppCvYZoGFOjIx9LLQ9Z1QqdaG7UpMW3tN2jUFxqisPg6npmhYNF1MmkXUms8 VsjDCaKCzaKQYHmNTmXZEzIBmo5staiT+/m4ihPkR3p5IMQh9R8gVZYyC4MT4eFJbuxg /6pZ6r3d1p1eOsOqeXVposFeHPyNUHmmdD900WgzrlQPSiIyIeFhwYx+u6N5VNukvH0r udoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=lkiKsrGghY1+tqWu87j/dNVPvsb88bb2RpuXGbm+/VA=; b=OobFq9dVR3rHB4ZeZwscM87sDhsamlDwM+Vatp+E8vX1rnsdUpk2VBtliRNmR+te7t PSjDRe1cHvq2hT2PIT/W0Sjnt15eSYnXqLGGscV61iq1ylOJ9EXBEXSLvdZlOGdgMMks PJYmolKtW49UpqHgnV6ME5wd2EHQYiTQ1gKQfIfDyc4RX4glRHP4LVobXrCTMnBzx//L yr9o/kFUovssxHEe8PAl3EfanSpCAww/0LcOATciWO0R2wzN0c+bPijG8OC9Al9+reQH RkBTgeOzr+WX/763Pk/nrwWQE6gWdLeGkuDREZrJRijYoZr7hVY9XHqO74HzvPvkLN2K VSIA== X-Gm-Message-State: ANoB5pnBRsaSkrVlBdic1TA9D6rlXfy4qP3nCgoUkvdOugUcTdiLZiZc KOqmYurEUOc/vRZhx7m3BSn/vfGEvB8O43p5 X-Google-Smtp-Source: AA0mqf7sgZzjDn7jKp2ODvcu3ShzFfUsM1djBmRCVU3r2snOVzfDWgcrvIwd9xVn8DEDpQZEn4ZfRfl8r43qIpwd X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:aa7:96d2:0:b0:574:2447:947d with SMTP id h18-20020aa796d2000000b005742447947dmr47086688pfq.32.1669950927931; Thu, 01 Dec 2022 19:15:27 -0800 (PST) Date: Fri, 2 Dec 2022 03:15:09 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.rc0.267.gcb52ba06e7-goog Message-ID: <20221202031512.1365483-1-yosryahmed@google.com> Subject: [PATCH v3 0/3] mm: memcg: fix protection of reclaim target memcg From: Yosry Ahmed To: Andrew Morton , Shakeel Butt , Roman Gushchin , Johannes Weiner , Michal Hocko , Yu Zhao , Muchun Song , Tejun Heo Cc: "Matthew Wilcox (Oracle)" , Vasily Averin , Vlastimil Babka , Chris Down , David Rientjes , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Yosry Ahmed X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 1657F1C0007 X-Stat-Signature: bzrwmqn5455jxgoz7z63popje7tcy9k5 X-Rspam-User: X-Spamd-Result: default: False [3.79 / 9.00]; SORBS_IRL_BL(3.00)[209.85.214.201:from]; BAYES_HAM(-1.11)[88.36%]; MID_CONTAINS_FROM(1.00)[]; MV_CASE(0.50)[]; FORGED_SENDER(0.30)[yosryahmed@google.com,3z22JYwoKCPIsimlsUbgYXaiiafY.Wigfchor-ggepUWe.ila@flex--yosryahmed.bounces.google.com]; RCVD_NO_TLS_LAST(0.10)[]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; PREVIOUSLY_DELIVERED(0.00)[linux-mm@kvack.org]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_DKIM_ALLOW(0.00)[google.com:s=20210112]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; R_SPF_ALLOW(0.00)[+ip4:209.85.128.0/17]; RCPT_COUNT_TWELVE(0.00)[17]; DKIM_TRACE(0.00)[google.com:+]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1]; DMARC_POLICY_ALLOW(0.00)[google.com,reject]; FROM_NEQ_ENVFROM(0.00)[yosryahmed@google.com,3z22JYwoKCPIsimlsUbgYXaiiafY.Wigfchor-ggepUWe.ila@flex--yosryahmed.bounces.google.com]; TO_MATCH_ENVRCPT_SOME(0.00)[]; ARC_NA(0.00)[] X-HE-Tag: 1669950928-590736 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: This series fixes a bug in calculating the protection of the reclaim target memcg where we end up using stale effective protection values from the last reclaim operation, instead of completely ignoring the protection of the reclaim target as intended. More detailed explanation and examples in patch 1, which includes the fix. Patches 2 & 3 introduce a selftest case that catches the bug. v2 -> v3: - Refactoring selftest helper reclaim_until (suggested by Roman). - Collected review tags on patch 1 & 3 from Roman (Thanks!). v1 -> v2: - Instead of adding a new helper, extended mem_cgroup_supports_protection() to check if the current memcg is the target memcg, renamed to mem_cgroup_unprotected() which is much easier to reason about (suggested by Roman). - Add a selftest case to catch the bug (suggested by Roman). Yosry Ahmed (3): mm: memcg: fix stale protection of reclaim target memcg selftests: cgroup: refactor proactive reclaim code to reclaim_until() selftests: cgroup: make sure reclaim target memcg is unprotected include/linux/memcontrol.h | 31 +++++-- mm/vmscan.c | 11 ++- .../selftests/cgroup/test_memcontrol.c | 91 +++++++++++-------- 3 files changed, 82 insertions(+), 51 deletions(-)