From patchwork Wed Apr 17 16:08:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13633570 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 B20E4C001CC for ; Wed, 17 Apr 2024 16:10:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 389896B00A0; Wed, 17 Apr 2024 12:10:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 32CC46B009E; Wed, 17 Apr 2024 12:10:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A54F6B00A0; Wed, 17 Apr 2024 12:10:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id EAAF66B009D for ; Wed, 17 Apr 2024 12:10:10 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B81D51C12A6 for ; Wed, 17 Apr 2024 16:10:10 +0000 (UTC) X-FDA: 82019510580.21.F1D3262 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf29.hostedemail.com (Postfix) with ESMTP id E44CE120028 for ; Wed, 17 Apr 2024 16:10:08 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UoHnlEPt; spf=pass (imf29.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=ryncsn@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=1713370209; 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=Srg4dA9RNSDxQazS93yF50nbI2bCxfJ5XfNZ+0IFk1c=; b=1rY20inqIvHzyoPx+wAsCZYRvsX4ooLSO0BzdNRMIkj6tYTKmzeQm66AZ4d9T4TpaYZJmr QLlysjckxcts3TvvujV2oBHzk0SXrke+8F4NNTcSUpsWat0FoPtw6E0GgAY9CzjSCHJmS9 p537Jujah5ZIlAk2iF3J0RzXvljV6pY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713370209; a=rsa-sha256; cv=none; b=SFwXbKP2akbdmB6ufmuitVX6Vzy/T7WRgv6/xeuxXvd3XC7JGOSSAEUvzL+ssIZ5IjEzZ5 9aZzTdvLs8A/4ByuLJQPtfOiuI0Lbx6SckDlu/rHI2/aVRTouNYJq7j7Hy4e6lgNpZwAWe rrJmTQu9xu1yq+ek9LXSx8oBbkOHqFw= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UoHnlEPt; spf=pass (imf29.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6ed3cafd766so4757144b3a.0 for ; Wed, 17 Apr 2024 09:10:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713370207; x=1713975007; 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=Srg4dA9RNSDxQazS93yF50nbI2bCxfJ5XfNZ+0IFk1c=; b=UoHnlEPtvVmMaOAgrPDVT+GVH2MtfrsfKpwCqPoJxoJ1vlQ3mjP4FRY31Fb3uNQrBB zsho1vhpdkNSOobYgt0GrdoevEOacL8LNUAjb+PHhIK7njZRoNFGKESiB3KvnQTFMXYk 7ltPrrtm8e18QCLZpP7AviIpf4eH0zNPQY4tdz9REBupUBtFLVJW0ppkLAmjAEEu4Zfk j21pEc4x8nfoXX5SI5QyxV9c1c2VDeg3zXYUNplCE4nMvttYs3o54SCO6mpaC1l2iw+2 BdLswpFf8iJXGllbEyUrklm6oimxuiU9vYxL0Iolyx/S205LuLTJlIIxEgROh1ifEjbj WihA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713370207; x=1713975007; 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=Srg4dA9RNSDxQazS93yF50nbI2bCxfJ5XfNZ+0IFk1c=; b=vSS9qBbN/QIIt62slMHayOBrYz/+7PJxa9NCepkXYHdB/lGBff+yKVd/xdHfwdV3Ie 3igHZwWXYr3LUrNSYqT+t4Xv0Cm2I/jIl4cvuWVvIoYVzUfuGGuc06Qa5Ko2Mm7Xtsn3 IgHlLEdHpj58lsFJqL3FQtcqdE+/eUR0r5IcmEzy/dEgeekNrhfA8NzsdknXpKFYx7AD pQLnwCjM7lRE9nPZ0YItoCzChLmx760e8NglKtmKFiWWbFmdqHyBis7GmtybsgelVns6 CweZDdLwT/3/ko8/pCRa1kzxLTM5uyc673z5vT8JF1nTGTgbyoOlc2IKvaljTB169ZkM rMMw== X-Gm-Message-State: AOJu0YwXTmUmN31wx136vpwDcAVyvb3QwLsesVgeS1JzX/twQMYidhbd Bc3OvzcRrmxIYENVlmFkcT4d1Vgmzskd1dBdfafn/iNVgB4KYzeTKAjl3/fuxjvkGA== X-Google-Smtp-Source: AGHT+IE91IYOeoH7Co4FQPgzNtFkiFYWeecE7d0F5J2GxZaKlBCPwnRQBB9VWoRDd1SCyPSrNH5WaQ== X-Received: by 2002:a05:6a20:3ca4:b0:1a8:2cd1:e437 with SMTP id b36-20020a056a203ca400b001a82cd1e437mr102832pzj.11.1713370207249; Wed, 17 Apr 2024 09:10:07 -0700 (PDT) Received: from KASONG-MB2.tencent.com ([115.171.40.106]) by smtp.gmail.com with ESMTPSA id h189-20020a6383c6000000b005f75cf4db92sm5708366pge.82.2024.04.17.09.10.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 17 Apr 2024 09:10:06 -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 6/8] mm/swap: get the swap file offset directly Date: Thu, 18 Apr 2024 00:08:40 +0800 Message-ID: <20240417160842.76665-7-ryncsn@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240417160842.76665-1-ryncsn@gmail.com> References: <20240417160842.76665-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: E44CE120028 X-Rspam-User: X-Stat-Signature: ko4bqo1ph45h4wa717ohyqiifxqbpriz X-HE-Tag: 1713370208-296816 X-HE-Meta: U2FsdGVkX1+WIKZK3gjTRqnRpSmf9IK2PdDLCfbptcQ2Ugz+r2r52GFG3gbT/p7S5813FSP+pENn2WPV9Ga2V2VcV1+rQX/okGPXXGrvtptOmpJUuzgqxLB5UafcMc2RZMoUbIMV5vhe2BAFKF8fbAi/sFuH4hs+UjXy/lCc153kZ4i7XknHnZgfI0O6s9/pqSs4mUbjhJvWUAAW3JpZLK4iHUt3Ith6G7y/ooFiMn6L6wvHA6HEFXnfpOP4wG8K9dLr/A+ai9pKBIRw7utO0hZ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5cvY2pM/2Ytg1ksPzX+2SNjw9vC7z738HLV2hHIsJEJcifBN8noR3SpOF8DKNr5TfJ/x8vvIErpqJ6ptLrNHMeBIO/hNkEk3RJ/y2+khPwRl6l/UKS9xGytGMTyDD7lg9/CZ25APxMz/MiVOM0YhqxZxpUuxddDPnlwPhPIFSVPn4qsaDxEaMsjNL4Fp8e2tHKHTTpcIESHjAFfsYN5FRgvz4MdU2MGkouwdZTd5wk4Mkh3sJHS86TejKA+ZJ3ExkFTx9umNl+AHM6aH 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. Signed-off-by: Kairui Song --- mm/page_io.c | 6 +++--- mm/swap.h | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/mm/page_io.c b/mm/page_io.c index ae2b49055e43..93de5aadb438 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -279,7 +279,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_file_pos(page_swap_entry(page))); for (p = 0; p < sio->pages; p++) { page = sio->bvec[p].bv_page; set_page_dirty(page); @@ -298,7 +298,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_file_pos(folio->swap); count_swpout_vm_event(folio); folio_start_writeback(folio); @@ -429,7 +429,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_file_pos(folio->swap); if (plug) sio = *plug; diff --git a/mm/swap.h b/mm/swap.h index fc2f6ade7f80..2de83729aaa8 100644 --- a/mm/swap.h +++ b/mm/swap.h @@ -7,6 +7,11 @@ struct mempolicy; #ifdef CONFIG_SWAP #include /* for bio_end_io_t */ +static inline loff_t swap_file_pos(swp_entry_t entry) +{ + return ((loff_t)swp_offset(entry)) << PAGE_SHIFT; +} + /* linux/mm/page_io.c */ int sio_pool_init(void); struct swap_iocb;