From patchwork Fri Jul 26 09:46:16 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: 13742538 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 394D0C3DA7F for ; Fri, 26 Jul 2024 09:47:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BBFB46B009F; Fri, 26 Jul 2024 05:47:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B48F26B00A0; Fri, 26 Jul 2024 05:47:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E9536B00A1; Fri, 26 Jul 2024 05:47:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7E19D6B009F for ; Fri, 26 Jul 2024 05:47:21 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 34B621A1720 for ; Fri, 26 Jul 2024 09:47:21 +0000 (UTC) X-FDA: 82381425882.22.E73EC78 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf18.hostedemail.com (Postfix) with ESMTP id 3D3C91C0004 for ; Fri, 26 Jul 2024 09:47:19 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=CIOEDnqI; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf18.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721987183; 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=iStQPHQRdxqlUzAFxf7mNsjUptqesHyoCMxe2kJhC00=; b=MgQ19SmY9mRhjG07cMsn1VHEEa0Sqx9XtG3YIxiSGqSoYUAfqoujnJVZwuXIRp0fKrGPMV do5v7br0Img6HsbrBBv1FLq1gOCQRFskM44YNbVZUBsf0Pp6OqkV6dEFqcEkXyyGqQ0jw0 TFQqJopL6541SpOJgkP3rzNKY5/xm5o= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721987183; a=rsa-sha256; cv=none; b=X33KNer4ATTPE3Ztxnn946Tb/vaUoQbrGOQQmumMSdK3HXFGCkqf6qMCaJmTfBu4u8+JSf RnmFJ4dGOBYExve4PlSaoWsGReRg7pEfvsPRBNgN0Gbb3TLxj0laGAvdxiWxSC55SNXedu i9pfdj0+5y4uKy2MBQ8Xj9Xa/FHWPbs= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=CIOEDnqI; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf18.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=21cnbao@gmail.com Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1fd6ed7688cso4135385ad.3 for ; Fri, 26 Jul 2024 02:47:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721987238; x=1722592038; 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=iStQPHQRdxqlUzAFxf7mNsjUptqesHyoCMxe2kJhC00=; b=CIOEDnqIGaLBgkCPeYPqIAVej6WsxgRHiB0+BNg1uNeMVRck1koIlHU87SyFFbX1p+ f2ea6DfziZzk+FRqqLLQ/MKOx1SMh06ChPjiuwzgkRdbOAKfUrN65qtjHS6cQ7ECzVPD 8KezHOu+Y4v+4eNUjmvaKFkvL15WjrLZNw1E5Zoi0cx+WScX7WL8ef+o0uGQfJapH00+ OCYDU0/TwrscIyHFZ7JFpqGb/U8gxLGfRV/JyyhbYacY+dm8yZBmUnfTZ5xRgkQ5T02L x1RHGcdKINkFOq2juT/zvdxjizHukgcaTBnPedkKs4OXc25kOqpJxRpg9R9MagJ+9rxi 0Lig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721987238; x=1722592038; 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=iStQPHQRdxqlUzAFxf7mNsjUptqesHyoCMxe2kJhC00=; b=LackTlupR91gOC6KWNpnPRV2zdMTsrt0gNvOO1iT8HTOe8nji8sydCgo2M1+xkr3SW HX9T4WpVDPAPpXUFm8mMLTtqkqfaIdIUIZuwJs73jVxbC2yrNum39VbGJfDUD3uwTJfe 1CSPDTLcRU9ggABkQiarvH2kbQcdoejXipk2aRee8wbjzQJLCEu2XimuUzC60eAYpW5b bTG6Xj/lpYkhZMMkXDuFRLOF7WqKn/NBeAPVOcoic6mLTVVdUDBQ7KsGEOMVczOnjoFH uTcl6ORhe8UgqSHHEeWqDAdmUiNNFZYLIpODtIGxa74JfknV7myrZagkv9c6uawNN5cs 76rA== X-Forwarded-Encrypted: i=1; AJvYcCWfQIxWuxdJqiWODSCrI5IYeUTiJvxDDCryeBBlrH8VctWS+PhG91QiUdSWMUC6r8FDd6zlgSofhyxNMHqavSgdxSY= X-Gm-Message-State: AOJu0YxjKEElk+B5N+zrXi8Xy4crb40LV1eOpYT5ErF8bY9bSuAvnBX9 Cb42ZU87cFOU7HWuK/fqbQCZRmeKGE4YfKtfl1HlAA3HkPiF8vsb X-Google-Smtp-Source: AGHT+IFV2vyejBZHn0Sbv1/bTqARWkAYD5OnxGQx8g/+AtNmVatjTvFKeAc/Eg61DQwGNl7rxqQGzQ== X-Received: by 2002:a17:903:18a:b0:1fd:6529:7447 with SMTP id d9443c01a7336-1fed389c064mr59497475ad.29.1721987237952; Fri, 26 Jul 2024 02:47:17 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7d15e98sm28127455ad.99.2024.07.26.02.47.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jul 2024 02:47:17 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: ying.huang@intel.com, 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, yosryahmed@google.com Subject: [PATCH v5 2/4] mm: Introduce mem_cgroup_swapin_uncharge_swap_nr() helper for large folios swap-in Date: Fri, 26 Jul 2024 21:46:16 +1200 Message-Id: <20240726094618.401593-3-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240726094618.401593-1-21cnbao@gmail.com> References: <20240726094618.401593-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3D3C91C0004 X-Stat-Signature: kosdhzoeo1dfxgbyxq4kyiej6fyzh5oa X-Rspam-User: X-HE-Tag: 1721987239-997717 X-HE-Meta: U2FsdGVkX1/EZpeFeTTcvvTBVI3Q6PinE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QvNvYDwsJwHSBCKGgaQdXaRif/9oLeQsYSwhzAaxutNYGP7IbxQ004Cv2Qarjw/BJWoKSL8+oxtfUfQMyaMN9RQUoEZtA3EZLFjzf/rGTxgltpcsWuk60Bv6oqthdD4ITRyo3Ix65+qLXMcUw+yXDb82lh0HrcTJ1V1KS2//Aa0Dk6cN7Cv/lxsyT/PxnyQCci90L6CcIaHcZRAMrzFR2WfF3b0FP0e4AgEC/bbrewZYWStBdXJwMXRru0AjXhTzgxXJDaZ/X7E5C7CWjqh4vbheUDtf+g0NiEHfGX8Hq8HQYeydS6UM8NvQni1IjynChsx/i6wx99QpHfxFFX1bqv5V1LsQ3NgE 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, it is better to introduce a helper for that. Signed-off-by: Barry Song Signed-off-by: Barry Song --- include/linux/memcontrol.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 1b79760af685..55958cbce61b 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -684,6 +684,14 @@ 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); +static inline void mem_cgroup_swapin_uncharge_swap_nr(swp_entry_t entry, int nr) +{ + int i; + + for (i = 0; i < nr; i++, entry.val++) + mem_cgroup_swapin_uncharge_swap(entry); +} + void __mem_cgroup_uncharge(struct folio *folio); /** @@ -1185,6 +1193,10 @@ static inline void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry) { } +static inline void mem_cgroup_swapin_uncharge_swap_nr(swp_entry_t entry, int nr) +{ +} + static inline void mem_cgroup_uncharge(struct folio *folio) { }