From patchwork Mon Apr 29 19:11:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13647562 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 3F47FC4345F for ; Mon, 29 Apr 2024 19:13:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD1DA6B009E; Mon, 29 Apr 2024 15:13:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C81236B009F; Mon, 29 Apr 2024 15:13:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B49256B00A0; Mon, 29 Apr 2024 15:13:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9766C6B009E for ; Mon, 29 Apr 2024 15:13:20 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3DF511C0A5F for ; Mon, 29 Apr 2024 19:13:20 +0000 (UTC) X-FDA: 82063517760.27.D22E35B Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf29.hostedemail.com (Postfix) with ESMTP id 5C45812000E for ; Mon, 29 Apr 2024 19:13:18 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=XWfRgnK5; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.170 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=1714417998; 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=54tBEeL3WLk/xvTe7LsTeIRT4DqSpvAgzssbqgMQpYw=; b=TEexZQOg2n/zqt1Um5KEpC+L6J8f9+2zAI84zWSkhUtlIi7RXVYDfYJcronum+Ij0nFH3c GmhLobSA4b4xE/E/01JfZ1SOhkPmF053ZmDLSSQZJDCvwLuoApXKd9sgIKsTG3Ed+OV/ik El3cNLU9BCvn3S6E9n4aUsTZWfRQKj8= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=XWfRgnK5; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714417998; a=rsa-sha256; cv=none; b=xB/MqKoC4oDddXKJPlr5yFOAR5cx9pi4DZSP+gns7Yh0X3TiHiknzdFxRgFjwTVUu+GgBM DWAovDCZ9UpOo1EgZxwKhLoQQOS+exVfAPE5Ai2jfZ+DM0KlkDZWYn/L7W4xsYUv2w52je I4GFNSKpKw1Obf8636ykeSfrNKupguo= Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6f3f6aa1437so1619480b3a.3 for ; Mon, 29 Apr 2024 12:13:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714417997; x=1715022797; 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=54tBEeL3WLk/xvTe7LsTeIRT4DqSpvAgzssbqgMQpYw=; b=XWfRgnK5aSMhFgz1Finb/ZOkBdoGlC76CJEX9vX0U7K32wF1GOWB9p5rL+RFSS6EQj kNMSVt/hvRR0yHBPhriCUV1SrficLvqsuoLX5A0ocG1YDnV5oHqtdax1qT0vJJbTP2uZ +5bKj7jSBqA7BMjuoSbQgyhODANMaDfHgbHQlEkeYO2ibpNrvy2YtLgCcxRLabzHkN5f uWQ4erckYXbe8cma+ksWRTZVyi859dgwsApTL9xrlX1zrsk5pxH9IwNW+7jQ2n6DKwba tXtKFj0yH4v0FsMAJGmjGS54KhnvgZDMkqVk+8rFPhC1VBbmK/HrYwEwJJwKDhORCZQl wTVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714417997; x=1715022797; 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=54tBEeL3WLk/xvTe7LsTeIRT4DqSpvAgzssbqgMQpYw=; b=KIio3s75sb3q6eVReBPA8rll7+KcUv69ryv5uIgwdzPP+eB5/hPZbC+MN74BU6EBcy bSOToBw/4sE8G1IHhf0JDR36iXaxrh1ndVvFocBvbJeFg7lecrzS3X4J+UC8Tdmqc6HT EGEj0RwYD2ZHx9vrY7cknymlXTuq7B/q1D1iYTToyPGY11f99EJQ+/J2OpSGcoQ5KFh6 TD6NwdV8r0xPi9HoURTJ4V4iVF1jDdQFUw1LXlhw/uHM4eHBWqRi97yKzdAXFjkHOeuD gEmIOU6e6TlvCV9uB/ECaYSRWZZkbZJhk+hOQSyCfTXmgmxIXmRSmtUMv/nFAZQRS4TD 4Ziw== X-Gm-Message-State: AOJu0Yw+cSfXxUlzTRlWMG8Y/xE5xCIlTH7Xs3ooD/QWtbxc9mHahq+O kCOtQM5X6gb5URMZnfCS/dfLx4kNDd5cm7aBmUfZ8HQlFu9h0h/EzHdBPpkba9w= X-Google-Smtp-Source: AGHT+IEkukKzFyXvcUcUCBcg+pFFl4Blb7KQzrcsvkEmMumk82TvVZAkxzMjSXvoKBD5ECjHeKmIeQ== X-Received: by 2002:a05:6a00:3a07:b0:6ec:ea4b:f07a with SMTP id fj7-20020a056a003a0700b006ecea4bf07amr12308186pfb.34.1714417996587; Mon, 29 Apr 2024 12:13:16 -0700 (PDT) Received: from KASONG-MB2.tencent.com ([1.203.116.31]) by smtp.gmail.com with ESMTPSA id e10-20020aa7980a000000b006ed38291aebsm20307988pfl.178.2024.04.29.12.13.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Apr 2024 12:13:15 -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 , Hugh Dickins , David Hildenbrand , Yosry Ahmed , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH v3 09/12] mm/swap: get the swap file offset directly Date: Tue, 30 Apr 2024 03:11:35 +0800 Message-ID: <20240429191138.34123-2-ryncsn@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240429190500.30979-1-ryncsn@gmail.com> References: <20240429190500.30979-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Stat-Signature: fy71jxxjmbgb5m9wkob7fxhc37kumk7t X-Rspam-User: X-Rspamd-Queue-Id: 5C45812000E X-HE-Tag: 1714417998-149830 X-HE-Meta: U2FsdGVkX19GYK8kh0cUNL8xtgoE8HB7zb57pN61VuJoP1jewkSH79DJZI4hrj1ytgq1VLyNHZiEd6Z4MEC01Jl8kJ4qVUz1oDsRFcBHS40OPqv9eOpyfkik2+LACGsF241Iadi9y2qJiOVelAdJMq65nmcL3lJb1e4rnxtbIvODHBTAo2wZ+3oIkSw30+Ht6rVmYpqr/+NznPAtwMK8mKHAm4efLLTzJ5yESKxSsTsrxZKjUpEkKpy4w7IerBtC3XxSwR6nYi3IUi202zqvIOCwfw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pDMK6As0lzr53qTNmVR8FyYVMTnw7lp5WZMI8FPOGo+7G3oS8WneP0h0bTKiFNa44Hv0lj2a5iZwgivjubKbt8Ima4+Z6WO8izqeewP8PHMbrSf3XuRurEzgIK7if/nYKRCZOp8g9fFjPqZNBzRb9es2ZOWyXG6AVQP2xQArxPClbl8+0PoIQv37PZZZWrSPmyJxQWDqweYttvvnlEig03RRsAU5cSE54LDEctmOKH+LJ6ptDO9UruDe2eub0vAbBVfto7zOPHhHk 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 file directly. Need to include swapops.h in mm/swap.h to ensure swp_offset is always defined before use. Signed-off-by: Kairui Song --- 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);