Received: by 2002:a05:7412:e79e:b0:f3:1519:9f41 with SMTP id o30csp188736rdd; Wed, 22 Nov 2023 12:58:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IGotQ+qXe8gdMsGxjvnGwXYuiA+VTp/saRw8DcCmNhtLTy2uIqFMd5D3jvDy5qF5ZZPS8nL X-Received: by 2002:a05:6a00:17a0:b0:6cb:8b26:9793 with SMTP id s32-20020a056a0017a000b006cb8b269793mr4255823pfg.24.1700686731831; Wed, 22 Nov 2023 12:58:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700686731; cv=none; d=google.com; s=arc-20160816; b=gz9RofWDk4H+ZLuaVgHbyT7wxKS0G3HCftGqTMCDG/0myRAKnU7HnqeEfoOm5EBse1 NYn6RQSSRkBsMcXW2bcFn3CJDYxUYUYwlJ2zqrMHlq2o68edwH+fVsMbcO5alCTATFGo fLcgTNphh/KmSDGnZblHp3We3Hmu+t2kCPhpww439rxMr9hO2+6UAZJLhDt3QBz/1f+M vUzANnvbrQW5Xfk0t/9tqO2AmnqVbSap8c0PW404Sg4ZMhJuLcO3XDrezuaVAODRNboG CDjWeLDhx2j5n/dsLlwj/Yc6YdQTbQOKzkZxQTVRaraSEZ99/Ef08TGn/jQzFdrUPaUW vJ+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=7HrNNwCQeYg//1wXfdONZGPlZPj4fJmEJbfhUw7Kkxc=; fh=K/LZ1BUptwrDpCNjVhfmA07Y8doOUYOQskSkVF/w5AI=; b=Ca+Hvnx5XkZgAW5eeum7SBjH/Z9aShRR1LqFR4+29m0P9Hj2b9KrOzOTlHe97nmVxF o1Gy2uqIn5/3oa94hjQDdvxw/burG59xZ14+EgkK3Ioo12pjOUqR81nTUgSY1E7cHdCf Hij6KvJZNqGIfa+pqsNq/sCpV70ULYawHzS+9v/k1zq9njPUVC8uWmn+PY5EOZOzxSMT uoie//U9LK56iOBxXgYSQHGPYYjv1TwCyiqXtNb1wDRCmSAKmrFAnUhXI9fSqCvQhbiE o1jU+cacp0pq5r/QCAzDDm8JIMVRFUKtokrJz6JuhaIQqarawr2feNTKf3B/6hM9dR3h xb4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XuXcikeA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id t3-20020a63d243000000b005c215b317e9si223573pgi.478.2023.11.22.12.58.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 12:58:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XuXcikeA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id C3E9A80C5FB3; Wed, 22 Nov 2023 12:57:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231596AbjKVU5f (ORCPT + 99 others); Wed, 22 Nov 2023 15:57:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230377AbjKVU5e (ORCPT ); Wed, 22 Nov 2023 15:57:34 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDBC91B6 for ; Wed, 22 Nov 2023 12:57:30 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A41AC43391 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-f181.google.com with SMTP id 41be03b00d2f7-5bdbe2de25fso134760a12.3 for ; Wed, 22 Nov 2023 12:57:30 -0800 (PST) X-Gm-Message-State: AOJu0YwrMh0tFtiqfi5JqjV6V/grnZzYc2PzPZF9hVbzLaqUTHTWhuwg X25vuCjgvnIHkMcuo9ulZiCcXn8LGeNLlM5fc81W6w== 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-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 22 Nov 2023 12:57:38 -0800 (PST) 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