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 156F4C197A0 for ; Mon, 20 Nov 2023 17:45:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 92CAB6B031F; Mon, 20 Nov 2023 12:45:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8DC406B0320; Mon, 20 Nov 2023 12:45:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7CB9D6B0324; Mon, 20 Nov 2023 12:45:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 6D58C6B031F for ; Mon, 20 Nov 2023 12:45:03 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 46847802D8 for ; Mon, 20 Nov 2023 17:45:03 +0000 (UTC) X-FDA: 81479058486.12.41FB8EA Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf27.hostedemail.com (Postfix) with ESMTP id 3E38A40005 for ; Mon, 20 Nov 2023 17:45:00 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DVwbr7CE; spf=pass (imf27.hostedemail.com: domain of chrisl@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=chrisl@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700502301; a=rsa-sha256; cv=none; b=YrbPlGyyfIt0torDj30xfDXWGwOaxZPs087RqoL6mQg+DaS9oUJe/i02i/GVNaaHHb+G6V IVDe4F0woMAeUnDHfb9Azgy2pvrnVAMi4wcsXcPNW2+ChH4DCaTMi54ghw70e82Nj0WqJV wgKSxzishiBN/NSzbsEUXmb/Dc5uMLQ= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DVwbr7CE; spf=pass (imf27.hostedemail.com: domain of chrisl@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=chrisl@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700502301; 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=xWt9lB+y319LSueyfyuaUC2CZ94/re0/qOWv47dZs9s=; b=vCPKlGrByw23wc3PQ3dpV27w5oXGkIzu49+QyWzGdnG9Azg3Bn5hPnzIPJ3WcklfGYBj61 GlekQpm9J8xaut7O19HDDGv0HIKqDM7XSDzgial5UYdP4PosO43pByXL+pbXMu88E2BqXb kQfbgm0mK6LlIJ+rYuQJmHY110Sck1E= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 871D5B80976 for ; Mon, 20 Nov 2023 17:44:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4ADAC433CA 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=1700502297; bh=QdIwQbi78L4iTaYOXSKTeqxE+zsyBy4NQBji7YRcekk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=DVwbr7CEYIoJNcl+2RghRF/2dn1Z3Hho3mI/U+Arz3jwLXMHsGkrFGkCZpArX5YBr a8O0tEelaaiHNibBni0jLK9zawmqwHtbRfn5lvTaZ164kSV6o/Q8VeIjzFJ6en9GxN upDXkcWRgAZbq4za27Y9yzkHfsyfpSlH+DkT1Mt3W1/Bxy+wPcUBRi1hCjU8PjXePV oPdQ5tphKBwy0DMi6+SGvd9SmJPFC6hv5j9ZrI0mqm/10tidaN8b3sNv11Dv0WTTPv GmZHZT2c2yZpBSI2LlIVBvp4o0+W3tjjc81NP2qAKe9HQvo5sgRTMwO2ZNkRW6+M8r pEhOvaold8ZDg== Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-2839b418f7fso1956434a91.2 for ; Mon, 20 Nov 2023 09:44:57 -0800 (PST) X-Gm-Message-State: AOJu0Yy4AP1I2IJTGHbN6D+SI3uiXr/nxWARxVM1UZXIx2MdokTsllmZ NPWZK/QoWkq2/s4lUUTjIO7ypLNEdVM4aaPOTo/Vlw== X-Google-Smtp-Source: AGHT+IFI+CQqJyVWsvXC9ndBboiTV94uGDMRbrItRTKY1+Z0K9hsVFu9dAGsddeT5wb1+o5lmC6o89+AgC3mEm0M9ec= 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-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 3E38A40005 X-Stat-Signature: ch533kxadhx76z5h5yw5n73a498cz3w1 X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avByc4ViLzhHKCylBlwDVhKTg66ZDPYS5IUia0dt8mFdNx7GSeWgtw/yDZBQw/mGOf7A7XLZvwjG4ZaodtP0Lu/r1YxiTJQ1tYeoRm1DRILU6l3HW3w4/LeNkRgOTH9mvzXqm+wwJa7MrluvxR0eWjGeiraEIm0+1wFbM8W0P3oidnWAq2m/Vd5T4m3sHEPEr5hs= 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: 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