From patchwork Fri Aug 2 12:20:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13751515 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 6CE78C3DA4A for ; Fri, 2 Aug 2024 12:21:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0149E6B0085; Fri, 2 Aug 2024 08:21:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F04956B0088; Fri, 2 Aug 2024 08:21:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DCC166B0089; Fri, 2 Aug 2024 08:21:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id BF7126B0085 for ; Fri, 2 Aug 2024 08:21:08 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2EC0C1C43AF for ; Fri, 2 Aug 2024 12:21:08 +0000 (UTC) X-FDA: 82407215016.23.C6DC0A3 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf25.hostedemail.com (Postfix) with ESMTP id 36C43A002B for ; Fri, 2 Aug 2024 12:21:05 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=eX9ryNqF; spf=pass (imf25.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=21cnbao@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=1722601220; 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=SZw+mrWAtNO8gx3RRID0EOwy0TVTv1NvTSzmaII/3QU=; b=02OSy4WaX8L3JPYSrD4lKQGm/2NGlAiIOZDfdBLXSCWjkw+XspB1frB67BDhs+/DTo1tWS gBmueMet7Tv9Flv+9tDIjvhHX1bRygm6ATR1AunutLqPz/stuAU2/vpIfAV2qzUdFt0D5R ikH8cZ/VnXKKj3L0bsjtUr4M1Q47Txo= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=eX9ryNqF; spf=pass (imf25.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722601220; a=rsa-sha256; cv=none; b=amBqOhDkCl3Fhi81BxWubqiKrl83N5aTpHQUko+vKiegsRCHalor+V2KhuQy1hTK0mqURS fv1WRjyAM/AEYuBbh98aq4KQCfo2VpuRK4Szxe+70hLzKMJ3AZ+9n5Z9iODSSmneQEuUR8 pxn++A2jbLx/X95Ze1wrnHz6Jm1WR8Q= Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1fc4fcbb131so70578965ad.3 for ; Fri, 02 Aug 2024 05:21:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722601265; x=1723206065; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SZw+mrWAtNO8gx3RRID0EOwy0TVTv1NvTSzmaII/3QU=; b=eX9ryNqFa/nZkX4ndrKyiJ6O8k9Z2viVkCrQO4vZlz8K2bpuGPEvjlBymODyIRAupH Uaw58aDMK27RXZcP0LRXesXqwylgxXaDtyU63AAf3WO4mmav61mbxneq8CQ+X8nvFRUo LxWRblZReDNsTNrrHySTvZclG0yBaDhCVEVJguNZpNtiQhP8QmPasTpXJ3cowLZG45vq n6zHlDucXYeLvePHxVwZhm50hFTIGo7IIHNMWWm2gX3W3VypjdQ0vDNgqqTZ8rNAcgGg 9EPLdRPyybR2ylp1KOtph2wzstVjofSfsmGNIWdOpFSWF/R7XOmFkOsRMrR3CyZIJc0l FGcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722601265; x=1723206065; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SZw+mrWAtNO8gx3RRID0EOwy0TVTv1NvTSzmaII/3QU=; b=JdtKQZBtCmWHlhjIZog4iZXhsvsyT6PBhe5mLVa9EouZ4iDfWMQg9NT5J1TMR0z0zq O08xQdyvybV7qkkMLbwBWWYRDrf8SAhA1TzLnScA52aFkwb2IGSHKlKyR8AmLYxqrGVR FXJma2JKIB9GSfzM0KOcynefostzcPDRhrsCY7c8KEfe3VxEWUu3etcLyj/Z2e66OO7z WDvk0GM1IlorBA5O7GLpXr22AephIk2RblKY/uE+GhUnLIRl5ksODv5Idk2m2lM3KN6H odzDp2u2A6TWxKwFCm6nqZ5/0yue683LppI7/MkamLBmjzdXjFXwgpUsU279JGwjaSBV eTng== X-Forwarded-Encrypted: i=1; AJvYcCXTUMl/QGaamXzrIGv+czBUUwFoTZSdenUxcvIWVKcfDKSrt1jeO+vHgOt2x9IheyHQacmuduCHj+xTH4kOATpj5n8= X-Gm-Message-State: AOJu0Yx77NvJlJYQLgcG3BBq9JUepj0xb3GjA4PZY5fHMwskKfdFmW8q +1mYsIwLZSc0wbBe2acSjuW7MEIji8SqkXtl+XLqq2FTRZm/j83Bihqjrg== X-Google-Smtp-Source: AGHT+IH1pVDAT1Yc267JouGX6+3PsrKXzfDOleAEismvtPezwW0HljZJprD4nR6qZc1Oy9FTD3tnXg== X-Received: by 2002:a17:902:db07:b0:1fd:9e44:e5e9 with SMTP id d9443c01a7336-1ff5744c810mr42469645ad.53.1722601264728; Fri, 02 Aug 2024 05:21:04 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff590600e4sm15841875ad.144.2024.08.02.05.20.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 05:21:04 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: baolin.wang@linux.alibaba.com, chrisl@kernel.org, david@redhat.com, hannes@cmpxchg.org, hughd@google.com, kaleshsingh@google.com, kasong@tencent.com, linux-kernel@vger.kernel.org, mhocko@suse.com, minchan@kernel.org, nphamcs@gmail.com, ryan.roberts@arm.com, senozhatsky@chromium.org, shakeel.butt@linux.dev, shy828301@gmail.com, surenb@google.com, v-songbaohua@oppo.com, willy@infradead.org, xiang@kernel.org, ying.huang@intel.com, yosryahmed@google.com, hch@infradead.org Subject: [PATCH v6 1/2] mm: add nr argument in mem_cgroup_swapin_uncharge_swap() helper to support large folios Date: Sat, 3 Aug 2024 00:20:30 +1200 Message-Id: <20240802122031.117548-2-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240802122031.117548-1-21cnbao@gmail.com> References: <20240726094618.401593-1-21cnbao@gmail.com> <20240802122031.117548-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: c1k11w8syney7axrhsyyjhnjzircn1pi X-Rspam-User: X-Rspamd-Queue-Id: 36C43A002B X-Rspamd-Server: rspam02 X-HE-Tag: 1722601265-483380 X-HE-Meta: U2FsdGVkX1+1gNHqOmt4jnRjQVPn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kcN9n2oHfHizf+uMvFvjk1sqeLPALTMHugR97aST/FZBL7b+4Bk4nF85V96lGGayahlpqXOIzTZrigLVcbLWfpufzBZvIm+UHFqHLDjjMwo5gGQziDpa56fwXyCH6iRyxl14BF78LmloU8eSYuFmipcruDKFosZWJPgGlnRWt3Wt7LjV0/Ub/VOc19mvFkAKq9NlT/bwHXgxlK1XC89X5NRpuCVURuaSfscgijZz3eMQl8jrEZywZznyKPKheJqghB6Es5VrfzbbnfuzGRSjaGQaY7F2+crz85D0YOeWZJhTDGC3QgX98xxfZaNLiyi4/H0X5aa8G9wDHrNPfzsVgq6RzgrQT0TsvrOjaorBObtaF2 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: From: Barry Song With large folios swap-in, we might need to uncharge multiple entries all together, add nr argument in mem_cgroup_swapin_uncharge_swap(). For the existing two users, just pass nr=1. Signed-off-by: Barry Song Acked-by: Chris Li --- include/linux/memcontrol.h | 5 +++-- mm/memcontrol.c | 7 ++++--- mm/memory.c | 2 +- mm/swap_state.c | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 1b79760af685..44f7fb7dc0c8 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -682,7 +682,8 @@ int mem_cgroup_hugetlb_try_charge(struct mem_cgroup *memcg, gfp_t gfp, int mem_cgroup_swapin_charge_folio(struct folio *folio, struct mm_struct *mm, gfp_t gfp, swp_entry_t entry); -void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry); + +void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry, unsigned int nr_pages); void __mem_cgroup_uncharge(struct folio *folio); @@ -1181,7 +1182,7 @@ static inline int mem_cgroup_swapin_charge_folio(struct folio *folio, return 0; } -static inline void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry) +static inline void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry, unsigned int nr) { } diff --git a/mm/memcontrol.c b/mm/memcontrol.c index b889a7fbf382..5d763c234c44 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4572,14 +4572,15 @@ int mem_cgroup_swapin_charge_folio(struct folio *folio, struct mm_struct *mm, /* * mem_cgroup_swapin_uncharge_swap - uncharge swap slot - * @entry: swap entry for which the page is charged + * @entry: the first swap entry for which the pages are charged + * @nr_pages: number of pages which will be uncharged * * Call this function after successfully adding the charged page to swapcache. * * Note: This function assumes the page for which swap slot is being uncharged * is order 0 page. */ -void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry) +void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry, unsigned int nr_pages) { /* * Cgroup1's unified memory+swap counter has been charged with the @@ -4599,7 +4600,7 @@ void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry) * let's not wait for it. The page already received a * memory+swap charge, drop the swap entry duplicate. */ - mem_cgroup_uncharge_swap(entry, 1); + mem_cgroup_uncharge_swap(entry, nr_pages); } } diff --git a/mm/memory.c b/mm/memory.c index 4c8716cb306c..4cf4902db1ec 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4102,7 +4102,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) ret = VM_FAULT_OOM; goto out_page; } - mem_cgroup_swapin_uncharge_swap(entry); + mem_cgroup_swapin_uncharge_swap(entry, 1); shadow = get_shadow_from_swap_cache(entry); if (shadow) diff --git a/mm/swap_state.c b/mm/swap_state.c index 293ff1afdca4..1159e3225754 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -522,7 +522,7 @@ struct folio *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, if (add_to_swap_cache(new_folio, entry, gfp_mask & GFP_RECLAIM_MASK, &shadow)) goto fail_unlock; - mem_cgroup_swapin_uncharge_swap(entry); + mem_cgroup_swapin_uncharge_swap(entry, 1); if (shadow) workingset_refault(new_folio, shadow);