From patchwork Mon Aug 12 07:42:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13760267 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 6A5F6C3DA7F for ; Mon, 12 Aug 2024 07:42:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C4C5D6B009E; Mon, 12 Aug 2024 03:42:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BFAFE6B00A0; Mon, 12 Aug 2024 03:42:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE91E6B00A1; Mon, 12 Aug 2024 03:42:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 90F376B009E for ; Mon, 12 Aug 2024 03:42:27 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 348C9A0940 for ; Mon, 12 Aug 2024 07:42:27 +0000 (UTC) X-FDA: 82442800734.27.7947E06 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by imf14.hostedemail.com (Postfix) with ESMTP id F1734100013 for ; Mon, 12 Aug 2024 07:42:22 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=Oq4bQ0S4; spf=pass (imf14.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723448534; h=from:from:sender: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=o6+ZLJUP4gIVFn0Lkl5fLomnFxVaP80TbLuhIXh/Zp0=; b=UPdLVn8Gacef360n5lHA+4BkaxRW2WfPl4KtvgpBjmSrGNGDx4eRtb/dMxi8r2S5cC5lWM ojLzTqKXBge7FRkow9YWjKcDMSGH8R+8qdwUQwfvPeHd+HJmxxtfsDOUWDhifcn16Cf3Vs g00t0nzxUJkSY8lMPUBnJGQ0K1n3bdo= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=Oq4bQ0S4; spf=pass (imf14.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723448534; a=rsa-sha256; cv=none; b=O6k4fWTqcTZIqJutAhHqXb5yogg3o2LMIt7yztnQOpOT+28zJaRBtv5VsGcBI97Nbs/mGS dy/sG++ZVD6WtP19UXa7xpT5mlfRVuDmMxOAskOO1Q3pMsjV+rElf3wfO7RAK450V1DdZs s5tVLvx4hnCIAQrVAMZ+8itu0P//GUw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1723448539; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=o6+ZLJUP4gIVFn0Lkl5fLomnFxVaP80TbLuhIXh/Zp0=; b=Oq4bQ0S4sRYKmxobP1G6SuQvWw8Y7VgYAIgZ2GPgBnC1zii6a+gZLYlgssvj0VvpLBUHjC/0uvOMIRjFLt5GMDuMzqgEPf5/F5gxjJmL3gGXGx2oj8MC3DHPvNwQCLS1CVq7D5CGuHtaXZsBjuE+8qwdEcMi3f842OriSxb3lG0= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WCbAKO1_1723448538) by smtp.aliyun-inc.com; Mon, 12 Aug 2024 15:42:18 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, wangkefeng.wang@huawei.com, chrisl@kernel.org, ying.huang@intel.com, 21cnbao@gmail.com, ryan.roberts@arm.com, shy828301@gmail.com, ziy@nvidia.com, ioworker0@gmail.com, da.gomez@samsung.com, p.raghav@samsung.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 1/9] mm: swap: extend swap_shmem_alloc() to support batch SWAP_MAP_SHMEM flag setting Date: Mon, 12 Aug 2024 15:42:02 +0800 Message-Id: <99f64115d04b285e009580eb177352c57119ffd0.1723434324.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: yfphbwgg8jta6psay85fazx5booba7in X-Rspamd-Queue-Id: F1734100013 X-Rspamd-Server: rspam11 X-HE-Tag: 1723448542-582450 X-HE-Meta: U2FsdGVkX18PoreRoolrJ3oXlKl/IBk1Kz5z3Vth0wWpDCtt/3lTLOtrenpZ56DAXOdCZXs0/cvTUCx63rj2/ZojIeO0U/MWacQaj7K9sYXcFssmhE8yUFa119gIo0PIZYzGegqzlEEMH3BsLWvrChwJ87il40tx+iHL/9vceq8OoTFxe+YF668UGvLhPLowMnv1ohp1WkJrdPlNCeNhL74RAthxuD3dSnA2sW7HkaJgByZDsgcpRm/Vyy2kpn87NddzqpHrDxhIyR+KERK8xsOdlBiHNtCL84Rvb3H9tvDG00TaI4oD0r/vxMH9juTOtKJj2pQgP/dhKTetmDYCml8Ozkxd2neDjPqFiyMo6/QKGdwNvyEdOEL9hituGfp9wzNoBuOc/DyJWmEyZG28GIUyYqKcl3K3gVQ05OciKoJs8d+mtCii95v2kuy0GG9hQhE6uRWXR3tQeLfCJuPLFwt9/6EZ6/fSLdBoAflewcpL47bFMv4VtjGx2INSKmi9uA+JBv4TLxBz+Q5yBCqdtiLFnZuDJ1EhTZwcvE9XMOyBvzUbadCC5B0PhqK7OBH84c6QHvzeiFPiw/r1ZMUMYeOLDUq4t03gtOOxoU4efftarpEFhCSC6LUyXIr1l3anzuhOgajpQx0ZSbaEeF9idD3akwsufhEk39abzJ7VLvklOi5fc571NmhamU99iE/8+GJ5Jg1Z4Dxad7dqwvzH9DgMmGCcBpJMr+JpohBEOyQQIlvRDThb1o/pdYYpULq7p87SdZZByJF59RoxnJFQsw/sihB6wBoBlkoc503OwH8zJTTmizDMpo20Gw4S/vwPP8a9Z82Ue1RoBcBMbZWZKz6hrxKLs+ir4G8jZgufc+35vsJPQ0VjsyfCH+OF5pkrMNt5NAKyv2OAJlAfqJ+A2sWC0SeRlTLbiJ50zOhV0aW8x9hYO1TWVIxWzIUrfMWwEzsORZBZ/S2TyI1qWex V6iWSNvm YE8GOUV/zuUqbnL3TMQbrHwLgtuqzTyxtpuIg+oDQz03l/Z7c6lzBn4U7tERPJ9H2/t09uYR7KQTl+QOVxzw/kL5Yx9WOxaIj1360/5SI47JjxZ9nYc9yvvH8h2+/QwMVe4ShpdZYHQPZk5wF4AjZzZvV2Oi3222DXOEO5RM+wI4bBlkk5nb4lDX2mLhxBRshDlpJp7bs7z9np8OVaKBOT8MHx7perumhITezvzASmKhkXt70d/tDSp7LfgDdkuLHjGGfHZb1bWcShHZ88jDNnHNNtCVKkTeldTCwUU3/Q/A77m+/Px7gCH38An6hfwjLZiCx1L0HyFTKP/jpKv3hDjsSQg== 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: To support shmem large folio swap operations, add a new parameter to swap_shmem_alloc() that allows batch SWAP_MAP_SHMEM flag setting for shmem swap entries. While we are at it, using folio_nr_pages() to get the number of pages of the folio as a preparation. Signed-off-by: Baolin Wang Reviewed-by: Barry Song --- include/linux/swap.h | 4 ++-- mm/shmem.c | 6 ++++-- mm/swapfile.c | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 1c8f844a9f0f..248db1dd7812 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -481,7 +481,7 @@ void put_swap_folio(struct folio *folio, swp_entry_t entry); extern swp_entry_t get_swap_page_of_type(int); extern int get_swap_pages(int n, swp_entry_t swp_entries[], int order); extern int add_swap_count_continuation(swp_entry_t, gfp_t); -extern void swap_shmem_alloc(swp_entry_t); +extern void swap_shmem_alloc(swp_entry_t, int); extern int swap_duplicate(swp_entry_t); extern int swapcache_prepare(swp_entry_t entry, int nr); extern void swap_free_nr(swp_entry_t entry, int nr_pages); @@ -548,7 +548,7 @@ static inline int add_swap_count_continuation(swp_entry_t swp, gfp_t gfp_mask) return 0; } -static inline void swap_shmem_alloc(swp_entry_t swp) +static inline void swap_shmem_alloc(swp_entry_t swp, int nr) { } diff --git a/mm/shmem.c b/mm/shmem.c index 4a5254bfd610..22cdc10f27ea 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1452,6 +1452,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); swp_entry_t swap; pgoff_t index; + int nr_pages; /* * Our capabilities prevent regular writeback or sync from ever calling @@ -1484,6 +1485,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) } index = folio->index; + nr_pages = folio_nr_pages(folio); /* * This is somewhat ridiculous, but without plumbing a SWAP_MAP_FALLOC @@ -1536,8 +1538,8 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) if (add_to_swap_cache(folio, swap, __GFP_HIGH | __GFP_NOMEMALLOC | __GFP_NOWARN, NULL) == 0) { - shmem_recalc_inode(inode, 0, 1); - swap_shmem_alloc(swap); + shmem_recalc_inode(inode, 0, nr_pages); + swap_shmem_alloc(swap, nr_pages); shmem_delete_from_page_cache(folio, swp_to_radix_entry(swap)); mutex_unlock(&shmem_swaplist_mutex); diff --git a/mm/swapfile.c b/mm/swapfile.c index 6de12d712c7e..1caeee676696 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3604,9 +3604,9 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage, int nr) * Help swapoff by noting that swap entry belongs to shmem/tmpfs * (in which case its reference count is never incremented). */ -void swap_shmem_alloc(swp_entry_t entry) +void swap_shmem_alloc(swp_entry_t entry, int nr) { - __swap_duplicate(entry, SWAP_MAP_SHMEM, 1); + __swap_duplicate(entry, SWAP_MAP_SHMEM, nr); } /*