From patchwork Thu May 2 08:49:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13651435 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 283D6C4345F for ; Thu, 2 May 2024 08:50:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B17DB6B009C; Thu, 2 May 2024 04:50:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A9F906B009D; Thu, 2 May 2024 04:50:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9195C6B009E; Thu, 2 May 2024 04:50:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6D99C6B009C for ; Thu, 2 May 2024 04:50:32 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2A2E9160ABB for ; Thu, 2 May 2024 08:50:32 +0000 (UTC) X-FDA: 82072834704.30.41A6170 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf09.hostedemail.com (Postfix) with ESMTP id 38B21140031 for ; Thu, 2 May 2024 08:50:30 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=j9Uxt1pC; spf=pass (imf09.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.179 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=1714639830; 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=6hBewYHOfG4Y6OYspQ+5fYKJoHCclq56Vlvet/Fbb20=; b=otRnElAr8VxuMA/bBcn2hKp6XomaVbF+V9Lykr8n9JeUr5unoY77mOtAs0KxfKsxMCXPJg 4miHZrB3KGl0btXijH7T78+FnR2LD6qUfeTPUaI428GRp4uVse1dU+2LhZ5sZhyO7gKiiQ +sBgfoi9MXYq0y2EIK3dkEoxdhAhNhk= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=j9Uxt1pC; spf=pass (imf09.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714639830; a=rsa-sha256; cv=none; b=K1vEGzQDdBFqIwO1XmJMoe7aQKgrt3cTtWhmjpf7fcEeuQVR+1/f2fXO8oXu/cG0zbVbZC 0Tc4M3QWM7xyosSsXI/KlVvlA8YiFdQ5+NKANeVWPykSH42Zlm1imPlhJTvgTHNDsLK0Eg 97CsxlPxfrTDF1deByPWhXNwHMX7fSg= Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1eb0e08bfd2so40093265ad.1 for ; Thu, 02 May 2024 01:50:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714639825; x=1715244625; 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=6hBewYHOfG4Y6OYspQ+5fYKJoHCclq56Vlvet/Fbb20=; b=j9Uxt1pCOw+QoLT3CnncIKP5xwchi0YR4R16U3DN+zTQ6pl2tpoj8SPMgemJeVVY/s 5Vd2SAkPT2mYBrvFtHkCaWyDlYHE+Md1pxVYXxdLDKoU/OIx9L2y2gfXAYax02a7/rwB mTQpuFdFqraihzYCWp69z49R2g1ZIpnN3rTBnLex3cNQebXzJftSkhtxhq4SSdR72eJJ KgV6o7rzABTuxeCXvjwI282HhVwVmBxDQoMZPaUVr+nQOz9gNP4Xo7XqCm8tAigRUueY lk4tpf0RpYw7Yv70qjwO1LkU6vyd41uaVG+lzfsDQTthQWieafxkpTf7Qv+ix0LPydLG Ut4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714639825; x=1715244625; 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=6hBewYHOfG4Y6OYspQ+5fYKJoHCclq56Vlvet/Fbb20=; b=QU8SFqhiM0GhNXviZHXtjbT6KdPGvrPyoR/7P2zT4n3+H6VKswvztJfYVvjFmd7YGE uwUyNm5+assvOS80b9w97MwaC/yTGe6BT6rdc4EpEWW6Se1VQyfVYuIlsmlVp8Z8bGHq KDZAQYjWKjRTaKlIra3xyFGYulBaRWuwonmL061C4VG6XVsmg0A+n+e6CRW2I+LyNoPW 4yjk9pCBiFdoeaFW1NKWQRYMFoDjHwe8ecy3J0xrTHvIiSq7iVomoRqBd3tvaVvtVgGC qfMRUxZKVxbaSrMDjMCjHOuzBRyDH6WUZHdqFD0oGjSMXnb36NWlBZswS/+Oh5XquJ2/ dDhA== X-Gm-Message-State: AOJu0YzF4GhNOTLglbtMc7PiY7ETJUmsqTD1wUvAMPABskyPmS+kkihW EwGnX5uUtm8v6iizuDNgqdm+yLia4rJp0uuPXy+Ha1nDB8UqTytQTgpxwWdCWZc= X-Google-Smtp-Source: AGHT+IFwlpgfcGprAqZdcSgM1C0FcJW03lvq1L6XneBaZZ8VDethVtsd8vo2+hwdnNRHKZqs7qydvw== X-Received: by 2002:a17:903:298f:b0:1e6:40f1:93be with SMTP id lm15-20020a170903298f00b001e640f193bemr1586793plb.27.1714639824889; Thu, 02 May 2024 01:50:24 -0700 (PDT) Received: from KASONG-MB2.tencent.com ([1.203.116.31]) by smtp.gmail.com with ESMTPSA id j12-20020a170903024c00b001e43576a7a1sm737712plh.222.2024.05.02.01.50.20 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 02 May 2024 01:50:24 -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 v4 09/12] mm/swap: get the swap device offset directly Date: Thu, 2 May 2024 16:49:36 +0800 Message-ID: <20240502084939.30250-2-ryncsn@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502084609.28376-1-ryncsn@gmail.com> References: <20240502084609.28376-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 38B21140031 X-Rspamd-Server: rspam06 X-Stat-Signature: 4kiap4xrqft5e19eqeu79gqi14hpfrhc X-HE-Tag: 1714639830-366073 X-HE-Meta: U2FsdGVkX18+hbPeENBQe1Ex8NwrwmADKYQRMZrA00UHBuedbtaum/H8/QcPN55BmnXyfD59mMCFzg+g86ucIJo4nBQQH3bbWKGXjOQ6//SReBr62ZhZi1m0vBCUBEyB+qIUj+8Kkr0xVHu+7y6HG7/VM6ptGqhzuKeTGM+ihH3ctoBxQojn7i+GSyKt6dc09zf58TARVKeIi8IgHNvgpMZu94LsA2dfmhohTd1UE4d6OlnOxMwt/sIzJgsWILzEy661RIH9X2RrL6qZjEJdI6x5Cd/05Sii69xY/AWUXKeggMKPN5J++oaNmWSOC52nebch4iAcdgwl9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ajBPAzVjKonJmFoRnXdl9p6SJHBnL37ZLjlNE7z9Tbdp38N79CtVHQUITy0e/ZeQ9DyiL4D30Oi4t2YrUREMo8vDRxw50ak4X8lwmwdhe77ePlsharYWAQVYZ7rmTOv7lonTmESt5VEGC9DXtOLkxF9an6Y8fmhLvIhZ7YyteOBhzF6W1jSmJs3cnvImJLG4zfclORWDml6hA5302NF3n9zEaKIh 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);