Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2142343rdb; Mon, 20 Nov 2023 03:19:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IFWhtlt73hXslM2DFh/GSgHNQVb68QQv8bDUD42mbEWXP6qXnCtBNmqVyMJk1r/TC4UO9mV X-Received: by 2002:a05:6870:1811:b0:1bf:77e2:95cc with SMTP id t17-20020a056870181100b001bf77e295ccmr8360910oaf.17.1700479152589; Mon, 20 Nov 2023 03:19:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700479152; cv=none; d=google.com; s=arc-20160816; b=qTQEAWL0ntV/rQVWkArveTeAkp/RD6RCgrdeiy88NDNMGTv5GnWOqTfWGerdFciiH6 VlSiMxCmBZ1sw/rvCoRjFfnwFrpFXhwRVMk/AQlvbIC6kQwj4jFQV/vaQRv8F73U471n mD8hfg5i2mhG7ML2ZdjafAvwN33CEgbswqC4Mqwy3sQlzb0AFYGhRciVLXxMhLzN5+NB fKTXANbRF33KQn4aSe5eIVCXnSbB0bsSn/5RioAG/wUOP80TIt2lLXQ1yIo3l4Ldl2am XsxIM0CHv8YwqDrAJ+kJBO+OZ5a497UwzTlYvVz0fzZ31IEDImK9FcyLxnsbq0sm1CeD fDQA== 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=GCEH2OhSh1wtb14SLQZhMNkQFOWqwz8F0y6cfbziznw=; fh=mxM+iyYud2eqLtG0pkLKi0uG+kielFRY+hhtqFHmhjA=; b=rcdl8irOzFbgUb1Ao6sEkdJyaEX7rUOYW8ytIrDB4zhgtUrKGsLU30f6e1zMv0ozbS RG7dA1W9LhQOnmiJNqapfa+Yme9PB5Sgv/vRve4SI2iIYnxDxYuTEageaXFEWWxxRg1+ IzY5i+v83K4pMFprAcnszVA7T8Di/6aTZh3qIn7TRMc7IGfn2WxTkcL6Pg3PiPUIAfY3 cXwDlOqvlU6Bqsy9/bRL3IjxgikkT1Vw+eK8r10xompOok5o+pXKqWkXy4YfxubHFGhw YS3zOAS0GkKqJzPnpS7tEmnRKW+Pj41cmAUk/Nz4VKocovEvmi0O+m/tajKZzKk8H7sg 9I6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FwiNNWm1; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id g5-20020a056a0023c500b00690228b1d45si8349718pfc.342.2023.11.20.03.19.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 03:19:12 -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=@gmail.com header.s=20230601 header.b=FwiNNWm1; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A4475805F940; Mon, 20 Nov 2023 03:16:31 -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 S233455AbjKTLQ2 (ORCPT + 99 others); Mon, 20 Nov 2023 06:16:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233241AbjKTLP5 (ORCPT ); Mon, 20 Nov 2023 06:15:57 -0500 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00C719C for ; Mon, 20 Nov 2023 03:15:44 -0800 (PST) Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2c501bd6ff1so52115171fa.3 for ; Mon, 20 Nov 2023 03:15:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700478943; x=1701083743; 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=GCEH2OhSh1wtb14SLQZhMNkQFOWqwz8F0y6cfbziznw=; b=FwiNNWm1RJ4KDnKIyZwNMjqSwyrMTxG8G3YUHCQUK0c5wVehU2GyEJUOLL5xi2tltd cjbEQPnZLM7XX08/R/jocIxDsS0drsIKzeoZ0NHmGBfZ6bn+PWD18rOMTF7gKSgD8Kpk P8RnMUqqXn85VsGQqYKRs8XuNvmFxLtEEIwf3HowSmNUf29wxgUO2hDsiii4vnbyew2a efEQrqDEYVN7gPIdNsNgHSxZ2bPcFd3uNfzlik0GSbrd6BSZ6UI8hqBqj1rSkw6Ohr8D pa0PTV7B0icW2thnsiwZwyDYZ12sBCpz52Z63ZxGyEhrtuaMTe9WTK6s5gWhSbXcmyQ7 GDuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700478943; x=1701083743; 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=GCEH2OhSh1wtb14SLQZhMNkQFOWqwz8F0y6cfbziznw=; b=rO8LhxEZtK2D+7yOIwwdXq6QTK4MgJmCnev0H05CLtek1DKvcXnPlzGYFDoJcKcAg+ N0sD0PYap+GfDfPyAmfwSHnwgSUgU+C2By4kHOJJg/BdcV7RIBuzyvaik+QOt82d58FO POMOPR1p76g1yUNjOgApKU1IhxyMZ+s1EP8di5kGQl+P2CtqTPfhIFwKXGQPUqzL+XZS jZzVi0B8dN9DXRPazBZoC4OxYIp+YedfeF6x0YrWbVryQO734+bawXk+diOjd7dKp+3x Zq7Xg9lYadnKIAsUqw1AOKE8r/iKtUbu3LcSp82wIngquWbDyVPWsljz103GPntLF0sP mcIg== X-Gm-Message-State: AOJu0YwZ2RqZgzgXpEL7eBjv7J1zgje06e3jrB/ulamFX5JQ2rkdG3Li itzQ9Gn8cR1Ls7yX2Ds78AvCY34T8I6CXW1XkLY= X-Received: by 2002:a2e:9348:0:b0:2c5:2221:614f with SMTP id m8-20020a2e9348000000b002c52221614fmr4209856ljh.45.1700478942832; Mon, 20 Nov 2023 03:15:42 -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: Mon, 20 Nov 2023 19:15:25 +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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,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]); Mon, 20 Nov 2023 03:16:31 -0800 (PST) Chris Li =E4=BA=8E2023=E5=B9=B411=E6=9C=8820=E6=97=A5= =E5=91=A8=E4=B8=80 12:18=E5=86=99=E9=81=93=EF=BC=9A > > On Sun, Nov 19, 2023 at 11:48=E2=80=AFAM Kairui Song w= rote: > > > > From: Kairui Song > > > > When swapping in a page, mem_cgroup_swapin_charge_folio is called for n= ew > > allocated folio, nothing else is referencing the folio so no need to se= t > > 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 en= try, 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_mas= k, 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? > > > > > /* > > * Swap entry may have been freed since our caller obse= rved it. > > @@ -483,13 +485,9 @@ struct page *__read_swap_cache_async(swp_entry_t e= ntry, 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. Right, this patch may make the charge/dis-charge path more complex for race swapin, I'll re-check this part. > > Chris