From patchwork Sun Nov 19 19:47:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13460660 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 63633C5AE5E for ; Sun, 19 Nov 2023 19:48:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE4A86B035A; Sun, 19 Nov 2023 14:48:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D91376B0366; Sun, 19 Nov 2023 14:48:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE4D66B0368; Sun, 19 Nov 2023 14:48:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A97F96B035A for ; Sun, 19 Nov 2023 14:48:18 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7D74C140331 for ; Sun, 19 Nov 2023 19:48:18 +0000 (UTC) X-FDA: 81475740276.20.75233C8 Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) by imf13.hostedemail.com (Postfix) with ESMTP id B43D320009 for ; Sun, 19 Nov 2023 19:48:16 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=gtprQfLK; spf=pass (imf13.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.161.43 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700423296; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xjzoOYVfaQZliXw2umUqNXWj2wEYGvE1fLa1+gbge5g=; b=SV2JcTKixnN09m5/AqvWPRz/56Hs7USpDMGfOQWXFHgFhqPPKVRHQFCydEOWyhNxxcda67 MboEYHNbUu4XNbzo8C5rgspYjKzjiXFWbJmyhtU5CJtbSFvJpTCkh2NsJMZ5Ac3DhTdLIs 6PEuvbOoiSI1U5dFdPV2pK07yn+1qro= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700423296; a=rsa-sha256; cv=none; b=xfKwm17Yz1/yiDGBivoR5yHvFFyxPp/IoqXHko2LDozrYt7NpeHDMNIG6SS8SQ3NXHo40E vVIaA0Dqs8C4nhvGnxoIccuDYYKeFIhhP3qCZicBZYOAozKPLPEZHkeS9o+jT4eGDdoh/l Km/s45vo5d4fTrr7NgWVq9xlIu0OZLU= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=gtprQfLK; spf=pass (imf13.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.161.43 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-58a737957d3so2507045eaf.0 for ; Sun, 19 Nov 2023 11:48:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700423295; x=1701028095; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=xjzoOYVfaQZliXw2umUqNXWj2wEYGvE1fLa1+gbge5g=; b=gtprQfLK3WZaF4GFD9lLJkd6SKRLUqvlC/vHi0XUppJXAirr0Y1bOiFuJBWWc2+2bo IvplgFSREU2YtRM9icpFO2SPG8VU5eV6abQzJd7rHiZ80fMMZCKUSbA4kHu9Qg9PJe6f wzIGcI419pCWdaDDOYt/CY5RKPbFmdiyQmlZ0tAFYAe4Kr5hnBKR3R+jBUbns4C4hQxY TOjR1CycLwaEJpJNQyFO3yHa6u470fthi3wnFUCqiSL6mio442QLO9qozQ1MAQbDlRj+ Tmgm3bUrKmLNMPxa4M3AQpbMme74Rqy8WVH3nLOuX+XOUIjtnoYU73IB+XQcytEw8267 /7oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700423295; x=1701028095; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=xjzoOYVfaQZliXw2umUqNXWj2wEYGvE1fLa1+gbge5g=; b=Skf+7jS8nGRwn3QcprJkO+erSJKPoR9yEVSq1hs83AJlNNPRSe4jT/M6HOJ18oj6Xy B97PTkOgbzRu20NpHqe+wV+ZRUebPQ1vNhSioSdd6ylbNNKgvNttItjtNBfHAHqdN+5i dk47B8lLiF2lXWHY5S2cmZyoMo6EBW34/pxtcpvKtlAMt7oTiqYUTkY7536gLtUCt0ED fyVbeF4N/fCP0Iart7AHssSKlvlO2w8GIoMxbkftdwyTFLDibLPkM/wDQgmFwV1za0LN pBZWaIbLZAuYnbbcqgErPI2+k8w2tSnq9YDtwDk6dGOjacDHFF179QDOy8ryOjHdDPRg IqBA== X-Gm-Message-State: AOJu0YycYyz6fyZOSaETNYY5FF3ZqlqNdc8z7sMwxGQB/9w4c7mWgIUo oDqhlJYdKFhHUhxn7+y84Eiiny7waxycKLco X-Google-Smtp-Source: AGHT+IFQHR1l2ZzyKI4Xa9NdFiIiGKaudZGQta2YkNoMRhm/wHLbj2a5Jpev7P/tpTPzm9ZFNWym6A== X-Received: by 2002:a05:6870:3b85:b0:1f9:36fe:fd0e with SMTP id gi5-20020a0568703b8500b001f936fefd0emr1616531oab.47.1700423294901; Sun, 19 Nov 2023 11:48:14 -0800 (PST) Received: from KASONG-MB2.tencent.com ([115.171.40.79]) by smtp.gmail.com with ESMTPSA id a6-20020aa78646000000b006cb7feae74fsm1237140pfo.164.2023.11.19.11.48.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 19 Nov 2023 11:48:14 -0800 (PST) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , "Huang, Ying" , David Hildenbrand , Hugh Dickins , Johannes Weiner , Matthew Wilcox , Michal Hocko , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH 04/24] mm/swap: avoid setting page lock bit and doing extra unlock check Date: Mon, 20 Nov 2023 03:47:20 +0800 Message-ID: <20231119194740.94101-5-ryncsn@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119194740.94101-1-ryncsn@gmail.com> References: <20231119194740.94101-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Stat-Signature: ugmh8dybc45f4aw94eimef68wnej6965 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: B43D320009 X-Rspam-User: X-HE-Tag: 1700423296-243463 X-HE-Meta: U2FsdGVkX1/+hZKdbUoD6f8w2RbT7bSALdRG1rSiyxBGQYyA3T61npBQjr27jgStuMOPzxnO46hehRJgt9Zx9TBB7cjtM4YA1nesahst504IDMmhWjFZiRJ7aUHnRNa/PQl0/+H3XfqTIigngNQbvVlojpjN+m5SXvqFS7yBORQXChhgTPlyhlpX/tfAlnB8QFPuz9WYchvza0YhkyvYs/LOhCgYP1miLzCCB00+jjxfYMYEuOVNBX1mp++FoK76OlqOF0i4PnvtOZma2cNj6+jBUsmlZ+YjF18lCA70EoLY1BMW8Yd2JjUz6fc2IuWBT41cE3cyqs7nODgv+SiSMRvCNTZcSj4Vk/llhSq8PQGXwnPNX+K/ZE5fjKpWHpPeReBetW58w928PKTzz5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8gMH8IXap4xj2WmJ4A/FanGcNgNpuNbYcnpLFPyjAdTtNgDXXBtOFscQ08+1FDzgPMYMmZyP3TKaQOnf2dEqowQMuFBTbszz92rxRhzcBM1BTG3E7oHFjc32k9N/T+CwfTbpU9Fr3tTvDg== 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: 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 entry, gfp_t gfp_mask, 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; /* * Swap entry may have been freed since our caller observed 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, entry)) - goto fail_unlock; - /* May fail (-ENOMEM) if XArray node allocation failed. */ if (add_to_swap_cache(folio, entry, gfp_mask & GFP_RECLAIM_MASK, &shadow)) goto fail_unlock; @@ -510,6 +508,7 @@ struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, fail_unlock: put_swap_folio(folio, entry); folio_unlock(folio); +fail_put_folio: folio_put(folio); fail_put_swap: put_swap_device(si); @@ -873,16 +872,15 @@ struct page *swapin_no_readahead(swp_entry_t entry, gfp_t gfp_mask, folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, vmf->address, false); if (folio) { - __folio_set_locked(folio); - __folio_set_swapbacked(folio); - - if (mem_cgroup_swapin_charge_folio(folio, - vma->vm_mm, GFP_KERNEL, - entry)) { - folio_unlock(folio); + if (mem_cgroup_swapin_charge_folio(folio, vma->vm_mm, + GFP_KERNEL, entry)) { folio_put(folio); return NULL; } + + __folio_set_locked(folio); + __folio_set_swapbacked(folio); + mem_cgroup_swapin_uncharge_swap(entry); shadow = get_shadow_from_swap_cache(entry);