From patchwork Fri May 10 11:47:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13661472 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 D388AC25B10 for ; Fri, 10 May 2024 11:50:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C83B6B00A4; Fri, 10 May 2024 07:50:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 682736B00D0; Fri, 10 May 2024 07:50:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 518EB6B00D1; Fri, 10 May 2024 07:50:34 -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 32AB96B00A4 for ; Fri, 10 May 2024 07:50:34 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id DA2AC1C196A for ; Fri, 10 May 2024 11:50:33 +0000 (UTC) X-FDA: 82102318746.18.6FB3492 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf12.hostedemail.com (Postfix) with ESMTP id 07F8540005 for ; Fri, 10 May 2024 11:50:31 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ACkwGVvZ; spf=pass (imf12.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.182 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=1715341832; 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=fgJiNuxuO3ugEp246cwKh8ZiD+bhu18k0EgRZTmr/d8rjdP9rPEmwIzZJJewyyRPgmhRa0 qCj7/fYvAtDJY2uuhFt2oUmlgAUEJuf8444ob5w9jeFR86kYYiwnYWbF2qWsId2A1tbzKb esSl6gzyWUanemX8av5zwB9zptF9xhQ= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ACkwGVvZ; spf=pass (imf12.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.182 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=1715341832; a=rsa-sha256; cv=none; b=pBj8LBJ9sqio5jmnrFB3rUmCwPfv3Se8+GU0zaitiD/mGOiz/82adyqQzOX12BmzxY1sum xMh6NuDIw3OlJG4fK6HtzOvqPoOmjEHueEMg1UdPjEFNVukxxNDXqZVuTi7sBz9f/Utwn0 1gbI33JZ8gURInBNj2vgQ6xojRJRP4Q= Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1eb24e3a2d9so17136245ad.1 for ; Fri, 10 May 2024 04:50:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715341830; x=1715946630; 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=ACkwGVvZ7gXC/XH7YLf9wkPYWziRD9AnxHTWu4I4o6kcQ/L/tJCk3+idjs3HTxDzCu EoX+Y+x0T+0T4IX1HrTO+WE/KDHhH1Nradn7nYd1LJWJQIB7rmIzruncbAAZjkfEMy7c qinUXxgS0KRBHKs20RTdEpotwFJKvg+5C3vqxmLyWC262xnlTGAWeBTA1UzXqJmDHkKZ YrjieNxlaiX6YtUt55m1FtXrhSW+Kke4lgLVJ4ZRJtK/mzTbtNGXyvTWOJredaZWz2c9 cWKEQq+a440jmA+95quh2w8wBVrc/SGl80Vbfx59KSH5O1obihRicIxqVFnEl6/qF4RE 0lDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715341830; x=1715946630; 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=Q4eiZVz4glYWhQAAisxLwkvY/3aq9PiDsIBbTaADJ4HMUNgRtnW4AdcdDPqVoCna0K 2z/QBvke42v1ETjwUXACE5FUD6eK7DqPJQF1WVTIchOLD/IiEWwhs7TiMRabF7nMymep 5xais7/SzbvNWFC8Q0Z0rNKr70rbnq+YQrxIvZpnz+uirl4RH3G5oPUih6MYP6pZJOTZ 1F2YoPcSxvMwQOwPw+oqt8ett+ppSDJH4JG/JdHpl21RHL7BRCxcHcCGF76DNzu1FoIs 1/j4G3ENSxW3H4barZM8CAyZIHMStVMLlgfMjSdCg94UQ16ooFAtrQtg8qot+W81o/DD Ouuw== X-Gm-Message-State: AOJu0YwQEhliWUPqsqOQI3arUEcrKPjMOiItUr2N/0cWmZsYeA4/icmi UBrHypNJ5t7wC5bspa4Na82TSs4tX6HG9bykCJckCjvAHhwoaWZghq/62KwFmglllw== X-Google-Smtp-Source: AGHT+IEEg6dE9/dabWmlAkHlSPTCpPJRcc/k2Jrk8P/i3G+yAdrIEP6CyhaxILwoXp+bzQftvYAMNg== X-Received: by 2002:a17:902:ecc7:b0:1ec:7b0d:9eb9 with SMTP id d9443c01a7336-1ef4404e44bmr34221205ad.64.1715341830560; Fri, 10 May 2024 04:50:30 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0c134155sm30183825ad.231.2024.05.10.04.50.26 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 May 2024 04:50:30 -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 v5 09/12] mm/swap: get the swap device offset directly Date: Fri, 10 May 2024 19:47:44 +0800 Message-ID: <20240510114747.21548-10-ryncsn@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240510114747.21548-1-ryncsn@gmail.com> References: <20240510114747.21548-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 07F8540005 X-Rspamd-Server: rspam06 X-Stat-Signature: tb9fqkgx4g7raywindss1bqh63j5n9zf X-HE-Tag: 1715341831-341522 X-HE-Meta: U2FsdGVkX19pjnwVZ8DIyZ5Y1LcQHn/zRwCBNQ5TsR4mq4sBQUNBFKvhsV69N2YfbCwsy4qC1lfm49VeRrIm4RrZKgl14Alx7mcr56S1J+lRl/0jO/rdQ82jbaIQVy07cvoGcLh5Aqdv3Bb6FL0t1ms7La9NjNf22SnN0i6kewmJYwJkmZi9QYwyRFr6Kz7ZFWl5fGhCKj+hktOPSHClyZQ3TfxT1UpLs5P3Qr8hAmWglJtzviR1Mg9evyK5GM36YrgBQpGRj+GpNrl3+82NruMv+YF3vxMKMUzpq803YAgEuw5WAP3ebFlhI5m+4P8CQnb6PYhyZ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mTy3cTzWe6m50L/n/4C3qxL3GvzKfgy8iqTRSP6NDBSVn1jybogTMRelz8jgDE1+QdnOcAdcccJULH9bnZ+XaRICb4Zg1kyla7rsVEWKgYgTKcVPkeWLqmHUM5IdzoAAOeeIeml8G0XMNovroJr05avx8w9H3oDj82DdHC6EmV7/UJq63ZBBOmjd08zi3SIBUpydsgw1Nru0uic6ciFdBTayq1G33cZZHpiUrhVW0JKQc0NVN0QCuVFl4wqww== 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);