From patchwork Thu Sep 28 00:57:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 13401843 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 562F2E82CB7 for ; Thu, 28 Sep 2023 00:57:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B09878D0078; Wed, 27 Sep 2023 20:57:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB8AB8D0002; Wed, 27 Sep 2023 20:57:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9A79A8D0078; Wed, 27 Sep 2023 20:57:27 -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 89D5E8D0002 for ; Wed, 27 Sep 2023 20:57:27 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 53642140284 for ; Thu, 28 Sep 2023 00:57:27 +0000 (UTC) X-FDA: 81284192934.25.3B14C4C Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf06.hostedemail.com (Postfix) with ESMTP id 9FBBA18000B for ; Thu, 28 Sep 2023 00:57:25 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=fFcAPEWG; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=nphamcs@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695862645; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=sD2wWZIfPcmHhJT+GMtj+x1EEBi2NflbeYV6Occ/i+c=; b=t9Izz8LH/UOJoP9bEHUyR1a1s4hu/TI5px6nywNxQrnlQo4MLxy/Fa+amC/huGe7wSmPUi 4Ngpy5CbK62etkJ7Tp63iX5ltfoze3bfyNnZX15WOFlejIO4WNiQ+qFbHMSk5rEINpa/Ud +f5kmA0ynG9VCVw4OzdRGTXcxQjPehE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=fFcAPEWG; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=nphamcs@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695862645; a=rsa-sha256; cv=none; b=sI8W/OiO3KswONYbGoJ5GzpVbhKJSBnjStBDptPotGFW7bUFz2GLUR4TRC6KHGxnL+0ncB HCTweGmiiPHCMD+/vexUIlrVEtyH8b9xqCE1YXa4fPaEcdmIjdFgX1rNeZTmnG8EwrX2bJ 9vjyOA/KFhoTwozBfwCPlg3GdCYg2f4= Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-692c02adeefso7289969b3a.3 for ; Wed, 27 Sep 2023 17:57:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695862644; x=1696467444; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=sD2wWZIfPcmHhJT+GMtj+x1EEBi2NflbeYV6Occ/i+c=; b=fFcAPEWGZlCHKmGi0CPlen3pOo1tFfuNFHkpT+0jcBj3alYGLD/2DJQdIz+eS/mhgX twctzfFF362++4A+AfhWvE/4YtOv5N+hiNsqdhcVn5WCZX1L3iO/nOzhm9Xf4V9I2s19 dJjIq/zXnl6g5qCQz2T0L0dChoQDe0zoaUj74Ex3g9cbDvqI4BM3lrL5AgNTYv8xLBb4 /u1BO6cAMzOPOD0j7oN2z/0eDtWxqXfUaTyFGcBk9ZEahDORpDLTTJ9xyO5IqvSABCUm xY2ASJ1LjDJJMwK0KulKrBRL6izhB7ekeFPXHUY20tvjyMp49P12kOaYFL9GqCty+8RN CBxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695862644; x=1696467444; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=sD2wWZIfPcmHhJT+GMtj+x1EEBi2NflbeYV6Occ/i+c=; b=FJ3GYk7j8Hs9TDellwtFYOLY+0SnqKNvVueG02bZ/E+B77LnWQa7m6ZYKG4FRXa8wj g+XFpcu8sgb3k4EasLcDLpMq7/wbhj+bJBm4lEG3a64Hfb7w5+97ZvrQuzc9cgwJfVHa TjGkpIK1uAFQbOzZD6VR8AxDZD1fsOQzaASGWqd/3qWkKjy1Tp6ACgYJ1Swjkm/VYjGA ESVhyAWg4vszbAc5ZFX/cAChpYwhXw0NdmdVvZKkOcxlWNqid+h4XalwtmIFgKRJ3tC0 5SnOA9tU1KgWZrNtC8Y0doe8dBBMf8FaQ9XAZ6dXcnioh4t8FhcQDHpoAtBjk6knAfy+ OCsw== X-Gm-Message-State: AOJu0YzSe/DTKDnyXyWI3N7uXDy0FPyFyt+mPZ2c/8pG5ksBL2ePpglB l3OaHD4+G4AvnS9j1ZZa8lk= X-Google-Smtp-Source: AGHT+IEWHDi0IEBItUnMQNx/EOdHh7CuSW8OO48aHoTeVlPy/2yXozxQpgYza/XqHCnFi1KAOM7Ayg== X-Received: by 2002:a05:6a20:9147:b0:160:c1b9:a759 with SMTP id x7-20020a056a20914700b00160c1b9a759mr4043353pzc.20.1695862644240; Wed, 27 Sep 2023 17:57:24 -0700 (PDT) Received: from localhost (fwdproxy-prn-003.fbsv.net. [2a03:2880:ff:3::face:b00c]) by smtp.gmail.com with ESMTPSA id z1-20020a170902708100b001bb0eebd90asm13684774plk.245.2023.09.27.17.57.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 17:57:23 -0700 (PDT) From: Nhat Pham To: akpm@linux-foundation.org Cc: riel@surriel.com, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com, muchun.song@linux.dev, tj@kernel.org, lizefan.x@bytedance.com, shuah@kernel.org, mike.kravetz@oracle.com, yosryahmed@google.com, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org Subject: [PATCH v2 0/2] hugetlb memcg accounting Date: Wed, 27 Sep 2023 17:57:21 -0700 Message-Id: <20230928005723.1709119-1-nphamcs@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: yotqx9sw9heccdjirz5k56xgapij5xhh X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9FBBA18000B X-HE-Tag: 1695862645-65817 X-HE-Meta: U2FsdGVkX1+kx9bqmH1ebX5apGgI7NRGyE0/2ZOlcbq+cB2UdDfrFJSjAfEkbPgHHepfAyBamFiI6uCT0Ja13zKQlgz8nSQYUpmpJfRrpMzQIAk5sqRQRDWXfSqirL6b599HWeqyclK2W4BVQVlimWpQLYyzcfAw9K9pUQO+nJMtx2pxPa4OjtS8gFyBmsOlS2YxUXQqv4CEwKV8eNkGeqlfOTXNUMjSYSgR/LHC3IKvSIT4KgJQ6tKDFjbjR1qoIf17Krbe+M6rmM49WpY3M5UceOhuxasWG5ReYf+7qfYeZgu1R3fWJnLPveV6kpsCO2ScGEZmxSNRsl1VVNLStTf02adW1hvleGWQiPTcfEn+5G24Akpd/ZVxNhfTMt71CZEix1qg/WGDDa0WIl67dkmAg/7o//NyGnt6jknB3fGhJac6mSLvDT/SbLUwzclWVkVs2WwBjl2tHsT1qCzjQqMGaKMyrJDBXCcnujGjGlbY6ME9edlw3FXeZK/kf2yESC95Iclvl66oGnO10hZKfEFx1dnFZxyZTslVhnS44WpvR4iWPUuqpUB3emeA27kWhys3mrMvdpKwo8WysBAecokSyF5mfkHcSHOmZKLovlwZ0n7C5eDuVa1420YPsK3s3pWcOnYJoJNUH6e+QU97j8g+oScKr802/eeyaG1XgLYLXnzK11gKLVGrawefeRVI7YvbPGT/fDifbsyGHv6mbtHjtyuun/3X72G/AiZ6KmPJ5ZfABt+MsHT/XZ9h8E18R3lgJaBadcuImjCtmW2YUltReMARBInq+xic/Z4iYinUNj7k7bhf4OphTTmJ6rrle3b3XDwsWXW0UOCMc4ElIYc30BkLHnIL5hb24hbsSu2/sMVV8sxub/VDLUu7Al4mnPLL2N9La7lqwnfWMVxUlEIQXiMYm7IE1X+Fax7aEYod5RJ+XgYNpEzJYuEjWsCT7QJf4RgsgAbPrQE0C8S tQEpikhR xKWRRdLk3jvt+c7mRjjKN9NYYxOq++h9tDQSaAIahCWkhQPuc2whQI5pjj0FxyHOcild6/ZWfZKwAmcN+p3wRHr8EPZXQqlsOX+LWdt5lNo10KioV+T9c0pbYc4rsXSNIDXwy8+hWQVOHCONbpg0BGlwD4X5vmiY+2aUSnxP6LXdoJULepmeYZg5cQH41O24PQhyJidvhv39RQYe9LUt6HfFYrvSkxmeWBcl2qMyFJsWJXPbErVnu7xw3qVrVY7wuLgKQZdQcVrSKrLbIGuCR3jEa566sgLFgB56E/Qvq1fGu+npiypQZ3zK6T3A5sceJKKTiwn+HwUoZgsDARBE7l3/QDRkp5mgf5Kv4EWJV32pIzB+5rBap7KWFqdMrAfRmPbSyfsMDzWI8ep2UbrLPBmG9Zw== 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: Changelog: v2: * Add a cgroup mount option to enable/disable the new hugetlb memcg accounting behavior (patch 1) (suggested by Johannes Weiner). * Add a couple more ksft_print_msg() on error to aid debugging when the selftest fails. (patch 2) Currently, hugetlb memory usage is not acounted for in the memory controller, which could lead to memory overprotection for cgroups with hugetlb-backed memory. This has been observed in our production system. This patch series rectifies this issue by charging the memcg when the hugetlb folio is allocated, and uncharging when the folio is freed. In addition, a new selftest is added to demonstrate and verify this new behavior. Nhat Pham (2): hugetlb: memcg: account hugetlb-backed memory in memory controller selftests: add a selftest to verify hugetlb usage in memcg Documentation/admin-guide/cgroup-v2.rst | 9 + MAINTAINERS | 2 + fs/hugetlbfs/inode.c | 2 +- include/linux/cgroup-defs.h | 5 + include/linux/hugetlb.h | 6 +- include/linux/memcontrol.h | 8 + kernel/cgroup/cgroup.c | 15 +- mm/hugetlb.c | 23 +- mm/memcontrol.c | 41 +++ tools/testing/selftests/cgroup/.gitignore | 1 + tools/testing/selftests/cgroup/Makefile | 2 + .../selftests/cgroup/test_hugetlb_memcg.c | 234 ++++++++++++++++++ 12 files changed, 338 insertions(+), 10 deletions(-) create mode 100644 tools/testing/selftests/cgroup/test_hugetlb_memcg.c