Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2401792rdb; Mon, 20 Nov 2023 09:46:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IFWiHu9QVdTtpOQvqKbp+/aC3c68U8+ubv+rRbEU9ldNrbp6hHcODJoHKyj/qgfRoknn9mk X-Received: by 2002:a17:902:dac8:b0:1cf:5cf3:b180 with SMTP id q8-20020a170902dac800b001cf5cf3b180mr3878038plx.8.1700502363361; Mon, 20 Nov 2023 09:46:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700502363; cv=none; d=google.com; s=arc-20160816; b=H1EZQWNq+7UARwf1c6+iDcT4Kiwok+OgjmaN9raepNUbHnEuDmd/+pP2OXPH+A2Sum nZywMDxfoKJUyTJavXc248oxQzwy57XQUIPWIXXODcq/Ayu/AUvVOPe1Ewc0fTTRGmdQ 5AJX/Ss35QMBv42yi+WS9WVdHfKYRpL47nvnj4RkEdumH4Yn3GE3Hv6CSWZvDinlnGkT DNxbWlSm3VxNk/1c026BZgbNCZRKWpEL/DlEU+42h2eCWOhb7LyP+8FriOhO7wsJ+qGk 72oDUW08S/JjnLW+db0Z7kqnlhXm5kMhcT4WXpHpG8GK5THToEldCV3zNWy6ADnyNm/Z tbbw== 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=xWt9lB+y319LSueyfyuaUC2CZ94/re0/qOWv47dZs9s=; fh=K/LZ1BUptwrDpCNjVhfmA07Y8doOUYOQskSkVF/w5AI=; b=H3c2XKGqJj2wRwJANbHBndOxJ3JP9P1OqGTXmEW7Aj/9S27+b/tmGu6rdHigBXVF3j VYG4YmqMNoyvgnvFmXikHDBzfWYy1v4qwlNLAYgXMjLjBGuUZtzW+McZeXKl1xI0X1hc fwuZMygy52w+g6szUBQxmbU781nqqmFY9QVrfVw6cqMcpdLXAvyVRuSjfHcdhBQ0K0yt orbkv8Om1NPCtdHz4IGRkT9pfKchkC5cTd0gTCbyPldC78mOvmpAg3vtpYjgr8TfYUw1 CFxif+I2lIOo7EYzihhpQeNJv3oGdvoKySRL3HjBEW0vTWwp7KgQWN5vTTSr/p59kd8/ X5bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tYPrWGsa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id f4-20020a17090274c400b001c9abd73cf0si8062134plt.155.2023.11.20.09.46.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 09:46:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tYPrWGsa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 8CB81807FC1E; Mon, 20 Nov 2023 09:45:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231136AbjKTRpD (ORCPT + 99 others); Mon, 20 Nov 2023 12:45:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230021AbjKTRpB (ORCPT ); Mon, 20 Nov 2023 12:45:01 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EB0C9E for ; Mon, 20 Nov 2023 09:44:58 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0636C43391 for ; Mon, 20 Nov 2023 17:44:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700502298; bh=QdIwQbi78L4iTaYOXSKTeqxE+zsyBy4NQBji7YRcekk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=tYPrWGsasDFSPcl3O8bKV1fTHxguNi4I5jhP8NhpHTqaz8jt3l4rDFIWY8KLK3sXN lM7BV3u7AjHXcjs+g2v6Jh0ne7RHiFszbywARTlT2hP1wFw8UmWuVCp4a5PwFHbFiU F9CLDpaD1PrmU3FbouaXIb3wUo0JsQNsPrOezqAJZhzIb/ffDDSZcHbET4reLzNJMS YJ1M8RDNryz8KCI4X4QJNNDvUFvSWldbVqX9tp+SVOhWLDJ5ihzob7vOxOlCfb2Ydg Mnn/hz9twBuX8V4hyGKO5d77C8927UOQj+vfZSH4spQ3Trp/qsHwQ6SouYbQdSNY8p 4/MOaO90ignLw== Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-280200949c3so3122957a91.0 for ; Mon, 20 Nov 2023 09:44:57 -0800 (PST) X-Gm-Message-State: AOJu0YymUJOASgA/d+UNvewZZ1DsYO8kWGON0OipP0n0BXqFeG3xKVqE jNgZEQy4HplQH3zRio+KL7n+h0xm6VSm4XiWLZa2BQ== X-Received: by 2002:a17:90b:3883:b0:27d:4f1f:47f6 with SMTP id mu3-20020a17090b388300b0027d4f1f47f6mr6589184pjb.32.1700502297360; Mon, 20 Nov 2023 09:44:57 -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: Mon, 20 Nov 2023 09:44:46 -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=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Mon, 20 Nov 2023 09:45:15 -0800 (PST) On Mon, Nov 20, 2023 at 3:15=E2=80=AFAM Kairui Song wrot= e: > > > diff --git a/mm/swap_state.c b/mm/swap_state.c > > > index ac4fa404eaa7..45dd8b7c195d 100644 > > > --- a/mm/swap_state.c > > > +++ b/mm/swap_state.c > > > @@ -458,6 +458,8 @@ struct page *__read_swap_cache_async(swp_entry_t = entry, gfp_t gfp_mask, > > > > You move the mem_cgroup_swapin_charge_folio() inside the for loop: > > > > > > for (;;) { > > int err; > > /* > > * First check the swap cache. Since this is normally > > * called after swap_cache_get_folio() failed, re-calli= ng > > * that would confuse statistics. > > */ > > folio =3D filemap_get_folio(swap_address_space(entry), > > swp_offset(entry)); > > > > > > > mpol, ilx, numa_node_= id()); > > > if (!folio) > > > goto fail_put_swap; > > > + if (mem_cgroup_swapin_charge_folio(folio, NULL, gfp_m= ask, entry)) > > > + goto fail_put_folio; > > > > Wouldn't it cause repeat charging of the folio when it is racing > > against others in the for loop? > > The race loser will call folio_put and discharge it? There are two different charges. Memcg charging and memcg swapin charging. The folio_put will do the memcg discharge, the corresponding memcg charge is in follio allocation. Memcg swapin charge does things differently, it needs to modify the swap relately accounting. The memcg uncharge is not a pair for memcg swapin charge. > > > /* > > > * Swap entry may have been freed since our caller ob= served it. > > > @@ -483,13 +485,9 @@ struct page *__read_swap_cache_async(swp_entry_t= entry, gfp_t gfp_mask, > > > /* > > > * The swap entry is ours to swap in. Prepare the new page. > > > */ > > > - > > > __folio_set_locked(folio); > > > __folio_set_swapbacked(folio); > > > > > > - if (mem_cgroup_swapin_charge_folio(folio, NULL, gfp_mask, ent= ry)) > > > - goto fail_unlock; > > > - > > > > The original code makes the charge outside of the for loop. Only the > > winner can charge once. > > Right, this patch may make the charge/dis-charge path more complex for > race swapin, I'll re-check this part. It is more than just complex, it seems to change the behavior of this code. Chris