From patchwork Tue Feb 27 17:42:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13574199 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 A36F4C5478C for ; Tue, 27 Feb 2024 17:43:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E4EB6B0085; Tue, 27 Feb 2024 12:43:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3FD936B00EB; Tue, 27 Feb 2024 12:43:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1AFFE6B00E9; Tue, 27 Feb 2024 12:43:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id EC40B6B00E4 for ; Tue, 27 Feb 2024 12:43:03 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A302AA10A1 for ; Tue, 27 Feb 2024 17:43:03 +0000 (UTC) X-FDA: 81838304646.07.3777D05 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf03.hostedemail.com (Postfix) with ESMTP id 21E1D20008 for ; Tue, 27 Feb 2024 17:42:59 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=oLA65UaV; dmarc=none; spf=none (imf03.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=1709055782; 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=KZvuxZ8Z0GdHFwXlTLgUAXn7W0I0rBhhGqeJNWJMEA0=; b=BTFGTRMG/iCSzt5CJu8UYpi70E5nZgJ6hZD2WDGSmoOFjJD7uzQefojpGVaFbdXDCL0nXb qD+D+4hMC9IMvqHIB+Cw6mieShQKG/vscBPeHLioLC72RwCQeYSWbZuKVuFpiVgxXJEk/B 2f8iZjx+UReN4lmOe7EhoF6Yos7GAr8= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=oLA65UaV; dmarc=none; spf=none (imf03.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=1709055782; a=rsa-sha256; cv=none; b=BCS52T956abdAT3eYT5LXNeiuIEVZnjL7SyvaJmr3vS3h6B8VMyndhp78L5eZp2rKd8sBV lMvHWHbyT2C3j26k5A8FpCy33yR8mB2UAMpmFv0C735W8Q6xcLeJVzoq3nAlUDNKp4c/lG W+NAduBHn8Pi0FqB5OfnSp+/RR9tkQ4= 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=KZvuxZ8Z0GdHFwXlTLgUAXn7W0I0rBhhGqeJNWJMEA0=; b=oLA65UaV457eibUT18eWCWgnFG 7i9qJyvLmglWC9HBBE3Owtm1FgSzkyUxBqVCsR9BOJ0sVYSoPHIFf0izlh7JdY8xPyUFpGqO7JYWz sxz5AJJUyh61l5Y/XP8Ym3YNGW5+L+0bB7LbM0mbLZ91tuxoNmTCF+H+ZkvWctgklTc/DPVztoEnt NYsHUlWxiKUjBxZmoahu2RVgTdwCW4tz3GowMgkwMqX45ZCtfsyYJn1K0LGpMMIX4FaYe1LYHfKab nk5ENNetdfgBxmFV0T0gdyeqa9sFRzl/qRUBFMUQnQTcoAK0nMj/+KSlOtebOuU7lCdpkz0ZBrAR4 z+yJ7iZA==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rf1Tm-00000002yr8-1vHD; Tue, 27 Feb 2024 17:42:58 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, Ryan Roberts Subject: [PATCH v3 05/18] memcg: Add mem_cgroup_uncharge_folios() Date: Tue, 27 Feb 2024 17:42:39 +0000 Message-ID: <20240227174254.710559-6-willy@infradead.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227174254.710559-1-willy@infradead.org> References: <20240227174254.710559-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 21E1D20008 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 84hk9scngjymz58sc8tzdezfn6fpfbpe X-HE-Tag: 1709055779-415265 X-HE-Meta: U2FsdGVkX18OLLpZZkDgjtq5Jq9I0mfXi1GgF9drdpRhbrF4NX0nVDSqXVCDw0NCzbuazWlo8KMhmWVG9M4RqHo+40Fa2J6Kgxp8Sb05guJgXgkjM2eVpfYEeFk7gkNfjFUgSnE6HvkyD7OKKcwzgAwmPqK8dvWPI7+xiKaYFVEaExSGQccdLnf46jTps0WQcWOkVLRePI3ZW2ogV81+s8RPxq91KWSUgP+SbJgE8lbF65UZ3OKlJWi1UtdbKOlxO+5nCO27noU3cnFLFZzrSpgtSEGtPi1ILUqTUc2I46VzHPWZvP73bF4LyZB985eLR5j0aGmC1dSnnemDtz6+sQFYktbBDmjMyLPynWn0ZL1S8B7PCdiJmjyrOI5ByAWv/7mljP5lRe7ddXblIFHXpRVODjlVK/ih7vljF8gUpyFS/UCEyWcMK6AJmgcD++somUkrcrA7u5+FvCulLKLp0U4JfGxJ0BELgGlx7w/sFFwlPV6TtQp3yvSXkgYJ1OLxYZhf81PNS5aMiymtB58Brp6JlVlWIA3jjW5mUe3UmiyhWZFXVUtsLYRxxR8mwxBgq+APEnSMr4CdqdE4YQ2J7r5QzPTrwHn8gdQX7eEk1jvfRtme1a/C7whEA9ZSCYTbZHDLiVvOS8O9IKJlCAx3UyavEEXpyY+1DtNAtvJtjxnEm8H/A1UhS6r80AfuhsxI8lQSmme7JOZoXbHx8U41wSYDS/AIuAzfJzuG1OJfCFRLAhSwcWakoPY+u4Y/k4+aCGH/mHuyEExtK+C9H9F9Xe0JYtQjvD1uH7JKOF00UJfH9ReK5GPKdjxWGgfA8ZnQRjXnom3GcRS8da54pBHekYDw6qNofczgPimWKFgGOg9rXOc30s2ckHM3RyO9z0b69Vu1MTS9MBZ71jAhiZnLylV1fxE7Ynvszybc2katVOo= 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: List-Subscribe: List-Unsubscribe: Almost identical to mem_cgroup_uncharge_list(), except it takes a folio_batch instead of a list_head. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Ryan Roberts --- include/linux/memcontrol.h | 14 ++++++++++++-- mm/memcontrol.c | 13 +++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 4e4caeaea404..46d9abb20761 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -721,10 +721,16 @@ static inline void mem_cgroup_uncharge_list(struct list_head *page_list) __mem_cgroup_uncharge_list(page_list); } -void mem_cgroup_cancel_charge(struct mem_cgroup *memcg, unsigned int nr_pages); +void __mem_cgroup_uncharge_folios(struct folio_batch *folios); +static inline void mem_cgroup_uncharge_folios(struct folio_batch *folios) +{ + if (mem_cgroup_disabled()) + return; + __mem_cgroup_uncharge_folios(folios); +} +void mem_cgroup_cancel_charge(struct mem_cgroup *memcg, unsigned int nr_pages); void mem_cgroup_replace_folio(struct folio *old, struct folio *new); - void mem_cgroup_migrate(struct folio *old, struct folio *new); /** @@ -1299,6 +1305,10 @@ static inline void mem_cgroup_uncharge_list(struct list_head *page_list) { } +static inline void mem_cgroup_uncharge_folios(struct folio_batch *folios) +{ +} + static inline void mem_cgroup_cancel_charge(struct mem_cgroup *memcg, unsigned int nr_pages) { diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 95c3fccb321b..4be37c9a0759 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -7564,6 +7565,18 @@ void __mem_cgroup_uncharge_list(struct list_head *page_list) uncharge_batch(&ug); } +void __mem_cgroup_uncharge_folios(struct folio_batch *folios) +{ + struct uncharge_gather ug; + unsigned int i; + + uncharge_gather_clear(&ug); + for (i = 0; i < folios->nr; i++) + uncharge_folio(folios->folios[i], &ug); + if (ug.memcg) + uncharge_batch(&ug); +} + /** * mem_cgroup_replace_folio - Charge a folio's replacement. * @old: Currently circulating folio.