From mboxrd@z Thu Jan 1 00:00:00 1970 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 DB6B6C61D97 for ; Wed, 22 Nov 2023 20:57:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4BBD86B05B5; Wed, 22 Nov 2023 15:57:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 46C4B6B05B9; Wed, 22 Nov 2023 15:57:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3352A6B061E; Wed, 22 Nov 2023 15:57:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 21ECD6B05B5 for ; Wed, 22 Nov 2023 15:57:39 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 029461CC6A0 for ; Wed, 22 Nov 2023 20:57:38 +0000 (UTC) X-FDA: 81486801438.03.B274AC3 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf22.hostedemail.com (Postfix) with ESMTP id 7BAAFC000F for ; Wed, 22 Nov 2023 20:57:36 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=XuXcikeA; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf22.hostedemail.com: domain of chrisl@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=chrisl@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700686657; a=rsa-sha256; cv=none; b=0ckPW6r2yue4Va8tEATkAhj/l8SyjMwSkR7/ZpCkqnq25TfPJlGSEPsf37fE6M92KMW1Pt sZmDUOEBtgPV8v5KsjDftktTpyKfRFB0oZrbERQ/G9/HMIntBhKr91fmo092JuxAdXf7g/ KuuscxxvKkDpluCHtiQjZDGuBFRvTW4= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=XuXcikeA; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf22.hostedemail.com: domain of chrisl@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=chrisl@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700686657; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7HrNNwCQeYg//1wXfdONZGPlZPj4fJmEJbfhUw7Kkxc=; b=12/8u1/w0iiDg7oufYCFrfWFcaPLWbglcYL6pE9FFSjbMkguc9YTGBl1etbfiWnrrKFYNR TxURExSp0w9eUGFmLOeg9fElxzuI2zR8/JSRMAwKCh1K+A5HOLy7Dr6G+X9lJEionHAyzB I4y3TCL7hnPh7LOraxh10rIGHna6Ew4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 28620CE25DF for ; Wed, 22 Nov 2023 20:57:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F500C4339A for ; Wed, 22 Nov 2023 20:57:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700686650; bh=7HrNNwCQeYg//1wXfdONZGPlZPj4fJmEJbfhUw7Kkxc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=XuXcikeA33Q/gWnu28IA8nuMw00BMbt1MiE+s5+0GkVvA8mYBFnbLs2cNt7FHmkQl o/HsgtRjSt6yvQA9iBmWoN1GGLB7cBibVRM8g5ZPQARuxZTKptTB5IwRmo9ygsfkJW +LXFK2csxvO1YK1pymiLc0qSR50ejKIuesyNQ0vG14Gt7y6+qbxW1Q4s4IYUKP+onn 2O8vX9zJYSuWk2KzWmkgflTex0LJ9bMhNqcs8wVfX9eY+dTBYaTybjuuzfXPraNW86 62Dct+3HkDIxkzfC6amhUkWQDFyiaOXirmiZiHK5buIW+AjFJ9bViZeYXmktshuwyd SYOsBfAcC1otg== Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-5c206572eedso151813a12.0 for ; Wed, 22 Nov 2023 12:57:30 -0800 (PST) X-Gm-Message-State: AOJu0Yw4rpewVbv+qxtzk0TsV17ZLhUAr1c95QLn5n20/jgonJmq8qtM PjcfIE9F+twhC+0v+wwMzabgmmwtKuAqUC2ms4ytkA== X-Google-Smtp-Source: AGHT+IFiijhA01TJBJCiU8uJ8BY9AkxHJlZ982j8yRZgJVXgFkxBtLfdID5bMz4YhZXoZIwOfNEZsF4Lfko9ol3wOkg= X-Received: by 2002:a17:90b:1b46:b0:280:6e68:a5a8 with SMTP id nv6-20020a17090b1b4600b002806e68a5a8mr3740315pjb.22.1700686649843; Wed, 22 Nov 2023 12:57:29 -0800 (PST) MIME-Version: 1.0 References: <20231119194740.94101-1-ryncsn@gmail.com> <20231119194740.94101-5-ryncsn@gmail.com> In-Reply-To: From: Chris Li Date: Wed, 22 Nov 2023 12:57:18 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 04/24] mm/swap: avoid setting page lock bit and doing extra unlock check To: Kairui Song Cc: linux-mm@kvack.org, Andrew Morton , "Huang, Ying" , David Hildenbrand , Hugh Dickins , Johannes Weiner , Matthew Wilcox , Michal Hocko , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 7BAAFC000F X-Stat-Signature: omtot1q78u7dohhfmsz4miy6c86xd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dRZP0jK5ZpBvsyyX81qf7r8+6t85MfG/VlJkkSTT9j4+yLdK5xfEod9mb1t4kox0fuodHf/dP4kPpUaY+1MMavkVUYiCXYdQjuWkyzeKBGft6YWGfsRKhDRVeMglNWoFuiBH0a9oCNnrREm34wqUPqU9xc+mlR8Rj5XeN/mYPQwK3p0zw= 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: Hi Kairui, On Wed, Nov 22, 2023 at 9:33=E2=80=AFAM Kairui Song wrot= e: > > There are two different charges. Memcg charging and memcg swapin chargi= ng. > > The folio_put will do the memcg discharge, the corresponding memcg > > charge is in follio allocation. > > Hi Chris, > > I didn't get your idea here... By "memcg swapin charge", do you mean > "memory.swap.*"? And "memcg charging" means "memory.*"?. There is no Sorry I should have used the function name then there is no ambiguity. "memcg swapin charge" I mean function mem_cgroup_swapin_charge_folio(). This function will look up the swap entry and find the memcg by swap entry = then charge to that memcg. > memcg charge related code in folio allocation (alloc_pages_mpol), > actually the mem_cgroup_swapin_charge_folio here is doing memcg charge > not memcg swapin charge. Swapin path actually need to uncharge > "memory.swap" by mem_cgroup_swapin_uncharge_swap in later part of this > function. I still think you have a bug there. Take this make up example: Let say the for loop runs 3 times and the 3rd time breaks out the for loop. The original code will call: filemap_get_folio() 3 times folio_put() 2 times mem_cgroup_swapin_charge_folio() 1 time. With your patch, it will call: filemap_get_folio() 3 times folio_put() 2 times mem_cgroup_swapin_charge_folio() 3 times. Do you see the behavior difference there? Chris