From patchwork Tue May 21 17:58:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13669616 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 C9498C25B74 for ; Tue, 21 May 2024 17:59:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68D356B009E; Tue, 21 May 2024 13:59:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 63DEC6B009F; Tue, 21 May 2024 13:59:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B7E16B00A0; Tue, 21 May 2024 13:59:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 29F8D6B009E for ; Tue, 21 May 2024 13:59:42 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D02A8A1310 for ; Tue, 21 May 2024 17:59:41 +0000 (UTC) X-FDA: 82143165762.14.0C34E48 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by imf26.hostedemail.com (Postfix) with ESMTP id F3CEF140005 for ; Tue, 21 May 2024 17:59:39 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nglIiw6c; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.171 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=1716314380; 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=D1huxSjfPNpI2elfAn7WJAQ+EPp79T3Zke3qFamrARc=; b=ze7N/SUt2vS6BAT5WKNK2a9PQkraelaXE6eXJfXcid1OgT6hZthNesrb5J7ROYOc5jyH2t ts9oATJvGRguzkmKzi48VjgOdWR85dtkafgqJscPr7bOPbntN2WkT281jm0CrDqzZoybZp 5B/DzQCJtsCJPGKC/KES3gFv3MZhpFg= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nglIiw6c; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.171 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716314380; a=rsa-sha256; cv=none; b=ZAJ1KpQY5vrjgi9E++4smUjG1ksgdTfkIOeYlC9dDbw3kNF3gPh7/kHKx9YDJGEDCbBn3K 55aVgOFr+0ohr2c1BcwfXTwmserSq7+VDXGJ5YI9XX+xjXDTl6y2j5uffxPMdx6OZeh76m 95ZF7It2Un/p9XbOzpNN1zopufjbkos= Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1f0537e39b3so3292045ad.3 for ; Tue, 21 May 2024 10:59:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716314378; x=1716919178; 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=D1huxSjfPNpI2elfAn7WJAQ+EPp79T3Zke3qFamrARc=; b=nglIiw6c6EtynG1XKslFcxFaFdlv//4Ry34k2bGy7G0wI39YHVXSOjSexUHKnzKUPl h0NKn8GLnoD7R08py0SnbwPpjZy4EDNNxYnOjX/eufEEvTV3Cjvn+LTWr/Rvly7MOEAx HZJUox7F/ZCPLX0fDLdup9YGaBJqvwYKNKF2lVJofXImx27glH8NsI3y57v80J10DQFc 69EnH6/sQUP57xvZOlhHN//y8loQqjkUUfP1HXSVJJGfLNWBBxbmJsBQRTJ9sOxnh0xI xcmElMA5QnoJ7oRooHTGpPXPmQXYcvZPS5DtWroQae6O+XsYo0Iob9ME5IVvAAFhiiGH 5SkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716314378; x=1716919178; 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=D1huxSjfPNpI2elfAn7WJAQ+EPp79T3Zke3qFamrARc=; b=txenX6iwWzOWeNtjWmlYwyEzM11+xthANTGWXKU5YRqqkCeMv/UqV4uFsozxQUYyrw xTvoPgpLnjdKn355lSgO7JsxSexG6AMBoJyL5Etkidv296hjN7NYIPt2qalm5EOcwXqs sYccFa3r4idi1MHL6jbD6k6h+TvHRhr5WSN5X6b8kgXQoysLH4jmXhBvi5CIDTx+eHA9 Bcnxp436jE9lmaKlmGLdOLw0rdxAYAdg24XmlSgUysUrx5bkKULi2gmApJM1+gUc8a/k 952Di4eDJe2Rp8aWhtKpkr/QWDfyj/RxM6NqafLAc0w2AUoFIqjVD4eUngP3+vo5RaQg ZKzg== X-Gm-Message-State: AOJu0YybJnoGo0JhFI1cua+jCtxQtEhA3cf/4v3N3oVa6BlZQTQzN/6I H6G6hJZik4PJhLyVP5WFj2oRjxbdtI/IJy0ea7pMAHVo1HLfidp4t/SzkP6NcOg= X-Google-Smtp-Source: AGHT+IFhWVOawISt67dDcpWfcLwWNuJAcHjeZXZi5aR2zc9zllf3tQdQzGB28iJi3njxKzYTcZWE2A== X-Received: by 2002:a17:902:db09:b0:1f3:1026:2750 with SMTP id d9443c01a7336-1f310262acfmr25409265ad.61.1716314378510; Tue, 21 May 2024 10:59:38 -0700 (PDT) Received: from localhost.localdomain ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f2fcdf87besm44646935ad.105.2024.05.21.10.59.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 21 May 2024 10:59:38 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , "Huang, Ying" , Matthew Wilcox , Chris Li , Barry Song , Ryan Roberts , Neil Brown , Minchan Kim , David Hildenbrand , Hugh Dickins , Yosry Ahmed , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH v6 08/11] mm/swap: get the swap device offset directly Date: Wed, 22 May 2024 01:58:50 +0800 Message-ID: <20240521175854.96038-9-ryncsn@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240521175854.96038-1-ryncsn@gmail.com> References: <20240521175854.96038-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Queue-Id: F3CEF140005 X-Stat-Signature: bdywuzed7wxm8ssxi89qihnfdhwnh3sz X-Rspam-User: X-Rspamd-Server: rspam04 X-HE-Tag: 1716314379-513433 X-HE-Meta: U2FsdGVkX18GAQmJ59YVHtApPDChMYf0KBFsLDqa0uHAyjJUGqEnSseVjrZbYzhnqNHdStySVpZc0YsKCIuALDNUvW6HkrypQIrA5Y5WytJNzUpw2qkeIbzrxNKAkEv3j5xrbm/ANvRnU6YdsAaJSesGBfq+KJipAmD2G1ckMHsNKtpwkTRnbYz4eH9LYvTEvnAg5A7q23LW3mn2uRANjAbtAIXAqjhBeTuO6gi+9VJZcW+oG/BMJweKQxYU4hr6IWalGQv/UCEFcErVY8GPk+tdgVlpZbXCNbB7h7xuH0iVzALtriKWU1AHHLfBO9oxkoMcO6awhHCf00zJIwYPbR2RM7quJ9OXrv+UlbGsB8VNqmeMECMPHD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4jz7aWQV6fNYn4+72H1/73bztIqDWjxtMcd07WuapaJIZFzHv0Dh43nv+D/EXDdlzGQijF6rNQKmWum++0TItPl5Zj/6R04AXDumqeJkhR45/n4HBTg+1K5AKqsYsSTwEjOQ7fBDLjLi/Lh7B+kLUmTv4jonDEX3pS6+9nnc70H6jO8byNiaUvxfoJH3y4gw/kjjUaaG2nT3XJhmFcCRb1pTnTV9S7gK1zzmIvGbCzEL1UoPaAyliP4SB21BD/5X1ryKY4I9J56Eg== 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 folio_file_pos and page_file_offset are for mixed usage of swap cache and page cache, it can't be page cache here, so introduce a new helper to get the swap offset in swap device directly. Need to include swapops.h in mm/swap.h to ensure swp_offset is always defined before use. Signed-off-by: Kairui Song Reviewed-by: "Huang, Ying" --- mm/page_io.c | 6 +++--- mm/swap.h | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/mm/page_io.c b/mm/page_io.c index 46c603dddf04..a360857cf75d 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -280,7 +280,7 @@ static void sio_write_complete(struct kiocb *iocb, long ret) * be temporary. */ pr_err_ratelimited("Write error %ld on dio swapfile (%llu)\n", - ret, page_file_offset(page)); + ret, swap_dev_pos(page_swap_entry(page))); for (p = 0; p < sio->pages; p++) { page = sio->bvec[p].bv_page; set_page_dirty(page); @@ -299,7 +299,7 @@ static void swap_writepage_fs(struct folio *folio, struct writeback_control *wbc struct swap_iocb *sio = NULL; struct swap_info_struct *sis = swp_swap_info(folio->swap); struct file *swap_file = sis->swap_file; - loff_t pos = folio_file_pos(folio); + loff_t pos = swap_dev_pos(folio->swap); count_swpout_vm_event(folio); folio_start_writeback(folio); @@ -430,7 +430,7 @@ static void swap_read_folio_fs(struct folio *folio, struct swap_iocb **plug) { struct swap_info_struct *sis = swp_swap_info(folio->swap); struct swap_iocb *sio = NULL; - loff_t pos = folio_file_pos(folio); + loff_t pos = swap_dev_pos(folio->swap); if (plug) sio = *plug; diff --git a/mm/swap.h b/mm/swap.h index fc2f6ade7f80..82023ab93205 100644 --- a/mm/swap.h +++ b/mm/swap.h @@ -5,6 +5,7 @@ struct mempolicy; #ifdef CONFIG_SWAP +#include /* for swp_offset */ #include /* for bio_end_io_t */ /* linux/mm/page_io.c */ @@ -31,6 +32,14 @@ extern struct address_space *swapper_spaces[]; (&swapper_spaces[swp_type(entry)][swp_offset(entry) \ >> SWAP_ADDRESS_SPACE_SHIFT]) +/* + * Return the swap device position of the swap entry. + */ +static inline loff_t swap_dev_pos(swp_entry_t entry) +{ + return ((loff_t)swp_offset(entry)) << PAGE_SHIFT; +} + void show_swap_cache_info(void); bool add_to_swap(struct folio *folio); void *get_shadow_from_swap_cache(swp_entry_t entry);