From patchwork Wed Nov 6 22:14:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Hahn X-Patchwork-Id: 13865575 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 8CA65D59F7A for ; Wed, 6 Nov 2024 22:14:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D93FF6B00A4; Wed, 6 Nov 2024 17:14:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D445E6B00A7; Wed, 6 Nov 2024 17:14:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0B7C6B00A9; Wed, 6 Nov 2024 17:14:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A2EED6B00A4 for ; Wed, 6 Nov 2024 17:14:38 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2D67880172 for ; Wed, 6 Nov 2024 22:14:38 +0000 (UTC) X-FDA: 82757075100.28.77893DA Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) by imf15.hostedemail.com (Postfix) with ESMTP id D4E20A0005 for ; Wed, 6 Nov 2024 22:14:00 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="SvIIv/KT"; spf=pass (imf15.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.128.179 as permitted sender) smtp.mailfrom=joshua.hahnjy@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730931226; 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=vBT8+7Y8eGQoStNo8j+EOisJsIkNwtvVgBPv7xvh8pg=; b=SwHyhI4wke1TU1C85kKdttNJP2W9BEpcUQHIxVzgc0Vfi5w/QkkxIM+MchjBk1e5nPfahr qTW+kmqZIe6OJvvKySdtIlY7MMl/j/WzKR27Px/1A3A630S1u2iDb7x16wb4ReyRfFpLEs ep3c431kMWZVvhMHRjspNgKm2AbjFgY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730931226; a=rsa-sha256; cv=none; b=JFE7nLtLfHQTe2TtmZyW+zPvy9+MBxKIFpZndyzbVIYpH3ypp8rLgA7Tdsvv0sLZjH+tPJ BjeIzQ3IUrKoUugUUCXL2G6JBSSvFtxPGBXYRnL/Cw6plZE5sL3yMXz4Wk8IFR/SSnOFBf YMRU7X9nQljBpH1Wr8fRf+so/Zpi39I= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="SvIIv/KT"; spf=pass (imf15.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.128.179 as permitted sender) smtp.mailfrom=joshua.hahnjy@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-6e330b7752cso10459327b3.1 for ; Wed, 06 Nov 2024 14:14:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730931275; x=1731536075; 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=vBT8+7Y8eGQoStNo8j+EOisJsIkNwtvVgBPv7xvh8pg=; b=SvIIv/KTXvDED92/BpZ5ZbBITBFgiSvjtf1/V/pIfg9Ef8V7k5R468GWixlbMszpwy DDz0EwhCvmxOtrGmQT+9qv7bKiaZSg+N7IGwBifIGMVFJI9Iqojikyl/BA+kZhwakFSI 8L0QTJHLXxXn9v/a3sBgcC302TkTpqmKzrqm4fFnO3Mnps3BHFXKJ/3p7K7E7LYN2XZu 59ywI9J3xl7wdb2n7+WXdXOTUnrbQM8+0CTDXcqGjEQsGgV2lZ3y6N964gFmKfyx1fMB 9RJVu4OCfsJpaCCVgdnWpK230UDYpZpgk/yLz0NIqNRKEL+fjD+qLaZ0XHEmwhPpU6eF z7tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730931275; x=1731536075; 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=vBT8+7Y8eGQoStNo8j+EOisJsIkNwtvVgBPv7xvh8pg=; b=JEoRdtkjNi9aLE2twrzajpeYgC3WMFzlRORjVxuLCS18q2fDVe11tM7MGhqFd+cybV DQggmvq/TYOCNdpnlu9RLIinN1qGPHLXxauDdWGKEbPlgmXDPoCVW5/XtUBB4o7Uaosy polTD+8sIaQWmwg6XUiEsAgd/a8SlsVhIVXs9BwfrsLKqMIZRgo4P9bp9nlHP8ctOW28 9k0Bc/NS0QOO3aJ67Q8MbDsXjSuOWoHIFspmuyh6BwkjPOu1x2KIk1HGYq/37uNnX7tV /DMZ+pfTYAuWx2FkfI1GSAIHfoazEH64PD2NyYQXsJZszI8SbQ6FiYBK3wfCXNuGWmbz klHw== X-Forwarded-Encrypted: i=1; AJvYcCVQHalPP1QkdYfNJkV52t+IU5CvvjxCPylzZokpjRCixlePF3B1zbleG+G/V+mq5Cu6jDHd6/slBw==@kvack.org X-Gm-Message-State: AOJu0YwBaMJP2DL+eqfR19su3ra5A06cjzv3BQ2BFiPdnLyJ3qXPK4MI JezKU85y5uZMCO4oanSORopbbKVZ7016WWJjxwIXVCjjvjyO4Adx X-Google-Smtp-Source: AGHT+IG53bD5/wh0AdwmE6KJSqgFkcBXwAWMV1DubYdMhPmG6F3ou0Rj2ZzQOQzCphQc3ElRVgS1yg== X-Received: by 2002:a05:690c:6f8d:b0:6e9:c117:760b with SMTP id 00721157ae682-6eacbfe3381mr9656507b3.5.1730931275235; Wed, 06 Nov 2024 14:14:35 -0800 (PST) Received: from localhost (fwdproxy-frc-112.fbsv.net. [2a03:2880:21ff:70::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eaceb09a6fsm206457b3.68.2024.11.06.14.14.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 14:14:34 -0800 (PST) From: Joshua Hahn To: shakeel.butt@linux.dev Cc: hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, muchun.song@linux.dev, akpm@linux-foundation.org, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: [PATCH 0/2] memcg/hugetlb: Rework memcg hugetlb charging Date: Wed, 6 Nov 2024 14:14:32 -0800 Message-ID: <20241106221434.2029328-1-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.43.5 MIME-Version: 1.0 X-Stat-Signature: 9zg5s74onugywfx978e4uscfccrsfjmx X-Rspam-User: X-Rspamd-Queue-Id: D4E20A0005 X-Rspamd-Server: rspam02 X-HE-Tag: 1730931240-117359 X-HE-Meta: U2FsdGVkX1+OyXYe4sYKuL7vfo/9/YxddBtDrrHP7+bwEJQwtIzp1VpQWkl3eW6vCaOZ52PpaQjbtzlM+FM+zACkI2YDPk2hfvzIOrqom7YkY6pdac/Pr12HUCwNXSIrbIv/OdApSLUQvF9BQOQ0Tzs5HbZy0csWG3mn7FwXri+NKSY2v+fVh15s9ChcUrgYwrR692Lutzj14uD1kCT/RGPn6dEQZau+q4llYuzGSUZbONkxOGhwAt5K3WMNu0/u92ydy+VxarcoPWnuTOZEfvC0o+iG8fx4E6fu2w+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-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: List-Subscribe: List-Unsubscribe: This series cleans up memcg's hugetlb charging logic by deprecating the current memcg hugetlb try-charge + {commit, cancel} logic present in alloc_hugetlb_folio. A single function mem_cgroup_charge_hugetlb takes its place instead. This makes the code more maintainable by simplifying the error path, and reduces memcg's footprint in hugetlb logic. This patch introduces a few changes in the allocation error path: (a) Instead of having multiple return paths, we consolidate them into a single error path. Failing when memcg's limit is reached no longer returns -ENOMEM, but -ENOSPEC like the other errors as well. This makes the memory controller error behavior the same as hugeTLB's. With this said, no callers handle -ENOMEM separately, so no existing behavior is affected by this change. (b) Previously, the memcg limit is checked before the folio is acquired, meaning the hugeTLB folio isn't acquired if the limit is reached. This patch performs the charging after the folio is reached, meaning if memcg's limit is reached, the acquired folio is freed right away. In the first patch, a check for whether memcg accounts hugetlb [1] is introduced. In the second patch, the charging mechanism is reworked. This patch builds on earlier work [2] which adds memcg hugeTLB counters. The request for this rework is also part of the original thread. Suggested-by: Shakeel Butt Signed-off-by: Joshua Hahn [1] https://lore.kernel.org/all/20231006184629.155543-1-nphamcs@gmail.com/ [2] https://lore.kernel.org/all/20241101204402.1885383-1-joshua.hahnjy@gmail.com/ Joshua Hahn (2): Introduce memcg_accounts_hugetlb Deprecate hugetlb memcg try-commit-cancel charging include/linux/memcontrol.h | 5 ++-- mm/hugetlb.c | 35 ++++++++++------------------ mm/memcontrol.c | 47 +++++++++++++++----------------------- 3 files changed, 33 insertions(+), 54 deletions(-) base-commit: 34d664f9c954f4bce85be506bd81024f64dd5fda