Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1984925rdb; Sun, 19 Nov 2023 20:18:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGrnFlOP4w5UzCWlGP7pNIuzGJJFixcnnD2rQzHmfP4GU/HAapJ8orVkIMX3NjD20Z+CCn/ X-Received: by 2002:a05:6a20:12cd:b0:158:143d:e215 with SMTP id v13-20020a056a2012cd00b00158143de215mr15323152pzg.1.1700453899045; Sun, 19 Nov 2023 20:18:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700453899; cv=none; d=google.com; s=arc-20160816; b=FQ8syGbzWd2Dw6UILnspLY4DnhIVMrBK/Z2GrK5nw/ryvDmiiJ5nm6rdVe0Lir7nWL 1q7iHkC9VbZdkl52cUCvOW3W6gVwhutRJjh5nDmJ2v/CQ2df4A16Ph9nhENb4QrHbQ6k iZmYSEUwVYhmb07m4gkvKc/nGmMk0cYrZYGU3o0omVQ9vsDJzgiiY0fG9ynQgP7woFDx tNGYbFjPAZ7a2ASN14XSzZr1ma+QxqA44AUVbfr0onQtwP21U6myxsS0tXJ5QShFV7dZ IXUKGEg8ldV6wShj/d9A8t9L6QcgKc2A36KCmc6CT7rDbkmeoN+ic3Hgs+Dp9wHrrcg5 OghA== 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=VZBuDHZLGkYj26cQROvbDDI7K8Acew+cClcEl9wrau4=; fh=v/j7QEwtsj+94eMIzch1qbwAijHXRMR6IcasrHCGlTE=; b=a7oC5O6wKCeuRj/NaE6W0Rt870Nudk8kYgH2ndxVuc/TOEwq4i9w37BWE3fGDxuczY m9ne65z35Qk+TH4Vsid1eXY3LyNegL1P6ym81t0c17DnPFdFHYcxlUdjhGxyzpGm2d8L Ztx0vxsoM3Ik5F+pFPGCAHR0LQnU3rAefmqgGfJVhSk72Yn3YbeDXXvCyZ9sOxseDU5h YvT8XclUblmFJAdm1gBd5t2rba4XS3Bl03hFaQvPazcsW0TonDMwvGpEOgDKyoi9nkXQ 3lu8XnLKp5Fu++Z+Ftrgc+nO3Ztw/1c5ptlvqxumRta54x8k8RvldUyEApPOh0LMRL6h bXVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=osZUrbBo; 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 30-20020a630f5e000000b005c21936252csi5281073pgp.307.2023.11.19.20.18.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 20:18:19 -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=osZUrbBo; 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 04CEA80781F8; Sun, 19 Nov 2023 20:18:18 -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 S231815AbjKTESS (ORCPT + 99 others); Sun, 19 Nov 2023 23:18:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbjKTESQ (ORCPT ); Sun, 19 Nov 2023 23:18:16 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EA3313E for ; Sun, 19 Nov 2023 20:18:11 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1FD15C433CC for ; Mon, 20 Nov 2023 04:18:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700453891; bh=BluD7GIVPO8PrPVuaW0518p8IU0xm5lBhxJYVGvOByo=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=osZUrbBoau/5wiylWuf727gI2yFiwS42NUycYdcMhSsIPZ6zg8UN0qIUwemah4AjV 26IplfITNMI4E3CbRY6Pmd2EP75Aiids9S6m+hmJ1wadnTw7EL3Rq1fOY80lcw+RSJ HU8IhCH9TnHssqjPaut1ZbRrsn2mVa33F49gTbLor+J9T6qRcr0j1onTEBgBNOWGl7 BqsVWiMa81+EFH7w+u9p90safr3xQgBMRRk3Qo62wq4dlB1fdUP84xMKwaYD1A0DDd V4FXDgwDZh06Q4pC+W2ikhufkdaLlZIki6A9CWw9sMPNnbQWMj//ZEHRu8m5MRbywl u2HaHaXK5CGBQ== Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-2851b271e51so536168a91.1 for ; Sun, 19 Nov 2023 20:18:11 -0800 (PST) X-Gm-Message-State: AOJu0Yxjc8z5pFr/WrwqoobRtfKWwFmY1MA8U4rStJ9zaO8/hEda4LMB 7V8GXEWRi7sCSWjcp3/NL/kBpMmkJkwkrihgwR4Obw== X-Received: by 2002:a17:90b:3e85:b0:283:2652:3d20 with SMTP id rj5-20020a17090b3e8500b0028326523d20mr9197638pjb.9.1700453890466; Sun, 19 Nov 2023 20:18:10 -0800 (PST) MIME-Version: 1.0 References: <20231119194740.94101-1-ryncsn@gmail.com> <20231119194740.94101-5-ryncsn@gmail.com> In-Reply-To: <20231119194740.94101-5-ryncsn@gmail.com> From: Chris Li Date: Sun, 19 Nov 2023 20:17:59 -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.4 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]); Sun, 19 Nov 2023 20:18:18 -0800 (PST) On Sun, Nov 19, 2023 at 11:48=E2=80=AFAM Kairui Song wro= te: > > From: Kairui Song > > When swapping in a page, mem_cgroup_swapin_charge_folio is called for new > allocated folio, nothing else is referencing the folio so no need to set > the lock bit. This avoided doing unlock check on error path. > > Signed-off-by: Kairui Song > --- > mm/swap_state.c | 20 +++++++++----------- > 1 file changed, 9 insertions(+), 11 deletions(-) > > 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 entr= y, 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-calling * 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_mask,= entry)) > + goto fail_put_folio; Wouldn't it cause repeat charging of the folio when it is racing against others in the for loop? > > /* > * Swap entry may have been freed since our caller observ= ed it. > @@ -483,13 +485,9 @@ struct page *__read_swap_cache_async(swp_entry_t ent= ry, 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, entry)) > - goto fail_unlock; > - The original code makes the charge outside of the for loop. Only the winner can charge once. Chris