From patchwork Wed May 8 22:40:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13659213 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 D35A8C25B4F for ; Wed, 8 May 2024 22:42:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 657A86B0098; Wed, 8 May 2024 18:42:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6070F6B0099; Wed, 8 May 2024 18:42:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 481086B009A; Wed, 8 May 2024 18:42:08 -0400 (EDT) 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 26E746B0098 for ; Wed, 8 May 2024 18:42:08 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DFFD8A205E for ; Wed, 8 May 2024 22:42:07 +0000 (UTC) X-FDA: 82096703094.27.6985861 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by imf07.hostedemail.com (Postfix) with ESMTP id 1309240007 for ; Wed, 8 May 2024 22:42:05 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DkJWcL2w; spf=pass (imf07.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.171 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715208126; a=rsa-sha256; cv=none; b=YxDv4rjGNq+nwobLwjYDj808MAiser73yYEqrOPLEENTkEhS5l91gDtE0wH490YSQ0C6Or /pofCD97uxItrlysawAyYcUSDx3Cc30soz72gFMYvi4yAZ3bf3UxqiErHRMlS9135aLD7M 80XXzaDklFR2eA8qZ4uT24QaSCq9skI= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DkJWcL2w; spf=pass (imf07.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.171 as permitted sender) smtp.mailfrom=21cnbao@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=1715208126; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=UYGLEQ5dG8GZxiWnoQtIB+ho0dBRJLc2akdsz5aCuO8=; b=UvYrf5tWBF30LDXe9c5zJ9JHCWo1TBJbopq11FHQcoIkIio0iW4SF3FGzyk92DimXzPVkr KmAwwiXM92IdKGl5pLaCmmtBQ/riKC9P1rg4NpS1UWpZ1/be4gDrt83WHGSSHH4/q9Z/c2 hyQXf56WCRDUIYnbZCvOLXnGyF5pwms= Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1ee38966529so10195765ad.1 for ; Wed, 08 May 2024 15:42:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715208125; x=1715812925; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UYGLEQ5dG8GZxiWnoQtIB+ho0dBRJLc2akdsz5aCuO8=; b=DkJWcL2w63M8vKKwBwR71Ok2PXZRjLQcZ6UviZ/ObiLZ1r6GRmc/usOcteSb4ms7YF PvHxKmQYd12NqWwqc1ESPyDS2p3nejL/3TgmzIVwREjmPEpp5+khIK+nkpm87d2zriwT Dz0JvrV9CtUV37Q1JAqGmIy/P+WLlvqmwWQmAyu89QJnaSOolLVEGTYvDfZ5x8VrqxA9 6ev8a3DwBCA4EodrIp4akU0vWcumJVTIv5fp9nFZrPfgZBUVFLgK0sj1dIubr/bT+E5P Ih6uRcLOJUS1ysISn5ILKywDI8/k84UGt98HaZ9Mtjq+RPyj/qGWJZd7snkxo4DUqyeD ts1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715208125; x=1715812925; h=content-transfer-encoding:mime-version: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=UYGLEQ5dG8GZxiWnoQtIB+ho0dBRJLc2akdsz5aCuO8=; b=Ra1mY3zew8nUWz9zlmMNHuciR8Z8DeVXF9iauSO0mkBIky7qQBzXbgy34sHD6yslMI BiQYvjFfJvZPcb4mINTRzUNilpoKBOx3D6hePUOSQdRPIa/+K64dDWQEZt8EE3mnNPnz PR9OcmucGyHiRNKrTSuqoBubbH+cua1a6NXvLNen6pIVQZWKEbTCj5DGLd6RaIfMg8Ta w2idtW89husvVqAHVXG4Q0mbb8h1SqaeKGBE3y42/ht9AnoNpV1I6iWwZgURWux+2ujM K/0zFlMEASte5KhmVSXvsSNtDFIviEpCwdoMDYSAYOwXoVAu8eC/T1yCnt6h1zltFKry n8dQ== X-Forwarded-Encrypted: i=1; AJvYcCW4luIUyV2cBOU6Se0uvfUIs8GRSOr2xKKsEoq82Nv3HxpGNLfTr9vDd172XxEoMNbJqv/idrUpJUvPNkSP0Lq+9Yw= X-Gm-Message-State: AOJu0YwnNi1CXobdVJM/JB6xjmioA2JCruzmfMog2/fP2CPmMKBjm5ye MN/9XbxfnTC5CWVAfeNBMMyy8er9QlkNoMzrcszBoh/cSorDHO2l X-Google-Smtp-Source: AGHT+IFAtnVi6xLor2XHGazgK0Nm3nnCaOAaL5JyBksp2vgFvFWPvYOXqRq2Ix3zEh88ZA/XgC19yw== X-Received: by 2002:a17:90a:db4c:b0:2b4:32be:4442 with SMTP id 98e67ed59e1d1-2b65fa1c4a4mr1504710a91.9.1715208124905; Wed, 08 May 2024 15:42:04 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b67126b666sm102082a91.34.2024.05.08.15.41.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 15:42:04 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: baolin.wang@linux.alibaba.com, chrisl@kernel.org, david@redhat.com, hanchuanhua@oppo.com, hannes@cmpxchg.org, hughd@google.com, kasong@tencent.com, linux-kernel@vger.kernel.org, ryan.roberts@arm.com, surenb@google.com, v-songbaohua@oppo.com, willy@infradead.org, xiang@kernel.org, ying.huang@intel.com, yosryahmed@google.com, yuzhao@google.com, ziy@nvidia.com Subject: [PATCH v4 3/6] mm: introduce pte_move_swp_offset() helper which can move offset bidirectionally Date: Thu, 9 May 2024 10:40:37 +1200 Message-Id: <20240508224040.190469-4-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240508224040.190469-1-21cnbao@gmail.com> References: <20240508224040.190469-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: teftnpz7if9dff37hzjobtqzutban4tq X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 1309240007 X-HE-Tag: 1715208125-875723 X-HE-Meta: U2FsdGVkX1+6KAGQ1tTdDbrBEj+mX5YJLns+37NYgL4P59pnssK/BfNwnEDBW5viLmvYCT2ygYooZ5obODdAg1F70CEutwZ05Y3O2PeNLVZt1puX8xXJ9eQWEF35BgNoYqn/3bI0ojqrz+4r/V1kD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0s2r+qTxDGyZNyF4k7IYIT+0795nPEDc1pGAwgnWnk8yUI3aZtZUE3vJ2ED0bzwdAlcksf/OIEN56pG2tBiOCLGFVxz3TzMLvMZ104HQ2ToFDTRr247RwwgbZ7m9LlDODgmLcu5yN7Ldq93nCF0xz6JfXn15bx+eenMyJVi+m9ZCQc7jskEzNUuZYPmGyT3+4TfOdezOgEgCoouSYU1vZkAHk8EnJAyXNHLtlpQhEvYfuNUkVAnQbWB5lgUY3gmSEzNV2CUaVqVWmp6mdtzzagG4VB9Auwa7/NnkuqxXr8tQrpGBYipnq3XjWXDFcaDVgBi++cL8w2X8RoH+ZjeRO0xIMNCCHy/MzIm44VpJ3gnOg2p6W6cNlFjgRITtQ8/McJhumdZUkCPStjfgPn+aD4QbwbysS+Q== 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: Barry Song There could arise a necessity to obtain the first pte_t from a swap pte_t located in the middle. For instance, this may occur within the context of do_swap_page(), where a page fault can potentially occur in any PTE of a large folio. To address this, the following patch introduces pte_move_swp_offset(), a function capable of bidirectional movement by a specified delta argument. Consequently, pte_next_swp_offset() will directly invoke it with delta = 1. Suggested-by: "Huang, Ying" Signed-off-by: Barry Song Reviewed-by: Ryan Roberts Reviewed-by: "Huang, Ying" --- mm/internal.h | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index b2c75b12014e..17b0a1824948 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -211,18 +211,21 @@ static inline int folio_pte_batch(struct folio *folio, unsigned long addr, } /** - * pte_next_swp_offset - Increment the swap entry offset field of a swap pte. + * pte_move_swp_offset - Move the swap entry offset field of a swap pte + * forward or backward by delta * @pte: The initial pte state; is_swap_pte(pte) must be true and * non_swap_entry() must be false. + * @delta: The direction and the offset we are moving; forward if delta + * is positive; backward if delta is negative * - * Increments the swap offset, while maintaining all other fields, including + * Moves the swap offset, while maintaining all other fields, including * swap type, and any swp pte bits. The resulting pte is returned. */ -static inline pte_t pte_next_swp_offset(pte_t pte) +static inline pte_t pte_move_swp_offset(pte_t pte, long delta) { swp_entry_t entry = pte_to_swp_entry(pte); pte_t new = __swp_entry_to_pte(__swp_entry(swp_type(entry), - (swp_offset(entry) + 1))); + (swp_offset(entry) + delta))); if (pte_swp_soft_dirty(pte)) new = pte_swp_mksoft_dirty(new); @@ -234,6 +237,20 @@ static inline pte_t pte_next_swp_offset(pte_t pte) return new; } + +/** + * pte_next_swp_offset - Increment the swap entry offset field of a swap pte. + * @pte: The initial pte state; is_swap_pte(pte) must be true and + * non_swap_entry() must be false. + * + * Increments the swap offset, while maintaining all other fields, including + * swap type, and any swp pte bits. The resulting pte is returned. + */ +static inline pte_t pte_next_swp_offset(pte_t pte) +{ + return pte_move_swp_offset(pte, 1); +} + /** * swap_pte_batch - detect a PTE batch for a set of contiguous swap entries * @start_ptep: Page table pointer for the first entry.