From patchwork Wed May 29 08:28:21 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: 13678364 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 75D5CC25B75 for ; Wed, 29 May 2024 08:29:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0458B6B00A0; Wed, 29 May 2024 04:29:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F11346B00A1; Wed, 29 May 2024 04:29:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D63726B00A3; Wed, 29 May 2024 04:29:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B1C496B00A0 for ; Wed, 29 May 2024 04:29:09 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6ED1A806EE for ; Wed, 29 May 2024 08:29:09 +0000 (UTC) X-FDA: 82170758418.17.1E9A5C5 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf07.hostedemail.com (Postfix) with ESMTP id AAFD440003 for ; Wed, 29 May 2024 08:29:07 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LVGBobmN; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716971347; 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=83K8bgM725IDCOF3GoIeML6r90yg5uTNSjeWCxUl1nI=; b=E8QuOBkKRUQg0OrNsH6RS0Ggbbq7I4EoVrGNaF/kZGdARzpShN8rfB8W4g9hJnh4eauChU XxhPKHpgVOrIKFc2KSuaDUSXhnE5v4DVHY53Mgg29F7xgPKdCz14OQ8PpzeWohPERsFmYn zdSPWd8SPzgXbNZrQNEc+YldZfaOm5Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716971347; a=rsa-sha256; cv=none; b=koaG9zNUUfKgaMKhqbMU9dxQLmNUMvDdP9gh8Fjl0Z63jH+pHmbr7RuDib6cnKXdQ+M8/g +YwfUmKJ4cnHtlPjJFkhJDSgZfELf/dFGx3kI/f+cqex1e4/+UHkwsGnjO7D3KlQTywRkt zr/praqf6ysSnBhpdfm58qlsjVBGNE4= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LVGBobmN; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=21cnbao@gmail.com Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6f6bddf57f6so1775073b3a.0 for ; Wed, 29 May 2024 01:29:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716971346; x=1717576146; 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=83K8bgM725IDCOF3GoIeML6r90yg5uTNSjeWCxUl1nI=; b=LVGBobmND3UybK3XFtObW8Muvq95st4KE75O/jWEyRJz8TkWqAWVK0akEU8gn8gu6Z AFfPN9G57dgnf4Jupy0VUwQkkA1u1iRJIegZK55EhIpaXq5CeFpPf3eUsipEGF+63Ysk DCCJwVZ6Aiier8KKgiu1aaR0J4nI7bBFbWsejqNpdAj8ZtjRsLP7HFDAxt9kgr5uRtkv t3ZZUj5AzSQZ8Mlq7cQC2LT7TH7VqIbubj+sEuV+AqMtIgsCTYr35wfWS3ptpDB2p3jW EccVWULl0JSGzwfG7CIKZS5vNl5zP4BafyZqt1oIOY9ZWZ99gZqrv/vMpE9u89Pb2gru TSAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716971346; x=1717576146; 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=83K8bgM725IDCOF3GoIeML6r90yg5uTNSjeWCxUl1nI=; b=RehWcscRMlJjaLa4DdkZXvVfqch/zd4k41pTw7dCGAW/1TgKd5+zyqSfX3u3kOfIHr WPJAUQQfsT4VCQQZI7eR9TvOG81LZAxwmUzaV99IvhybCupW2d1iV26dRDJgYEBASYn/ soj4x9s/WBkf0Yh/bEfU+HgVe87ZKjB2r5NPlvpkR7+T0T6fNpllsx/ekcs7pOyP+dgS 2Nj5W/4OnZCW++fAbSFJVDRr3HgxwOWC3INvBVoQYdKe+xuUlblFjfqAIJxFZ+zRXYzG A7MDSczmwnqgvU6c1gnyHSavIe79EsupXqvCzOcDFkBCI0cVq15ZPO9Xd8qw7KGohjpl qS0A== X-Forwarded-Encrypted: i=1; AJvYcCWz6lvXpIe31WIECi3j5S1clWvebyHKMWa6wf1foE18roxqiDef8sWXJTKUtiDfcKcBI1ceqMWoTRXwuwx7v4o/E1w= X-Gm-Message-State: AOJu0YwAgRj488OKzerWLyphR/hHGl8hz6Gc6R4FL0a/PWlOsyUz4AiW uxB/U5oFGTkhb9v9XLjEAKI6zU5uZaXXWoHJlXYpZ9lUJEGto+pb X-Google-Smtp-Source: AGHT+IGUylP38UecAp4ow7R28ofXyse8WlZ1y+8tflbwIT3kfaBZJA8cTz9JYhcDnvYjYa19Kqiapg== X-Received: by 2002:a05:6a00:4390:b0:6ea:d794:ccee with SMTP id d2e1a72fcca58-6f8f38010e9mr17376300b3a.17.1716971346524; Wed, 29 May 2024 01:29:06 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-702220d948bsm174916b3a.131.2024.05.29.01.28.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 01:29:05 -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 v5 3/6] mm: introduce pte_move_swp_offset() helper which can move offset bidirectionally Date: Wed, 29 May 2024 20:28:21 +1200 Message-Id: <20240529082824.150954-4-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529082824.150954-1-21cnbao@gmail.com> References: <20240529082824.150954-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: 37a8p5k5nkd31gypsywix4qececx4qkm X-Rspamd-Queue-Id: AAFD440003 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1716971347-875045 X-HE-Meta: U2FsdGVkX1/dO6npdj9r2Jqa/fjq1DYWQ7cAJhsV2MWPCwhT4sYsfyVHPk3XC3Xnf7kQ9Sav2PqtRLfhe9rrHX8h/t2EXMi3/gjsMm1laBkmR7TyzSzvDvU2893YMR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kx1uWh6NxWvTavyMi3ee30nYBzc1B0/6CoXzLyv920m8BwVqUizLZY+hJEWDDKfxV+IiGdw48odX9e5GN8KRU5pPhKWIhEJ3wjOwApIcF3bfRQ/Bt2ftvc/vstuAGDHd0tsgmZ+XvDocq4NodSRVnCa6xzctY0rMA7FnclmtBUw5ZcxyqMJSjhzI93IQ96qG7gd7lRtSI9dS2ltiV1blWx1S+RF1SPP85DwU5TvJ5iYhVomT5hXa2I7vsRy/ps2TYPBCg6t3vnP3bJKaKDOor+SJTLcBsOMXNbx6Yi7auehalMesq8t8lrI7GUKqUcPTkLjLNajLjusvOOUZo58E5czPlMC+0d0PrAtUt5rXBxxZVh7zRDfd1onCLn3jG7ZYfeHYA1+CjVZFfJu33Z9HEJYopBUvyCjQdQAwXcO2wXFU76jmT+CyGAg== 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 bbec99cc9d9d..3419c329b3bc 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.