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 365A6C61D97 for ; Fri, 24 Nov 2023 08:15:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ACA716B00E3; Fri, 24 Nov 2023 03:15:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A7A1A6B00E7; Fri, 24 Nov 2023 03:15:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F39C6B00EC; Fri, 24 Nov 2023 03:15:03 -0500 (EST) 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 7498E6B00E3 for ; Fri, 24 Nov 2023 03:15:03 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3CC8C140A02 for ; Fri, 24 Nov 2023 08:15:03 +0000 (UTC) X-FDA: 81492137286.11.972B881 Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) by imf27.hostedemail.com (Postfix) with ESMTP id 453B440014 for ; Fri, 24 Nov 2023 08:15:00 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=M1PCXbOA; spf=pass (imf27.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.208.181 as permitted sender) smtp.mailfrom=ryncsn@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=1700813701; 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=6oXYAGeXachCCe2/bIuP5OEv/Ub7oTlTCCZrnr5GJzY=; b=b2bLJBKOLb/ZVEdGfMxQ4g0hrLOtPys69ykmLncq0hm9h2I6T6NFhb0LQeQDrPBWEXYmKY ZInCjwXZ2zk9TIcQUGiN1EguUqLr+hLoHZSrcdaCyx8YpEkNt/vG8+S3LxHpO6Q/JzZxAD C/xYFSFjgah2Oe1gV+kgx6/G1AcOSm4= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=M1PCXbOA; spf=pass (imf27.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.208.181 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700813701; a=rsa-sha256; cv=none; b=Li3rHa7iOqw2jbis7yskh2dpJE9iXt6dyKjp5XHxZIRNWQX2aPgJWg16vTPMax10TA9yGL sUBb0Pvns2EOAzt5u9ZcmO141okT5kxj+FlMAH8ce/jApqyQofknXuhbtXmPIwq5FrB2JG dn0jt2y5Puhk3cCol8wU/l+lfY7crvk= Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2c87adce180so19670731fa.0 for ; Fri, 24 Nov 2023 00:15:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700813699; x=1701418499; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=6oXYAGeXachCCe2/bIuP5OEv/Ub7oTlTCCZrnr5GJzY=; b=M1PCXbOAAfWZDQ6qwPjr8H1h1X93Ma1izFZAyMXD59PjVBAPuw5WWzjvQJVjj7PTPr v26x2sVBOOdccJR9g7PWLkD/mYF2OWTrNAyreyN9ydlUdqi6rqxhEPmUIvAMC+qzZulD yaI1pI3lV6atSZMMoWxwavg/5bQ/9fuhDTk9fTTEdhovEGqu15J37MJiUsOdDH6oxc+Y xyFjKoi5Hpsb4I57b0sc151O9gp0+wjSv/OVoCqw4ILn7o11i3M/ICNYdNaMJb4hmEJ0 UqMbs5O5emHYI1ZnkRr4LZwpQsvwbSwICn+U4XFEwz0hPqfDkh262Of3TMv6VyFR4lVw DM/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700813699; x=1701418499; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6oXYAGeXachCCe2/bIuP5OEv/Ub7oTlTCCZrnr5GJzY=; b=ECLFqpiyczwJjlPKXbWlxQcssicYfqhsIsiJxRhI3roi/MyKc10CYldNbumPwV2oMB mjki1g4sgAUzHtYyvMOErFbzP4Z+VgkA4e/AHTbzfwt1nQjGHaAUPz6qAxmp4Wv7kC+u +lJ/2HOysmnfCAoDdBrfZzisD47RRED1fRW4rOnc/B271LPCDp4pSC4HZUb5jQjFUtgL aFfk9H+qPh/MNMxdXiTj1ghyAANmLute4peh6bTHRM1TwS5aSClJzwnSdANT+uSgLVV4 3E0Hf+NGLdWtPdg9gQ3uikLYgb3Wnapkrd83JDVQZWT1ncji6I3tOZ7tILtiTi6Muw4H NrpQ== X-Gm-Message-State: AOJu0Yz/xyvHYwR5O1BCTe31s6WxmVfAEg2Z61ts5qoYZ5d1jks6ae/P JRVgL7qzUvFeE76McDDsfvcbELyFiiUUvCdrnLc= X-Google-Smtp-Source: AGHT+IFRMh+bKAjZCpJBgtB/uvXxgv0uD8dPXcIWu+uZcx/fWJ9STjrWR/3JOQ4bOsE/AYrcPq1JnUdVcqrQsbVwcP8= X-Received: by 2002:a2e:97d8:0:b0:2c8:83c7:4046 with SMTP id m24-20020a2e97d8000000b002c883c74046mr1291556ljj.26.1700813698968; Fri, 24 Nov 2023 00:14:58 -0800 (PST) MIME-Version: 1.0 References: <20231119194740.94101-1-ryncsn@gmail.com> <20231119194740.94101-5-ryncsn@gmail.com> In-Reply-To: From: Kairui Song Date: Fri, 24 Nov 2023 16:14:41 +0800 Message-ID: Subject: Re: [PATCH 04/24] mm/swap: avoid setting page lock bit and doing extra unlock check To: Chris Li 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-Rspamd-Queue-Id: 453B440014 X-Rspam-User: X-Stat-Signature: mpfok7tdbj5fp5hqqficfmqnm8kzkhx7 X-Rspamd-Server: rspam01 X-HE-Tag: 1700813700-41063 X-HE-Meta: U2FsdGVkX1+UypH6XzJxcmOlqPAsGZXGcoHE5mRbgDvmia/ZnDa5DjGmhwYF7rNdY+Vv8yGEZ15wfUtDjih9gy22azCSDM2pTqzw1FGyCRtjgF5uUGfaa8sWELXc7UzszeKlg6D/yFQgw05FPiVXOQs9ST3uS39Wo9cRL3wRUq9T3RdlDhNnbuTnXzX994DVa0I2gCKbFbB1St4Ll0+9pxbAeoXDIovA+yPryks/Q+0bb+fUxSmENYJOr77F6/AzMrf46GDN/nHt1YkdKOS/0NqpnmBsVid/nmXCHvQ+BKFO8TZpTH+JU+VqqTYzemxJMBjzQr0/wpFq1u+IeBq83JMf4b0f9eq/2OO0TR/LdqREQLGBXunsk6Wmoz0SegJ5Ks6otv+Efj1kC7xwX+Qjrg2UzgUQfnoXy5yfEinYczmGeXeu971iNhpWyu/0SlU3bzo6dIdiHRAdUfctdzackXsX0PW3j8yHyhsTjenb+roesrwGNibb9SZHJ7UmLHAi9qIwqAh48oF95Uqcdiq2CrG0YoC0pZyn0izhN+h0ZT9uQ4WPInaus/r9ylA2WAsvM6C0Dh7rJKj6iFa7MlhdKJShGm8WqMi/xZrT8jKPwQ1UIQ4U6HWUtOofq0l3v1jZ3fzxjaYjjF0HNE6BpGNap1fx8BpQwwfgVEidWZtHy4bRIxyyqRPc8IWsPQefXWUjxe9NQ/Udo7jUUfvja9e6f9U+Fd3P+0rOAsjhwE0LWuFfm0/mgk5scOU5rCXqsQMUGB6ETZdX7azzkbcxRFxF5McqQ9qQiK+DnxjaWCb+3k1RRQp4njpai7KguXIJLZ7S62hDrrtiXrxjEfs8MmcoISd+6WPeDkW7dA50IguNhezO3OjRkSt/aJn27ABSsipms9Rp0dIAyDjb3s+AWsjhucRsFh+GexO4jif1NFlNqzBOSmSW+cdwHJ89wOZWDHhDxxQBtLeP9vt+O6VdayF NFV3rbmL bRNHeBCPPC8cufkwKz729zBRKl/CW4vL0YRwk+/WNqvy2Zt79RmNbN/AQEwK599B2dPKXU1B875IxNxdPXg4EfnT/V8+WN3kozoRvGxVyI6DPW9QPldKK6+VTdoP2DmzdpPoKgPWfjTL4bE9XOkMJgqA13yxFojXreQglwY/P3YscwQEC3Dd/blkXMPKKMhjvk31EFZViJZG6U65pm5xRSOXC7YKnJmw4bb/olBdOU3N+tTJ3gsVAzwT8SBlAKsOegPm9fPHPVEoz0ykj5MjaWlUhFg6txVrzOMVdTzawczjrfVl2dxEHc5ENebEsH5ZF4C0pOEQNVSb8gdzOu7kDMRhtKaA1OmuXKlPSFidZiZKL3fOIVxdWO7qFO24f43JV3uFGXhla/yiBbA+56xrV5giPjO5hf7hG7JYUk4FDf5gUfiho1x39p602tQ== 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: Chris Li =E4=BA=8E2023=E5=B9=B411=E6=9C=8823=E6=97=A5= =E5=91=A8=E5=9B=9B 04:57=E5=86=99=E9=81=93=EF=BC=9A > > Hi Kairui, > > On Wed, Nov 22, 2023 at 9:33=E2=80=AFAM Kairui Song wr= ote: > > > > There are two different charges. Memcg charging and memcg swapin char= ging. > > > 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 entr= y 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 loo= p. > 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? Hi Chris. folio_put will discharge a page if it's charged, in original code the 2 folio_put call simply free the page since it's not charged. But in this patch, folio_put will cancel previous mem_cgroup_swapin_charge_folio call, so actually the 3 mem_cgroup_swapin_charge_folio calls will only charge once. (2 calls was cancelled by folio_put). I think this is making it confusing indeed and causing more trouble in error path (the uncharge could be more expensive than unlock check), will rework this part.