From patchwork Mon Aug 21 20:44:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13359799 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 B2B30EE49A8 for ; Mon, 21 Aug 2023 20:44:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 27EDD8E0015; Mon, 21 Aug 2023 16:44:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 22FAF940010; Mon, 21 Aug 2023 16:44:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CE4B8E0016; Mon, 21 Aug 2023 16:44:40 -0400 (EDT) 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 E964D8E0015 for ; Mon, 21 Aug 2023 16:44:39 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B804340D05 for ; Mon, 21 Aug 2023 20:44:39 +0000 (UTC) X-FDA: 81149290278.07.B2B24B3 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf20.hostedemail.com (Postfix) with ESMTP id 2ABE91C0015 for ; Mon, 21 Aug 2023 20:44:37 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=aiiT88YK; dmarc=none; spf=none (imf20.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692650678; 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:in-reply-to:references:references:dkim-signature; bh=0TDRpjnt3h85NYff/3U+8TfIQhuK6SlrkWQVnJ9yr4o=; b=saY8PNPeFmkocy+yPDiwle/rDLJ4FBbrjmcZUsq66733jUeOZZpe8rt4h4Y5SNtOO+BHBp ZEpeV70AmGROkOCZUWqy26zVE7/9YUluGjcD2KTeibDL0OlDf/De2OWFWqHhJPnVicGJM9 JgwHceOBFiYaM4ZRSrxg8Lb357yPIsE= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=aiiT88YK; dmarc=none; spf=none (imf20.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692650678; a=rsa-sha256; cv=none; b=rtX7QplNUt3dvdUHABsyMwmkJDIAJ++yHJ0nGixgrHAYTZVPEwfBnrIcVZFLg/qJkEO/Ny RbjtvlHSdtITMAeS9F68Q8q1nEIPCIkcn/q9zJwj+wcqwJKDTumy22UGCUIKNMTeHsr7mk zb4BOQXG11VJyhBgSlGuUnNEnwJrbJA= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=0TDRpjnt3h85NYff/3U+8TfIQhuK6SlrkWQVnJ9yr4o=; b=aiiT88YK6Uq8pKYYh93LEy3hCo ajum08THddgPaTpbnBA3jfDAgrJJ5E79QHuouJ+U0j4Z/1E1CUN/BUnXceIybVt8GPL3Nu+B9PjzD AE0yomUGbAvwFIS2TFZPuFY1qBtBDW1m7tHXVozEnoS1/QH7ZAu+6nsWmQ59131mZAYmBC1PP1OnB gfEaUoDsI/W/CwDvz0kgSGufTriLT0IvyIVDV8y3oisW93lDCHIdxaFDKi1oyXkhEpZQxqzBXROWX ca6+SPI7sfqyPbDKo0gSkQ8ipUxXCD9KpFQkWChmtkVI406PQiDMBYZDV/twMf8te4IPV3GP4di19 6qq////Q==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qYBlF-00CL0M-CQ; Mon, 21 Aug 2023 20:44:29 +0000 From: "Matthew Wilcox (Oracle)" To: Mateusz Guzik , linux-kernel@vger.kernel.org, dennis@kernel.org, tj@kernel.org, cl@linux.com, akpm@linux-foundation.org, shakeelb@google.com, linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" Subject: [PATCH 5/7] memcg: Add mem_cgroup_uncharge_batch() Date: Mon, 21 Aug 2023 21:44:23 +0100 Message-Id: <20230821204425.2940496-5-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230821204425.2940496-1-willy@infradead.org> References: <20230821204425.2940496-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 2ABE91C0015 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: q9up78uddraoqz5qic6m9az1jsq9iu5z X-HE-Tag: 1692650677-94435 X-HE-Meta: U2FsdGVkX18S1nrpCjedLVt94tyviCYY+v2jZ2VfAsYYjeSpQGnFy6LxAUwdXou7lqzR8P27Cryj179NzTF4hWQwAVtEEOVOYcVBgvjL3oJzR7ag/M0FCIjjEv8QuP3w0Hr+0RpSUTEIqgMP/EB5Qi/t4Wwp4z1oOWKw3ZRXf3WGRdphXxsrLaeiK6ZWa8l5FhfQgiFTDwSWJgEW3TjO9t7OkPmO1o4Ar+FeHrHpfO1PMZdyDHC6f1LlMmsgmkxlNvTPm1HuqMSFBN/AcfPwD16cGzupmgt9CHcQpSrG+WTxc84h2SE/SHIyJlrCC7zndLu99vqZv/Rmo6aDmMnzl+UesHm0JODmG3N4Wd0sXd05s18uYPQ8XKSDSqw3e58ogtQ2e2W9Yd0sFk9nCYdfebTyGp8fEov05ipSL0xhtxuS3hbyOGwxhiMmzpMaPp2tV4IRk8+h5OF/vHEcuY7GqCs4roZRG4GVXgwgJ9VgjH9aaedsjDUTnNkfkp3PKbE3YJI5rCCFpQrG4sDGnIcMBG2H25hYEKtp37/eTiskMoU//nW5/Hcha+opwUuQaq24K38Oy9LvQg7bhtXlNwY53qA4MichBWnLWoIiYe7Gf2IGmfVjraD9cpjnqPt0/OoXOidbcBkKN9ejABpmvDsv00LzM0veK0f6W9Dryk7AaQYsdtr2dnK2cVnMNHPuEHXDi75LBk3vihO/SPdkWKkkqqfb35aMwfrGJ0T2k5BqvA6JPcy5B7lU2t9UScknBCz8O4DyGKpFBIyp9usQGei4p7wuwDhsJ409KYA1cRxFIbxz0tFqQfhE6eVNBnHZsptPTiHpAIiORvHJmAqMKMcRAO0tTTeBYXM/zKDrxoXa/lPBlWpYwjLfBr3E4XZJJecdRfF+jQemiylg9zs+FzVXwohogiB92WmM8i6CgVUrWL/eg+NkqUlZTYV2JSQzZmMb4rWkwWFGBv89z8/Vh75 yEeJOCP7 ewE1EZSucCBbSqSlnsSCmRe2feGlVRdYaImX3M41uR0kuH0bzRYwSxns//AJVS54rUB3B5BpgSI2uNsaxJc3TJg37fZ9RclxkOyJhU/TCzgHmnY4pS2i69G6pOFe0rIOjSj7+XpoUOMyQ5Wilq3m+hCQl2mUA0Vz8Me3bnuuwdM8VlF+G3iNAVkFUwZclib9hS6u8PC/K4KwqLn/KQXw93Ahb96HBX2zcMLiFs2knJjl3FPu8mdvCXnGG9gQTKqT95KqjJMxeY/2SKeg= 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: Almost identical to mem_cgroup_uncharge_list(), except it takes a folio_batch instead of a list_head. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/memcontrol.h | 12 ++++++++++++ mm/memcontrol.c | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 3bd00f224224..4ea6f8399b05 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -708,6 +708,14 @@ static inline void mem_cgroup_uncharge_list(struct list_head *page_list) __mem_cgroup_uncharge_list(page_list); } +void __mem_cgroup_uncharge_batch(struct folio_batch *fbatch); +static inline void mem_cgroup_uncharge_batch(struct folio_batch *fbatch) +{ + if (mem_cgroup_disabled()) + return; + __mem_cgroup_uncharge_batch(fbatch); +} + void mem_cgroup_migrate(struct folio *old, struct folio *new); /** @@ -1269,6 +1277,10 @@ static inline void mem_cgroup_uncharge_list(struct list_head *page_list) { } +static inline void mem_cgroup_uncharge_batch(struct folio_batch *fbatch) +{ +} + static inline void mem_cgroup_migrate(struct folio *old, struct folio *new) { } diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 67bda1ceedbe..205aa28c2672 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -7194,6 +7195,18 @@ void __mem_cgroup_uncharge_list(struct list_head *page_list) uncharge_batch(&ug); } +void __mem_cgroup_uncharge_batch(struct folio_batch *fbatch) +{ + struct uncharge_gather ug; + unsigned int i; + + uncharge_gather_clear(&ug); + for (i = 0; i < fbatch->nr; i++) + uncharge_folio(fbatch->folios[i], &ug); + if (ug.memcg) + uncharge_batch(&ug); +} + /** * mem_cgroup_migrate - Charge a folio's replacement. * @old: Currently circulating folio.