From patchwork Tue Apr 23 17:03:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13640393 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 33480C4345F for ; Tue, 23 Apr 2024 17:04:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B3ADB6B014B; Tue, 23 Apr 2024 13:04:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC3A46B014D; Tue, 23 Apr 2024 13:04:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93C876B014E; Tue, 23 Apr 2024 13:04:22 -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 6F7AE6B014B for ; Tue, 23 Apr 2024 13:04:22 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1708D140530 for ; Tue, 23 Apr 2024 17:04:22 +0000 (UTC) X-FDA: 82041419964.13.BA1DE6F Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by imf06.hostedemail.com (Postfix) with ESMTP id 28FEE18001F for ; Tue, 23 Apr 2024 17:04:19 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=MrmhWJPJ; spf=pass (imf06.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.216.46 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=1713891860; 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=KNG88VEX6ymli+8A661y92lZCXehoPGwKzjIttUG4iQ=; b=vGIVuijv1o0PP4pnFtDRzeOnHzCkuElSTf1vf3kPraNs5nGcv0kSifs5D2opYqEOxYJKxU r96z4oMyzRLzTV5Af11OX1GiAdjctyCSCOYYRV9+dRDYkZpcqG/HuM+fwWRfeA2Z9klPQB xWdfUHNouE5e3PMBYxAt+S3k/kY5s4A= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713891860; a=rsa-sha256; cv=none; b=FfZgLTAMb+c8a/AZZqA/kDWlJW8aO7dic6+EQvIQR0jcIA1Yw1+juvvjdW1caC+TWB7R0h yaJQ1bM6M4A2hhTeDpxVTWMEHOn+HGvjv6biarCfGVMwzSFOFnVPjuC6th02l0xkd6JLiK 9oc90VXc6ymK27e9zl+0tmH7+JUnW70= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=MrmhWJPJ; spf=pass (imf06.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.216.46 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-2ab1ddfded1so4913063a91.1 for ; Tue, 23 Apr 2024 10:04:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713891858; x=1714496658; 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=KNG88VEX6ymli+8A661y92lZCXehoPGwKzjIttUG4iQ=; b=MrmhWJPJneAPuj8Jo8OzWbtDypEGqXxFxWNIGQT/kpha5Z9OOG1puI1gQnzvTHUIIj 1gshyACilPtf3lZsrHNb7R5RpwvaaR7h9NPrMKDre+7ut+ejlpUxZoCL/7P4MLUJk+hq Cg9B8nvWs2oBRPJZK66ALs8ZAftplngHqsG428QV6OqHip3bfXbDTmj7h/BaMNuEQOWp yS0SDRzTW4uwBDFfX37wGAEXMV4qRjhGDAHMe0XlSormNFolL+E2v6AqG/TmdFZWj15d iDOoUZ+KtCzvoBHAEtVIEhAeJBvaX3phSJqY4uBOdFVyC1c+Ojz8x9b8f30x/sas3E3V FP8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713891858; x=1714496658; 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=KNG88VEX6ymli+8A661y92lZCXehoPGwKzjIttUG4iQ=; b=BYzAcwYFNMfEKQ5K1MA937VkVWBRlTHCyBEQTvFUU54jYKDFLx33ALhqciYnFjTbWl B+pHlShbNj0OIqbhRR63mZWA02Dz66O4Hy9rWHj53XVZaht9sn6jxmTbD752+4FjRxfl rKrc6kBpoX8Byfo2L+fzKbu+XvtFbLlD8AzAncr9g7I6aHY0loHWp4swlZMCHq8cIlod w6tqDbwWZv+EBsIOpHlxXn07KQfDI/QANYvZ11vMxM0XsmbtCqWw7tkYsj7QSUlYeo5G SeOGreHxSDbfiRL/LakmD2KpblHTKx5AQFGFExXEoIkZhfdqeqWwXwEnivewlgDL+9NL CYrQ== X-Gm-Message-State: AOJu0YxsglhZ2uY+K+EsNO85kyR6spXrK7rUvi5SqVyfhxhyIhEgScXI TzDqfMJ4Sg+YjGthaG9iWzGhfehaNp36gJWnxWCK9JNh9unCBnsl8pdYc08z8MrI+g== X-Google-Smtp-Source: AGHT+IHXKQ3glHiIimSKVos8NC6ThIL+D5to0mzqdpKPEwEZ9osxyRN208oepV+c07VYuM6yym9TLw== X-Received: by 2002:a17:90a:7847:b0:2a2:981b:2c9e with SMTP id y7-20020a17090a784700b002a2981b2c9emr14886163pjl.36.1713891858028; Tue, 23 Apr 2024 10:04:18 -0700 (PDT) Received: from KASONG-MB2.tencent.com ([1.203.116.31]) by smtp.gmail.com with ESMTPSA id s19-20020a17090a881300b002a5d684a6a7sm9641148pjn.10.2024.04.23.10.04.14 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 23 Apr 2024 10:04:17 -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 v2 6/8] mm/swap: get the swap file offset directly Date: Wed, 24 Apr 2024 01:03:37 +0800 Message-ID: <20240423170339.54131-7-ryncsn@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423170339.54131-1-ryncsn@gmail.com> References: <20240423170339.54131-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 28FEE18001F X-Stat-Signature: yddyccgozsnhj9rtqqnumzbrzu9e6k99 X-Rspam-User: X-HE-Tag: 1713891859-990637 X-HE-Meta: U2FsdGVkX1+xvKmT0yYJ/IEDHck5y6+EozebalEdccZ1/BDnikfM6Z9udJPqNL40xdHzWyXrMCnWdbSvhJefKHhTpRBygkWoDbW1iNzmafhJKStW7SOjSR6l/4WbQ+dQBVjGDIGDr/L0yBr5ohVneYIvU+yfwFVJwuwqb0NriDrKMNTAspeyk3KBP8O5Lyaub/vp11wfM8Zsf++GT8893O2IcEgAD2n8WHmFEbctHobF/r6ZDYMc+BHsgiZx9cZpyDearmbsYhqjZtY2IXNCuqRjBXS9u8Xr5OgeQQcgEzHCXNrBr1Uad/ZmNEOY0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7GWdniCxLqi0Pbdk4yBq8VOz3dob+Unc0pfgl8VIgLSmpVMaEZcVwuMUJHW3SHeBj08HnUzNQq1rcwWvWR/oNQCmHeV9GiO7u+UxHoDmmO4f84FbJO8kvbiRyCeQ6+2YtiyNPt0EYDIZlS1KpTtakeIG2hmFcZxrVupC07pzXkijSunHgNCChc6ICexVb1oe98d04lbIfYroYPHFc9qlc4CPEVGHV5ONl4le3CMHhbX8ZbMtI2DrnukYA+cP 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 ae2b49055e43..615812cfe4ca 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_dev_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_dev_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_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);