From patchwork Tue Jan 2 17:53:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13509228 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 4BE52C47073 for ; Tue, 2 Jan 2024 17:54:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6D716B013C; Tue, 2 Jan 2024 12:54:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D1C846B013D; Tue, 2 Jan 2024 12:54:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BBDA26B013E; Tue, 2 Jan 2024 12:54:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A80B86B013C for ; Tue, 2 Jan 2024 12:54:06 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 72F871207AC for ; Tue, 2 Jan 2024 17:54:06 +0000 (UTC) X-FDA: 81635119692.07.1ECC3A8 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf10.hostedemail.com (Postfix) with ESMTP id 8FDBCC0010 for ; Tue, 2 Jan 2024 17:54:04 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IucIqIma; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1704218044; 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=5EuDdHpwOIkkgSSbClAkFkJceQknRHYQiFDZ/42t/cQ=; b=ByROHejaM7ZTPFzk5FBD/M/Ce/KrYq9WUwLW5lmW1yPQOTQcgsldYUw250NW+ROyzV0WwB ru78uVr7Q2qG4wGg24L5bfnjg8mFXus0lTX/1DmO41FFKsEd4cl1ZOcIXB6sL7vosvhVuu mGoPAh9fnpul1C3dESxiQBo0CQ+EBdA= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IucIqIma; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704218044; a=rsa-sha256; cv=none; b=L7nITgbbW9tcfMZQ6S4apqpjqYxMP6iYRevUOCZ88AebPJb0XV7E7kVGm1n71P9rFwOx7W Qswjxhjo+lY26EhL5W2BztkgE61cIGKunIrhRMMPZNEyuvXXzv6LK1+DpKNGv3/g0Fj6G2 t1WsK4x+4rIL8t9fUgrAxBMDCSFyHh8= Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1d43df785c2so21398265ad.1 for ; Tue, 02 Jan 2024 09:54:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704218043; x=1704822843; 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=5EuDdHpwOIkkgSSbClAkFkJceQknRHYQiFDZ/42t/cQ=; b=IucIqImaCG/cI4+vPatsNiBboZpxA8Cseaf9FjGvMPdP3BGEaroPP8oZ4jJAftXpT2 A/A/nKvXCkUSaqqH1QVc2X/fc5KUAVUZSxUlEelAEGD4UQxQvFCJx0wBNx1jhBhmSTIk uiC5djy2O2gk/TArYLjLlNNFyQYcm88aq931Do9/86rym8HMSnH1I3icHqQS+InzMuAK 1MGBP1QFe0zHwzXmOjA7eTqeTLXf/MNjC6ZYKVMYlPxzSA8OHpnXCQzAY7KkIl+3fvK2 vnyDF56ieGtA0v0U8AapP4T3aCxi0YkbdEhNprFT9olLQTtpOeo1bmBU0+82i25co/nL fTNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704218043; x=1704822843; 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=5EuDdHpwOIkkgSSbClAkFkJceQknRHYQiFDZ/42t/cQ=; b=ldNQvYnI4ehMNYX+z1dMBrxDhHjL0O00XjFf8WjayH6ITP63ncoxJI/m4n2eUAxted PazlSgOdwG991G0FFmQkD88UKDxUkiUVi4Tfey2n70RfmOo+EwWilOEGyM3a5QROOWNr 4GcxEvg2rFjkoNEjlSF1Z3rsyvpj2uxK3tDtp8H96hLHt69S6m6wCbo8uN8o4Az22WcP reMtg71UAj7KAGh9ZMwmi7sMfvHvkyUd8QkrlhKuBidEtrljYIHKq3zXIn45yaixD167 QEsO2fC3wWpmniu4lDbBV943QMUcsPVsSHOEEqyH1i3W6Pkp83voEjoaOlaFPvCNRD94 gfvQ== X-Gm-Message-State: AOJu0Yxe4cwkD7tRKsKx5k2woPdTB3gLh9hXR4EofzGvjkOhieWw3xRU 5W3TJKIWK2Ty8fdJMf3fR4CHx+W4kU905aNN X-Google-Smtp-Source: AGHT+IGfDUQj/99XwdeiZZ73lh5kEPQ3dWYF+KkQDfvXFyCLAaB8H9KSj/gNI32pWe4Z84HwpG1X3w== X-Received: by 2002:a17:903:184:b0:1d0:c986:8ac9 with SMTP id z4-20020a170903018400b001d0c9868ac9mr9755498plg.22.1704218042880; Tue, 02 Jan 2024 09:54:02 -0800 (PST) Received: from KASONG-MB2.tencent.com ([115.171.41.9]) by smtp.gmail.com with ESMTPSA id be10-20020a170902aa0a00b001d3c3d486bfsm22151969plb.163.2024.01.02.09.53.59 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jan 2024 09:54:02 -0800 (PST) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , Chris Li , "Huang, Ying" , Hugh Dickins , Johannes Weiner , Matthew Wilcox , Michal Hocko , Yosry Ahmed , David Hildenbrand , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH v2 3/9] mm/swap: avoid doing extra unlock error checks for direct swapin Date: Wed, 3 Jan 2024 01:53:32 +0800 Message-ID: <20240102175338.62012-4-ryncsn@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240102175338.62012-1-ryncsn@gmail.com> References: <20240102175338.62012-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Queue-Id: 8FDBCC0010 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 4gksndtd67wcdkhpp4ukg9tkwm6xj9hm X-HE-Tag: 1704218044-209268 X-HE-Meta: U2FsdGVkX18uJ7uCpTVwiaVlvbKRzzpNp5OgwH3tTnyAotL5/pAzyH3BEZxVq3ViZlmdDLwLFjP7XTzOiFcx3GsP9xD4AlprxOqujx3L4IhnHmaEzN32Ot2OMYjwvdHA7/SBP1VtKKBTjvqSfv7bGvKNyJAFAaAQjqq3GJxNGHUE22HPkUgFYDy/ayoV9HhkkzoOU1u/+B0hOmUpgaPYmhWLN7gdlv9SCSb9EudYfkBK5RCln1tVUoceMSuiH+ihPlTrME15DmJIhGvt6asJIp/Qc+rZyWK71obvveNPsL9QJzX5TatW8To3H5CG13pw5X7u2re5C7RgRSAIkUkW4xfR9ZR2+KSyz7TYHeJ4L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xJuwwBzzESF7V2g27wnGedXURJdBV0JIMoY2rbHLl0+pN1VlLgAcoEeskmzlksE7SIJXEq0ob2WV4kNeRE3Dva5F+vOv4jzJa+20p43vOSoO0sX0mUtgnINs0oAGpIThymnjjv2+DxeP6TXxp4O1yMKscDVGTZV/NM8vk4LbK5q7QjJHbMVlb0i7Mp5m0BEV X-Bogosity: Ham, tests=bogofilter, spamicity=0.000240, 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 early. This avoided doing extra unlock checks on the error path. Signed-off-by: Kairui Song --- mm/swap_state.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index 24cb93ed5081..6130de8d5226 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -881,16 +881,15 @@ struct folio *swapin_direct(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);