Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp904182rdh; Fri, 24 Nov 2023 00:15:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IGHa8mGj8pLO0HvpgbJHQYaSFnZh4WtCIEXPq01WeZfKM5cq8mtscbiRm+G7qCvo2CHyusr X-Received: by 2002:a05:6e02:1d91:b0:35b:10d1:a0fa with SMTP id h17-20020a056e021d9100b0035b10d1a0famr2651443ila.1.1700813737174; Fri, 24 Nov 2023 00:15:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700813737; cv=none; d=google.com; s=arc-20160816; b=S3wkjCs/KVJoQ7lmDH5u4gn47L12Vbfz1JbXuEtSDGSIRo7KGMFDR8YwIkfZKfGala 5gliVWhK5Wvx/NUhl0ihfbrT9buIII74o+kWIiYcyL6ni4hpTI/SS9kTgwwpHnLdtlOf ZVIxmi4O+EH1znoiHbwSeCUTag1hX0YUWNz40Sr16GUCXEBWoLm4NR4i9BDyE5q1OpzQ pRkGSWPJmWsNVC1mPwHn78AKh6G3KIDftUruQSRGY5Ifg5ksavuWQBVbY0E2KCWXvf3p 08x2o1o5PDKi/NmAPclnsbhQQA4xQ8+DcWCxszTqlVzbx9uluzR7V32+SLjgXOHpmvQe bIUw== 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=6oXYAGeXachCCe2/bIuP5OEv/Ub7oTlTCCZrnr5GJzY=; fh=mxM+iyYud2eqLtG0pkLKi0uG+kielFRY+hhtqFHmhjA=; b=m4R3CFEX9745RdFgWqq0p7u6MmHg8cYW7+HzgXtz4rgnpdgvlKUZ0su6AcLIg2Zrbf VqD9FVU48E8UI89XJ9/SvEyYnW2D8NUHMAZtTOEiN3qUojpWjGT7zB3+HQ/DY0ea7Uep OBng2E9BUajsRkNHXNeFFU4WLBOgxRLW2/cK534Hst6Pa7N9kVnkFbzCUkCqBOncK/vd fNCfVu1+ig8+s1yIzw0ahpOjHWtC57yTiVpwB9Eke04isCGqnrfvnkDC7jihNkIv5QLc YyqDx9humsVfcr+Fq4+XehED0Wh8WVU5HU7zBgP9ZOzfPrGqHY+evrwIwnKUTK5y4rWu Wi/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=H2EPh4l5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id k7-20020a63f007000000b005a073e0cc9asi3088639pgh.803.2023.11.24.00.15.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 00:15:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=H2EPh4l5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 4C97A80ACFD1; Fri, 24 Nov 2023 00:15:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232631AbjKXIPM (ORCPT + 99 others); Fri, 24 Nov 2023 03:15:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344572AbjKXIOz (ORCPT ); Fri, 24 Nov 2023 03:14:55 -0500 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0912B10EC for ; Fri, 24 Nov 2023 00:15:01 -0800 (PST) Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2c503dbe50dso19513851fa.1 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=vger.kernel.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=H2EPh4l5Irng4ffln7rTANrVyjn1TPTepjwmQrRqpFFoc9G8vwM9JnjaMUQPjZhWnS Jtv+9T7A0JCJTPFH1tXzI8VEpYl4OJgOqQFjoH8+4EiXG8/ohULopJ2IqC1UOcZ5AYdJ RwOQssp1b0KPG92lt8f4u/evcuaeJuBjgSjcH4Os26AXfTUKc3rp9cKHwohjYG8SbVgs 5PI2WbR8NZfr6Ck4hkQ82jBYMfePQ441WNc+IdqeziL1lkw2ROZepxNxvdbPhucW/IOZ ukcLQQlqnFkXBUVewN7B2yupHw3GY3LyDcTDWYUNj0AJ/j/Xft8NJq828J6yxm19K4y6 Cy9g== 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=VHvZT3WPJgOWzNixzNihCi3fkcm8/kzT7yV157HbIXvS0iBlT2YZ5tNVtH9iHmTTYK MDPiG70BNmYlz2RGrY+95XoQufPOfq6oxwt7xAapG5QhVzM0H8/cQXUP1NFU0kYktwNg If+FfKiSygPS/P7zx0COdgCPwvtC4cE7robAQNL5rcGOYIikVC2o0yxstTw3YRukq+XI 6+diDaEFYZpiYDJIch53r1SS7TaB5TKzCiIUtUZc1Bqr/hRYlxW1klPvdIi04DCjlKgH lAGwX7ygyev8S8/bZeeElviXV7nEwawxSQxXdFQ1tmFnLafceFKO9E3eCx+CspSmMLXJ BD4g== X-Gm-Message-State: AOJu0Yzd5FnlonIcuVFlnKPU+/qWPbvqu79WdMpqol9nWH0my+cQThk+ 66cA7Z2N+f5EvFve2ig3VdeElXhhkWpje0DPlSyv3T/4zKQ38A== 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-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email 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 (howler.vger.email [0.0.0.0]); Fri, 24 Nov 2023 00:15:34 -0800 (PST) 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.