From patchwork Thu Jun 6 11:58:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13688381 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 60B32C27C54 for ; Thu, 6 Jun 2024 11:59:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B2B956B00A1; Thu, 6 Jun 2024 07:59:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B03416B00A2; Thu, 6 Jun 2024 07:59:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 954B66B00A3; Thu, 6 Jun 2024 07:59:23 -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 7327F6B00A1 for ; Thu, 6 Jun 2024 07:59:23 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 2E874A0AEA for ; Thu, 6 Jun 2024 11:59:23 +0000 (UTC) X-FDA: 82200318606.19.7886B35 Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) by imf07.hostedemail.com (Postfix) with ESMTP id C751240012 for ; Thu, 6 Jun 2024 11:59:20 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=MJejOjNZ; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf07.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.118 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717675161; 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=o5pjG+XJpg8uvpOyj3LZoopMVj7n3+rVaRa69RLiHo8=; b=j4d5iRnyaBVpwdYD2/3oVrPxmpNyzaGoCU7FMEtCknjPaN5KV+YkrshVZtLoqN1Zvs0Pmu Mn4KxXXUziy8RGbIKWt/ZGuFovi2DhGzKlB+Ad5s28LHlG3bwu+Ul97n65jPFLGCBM43w8 tC2MGoE+TvatFCRa5J1tIxPp+I7FSO4= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=MJejOjNZ; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf07.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.118 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717675161; a=rsa-sha256; cv=none; b=xAgMiy/Rl1H2QZw36KES8Gj1qOSSb4WmNjM+Pkx/kCBUIS7K5jcK1RYhnwCTAWSl4Jw0+i ai1OB3hziLLK079y681mFfnFtjZj/ohuQpBsgbl4vz0YnBWUOKNMm/M5LwIEaLxsuFcilo SpYUqTN6hlRgbv0Y0P6Kf7aZQItN9xs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1717675157; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=o5pjG+XJpg8uvpOyj3LZoopMVj7n3+rVaRa69RLiHo8=; b=MJejOjNZG/SXzwGDbC5r2mj+D4SUY6IM8mgFNQtzQZtO+gnSaNddtDbXD4TaA2IOMCOEeTBa2Vi/qmughpBZDAxoyFDbursHWolksm/4u70JNlgwy5K7LCrbRZtUA3bR37Pjf0QrFNEjlaGJGhKfODZIQ+9IH6N0JYMWyVJIATY= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067109;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=17;SR=0;TI=SMTPD_---0W7yDX0a_1717675156; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W7yDX0a_1717675156) by smtp.aliyun-inc.com; Thu, 06 Jun 2024 19:59:17 +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 6/7] mm: shmem: use swap_free_nr() to free shmem swap entries Date: Thu, 6 Jun 2024 19:58:56 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: C751240012 X-Stat-Signature: axwni5ya6uwgbagydx8c8ofg4ncu9onq X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1717675160-784252 X-HE-Meta: U2FsdGVkX19R2XoL/CWV9DURLgs3qq8Unxi33xflt8G1Mw9NmAyajmSi18OfcNVoBmJQaZW4G95Z3q4+9SE0IfUGv8g62bbDOS4R528j3tV1BNjdRvnmvWDsG7ebLVUHe+2gaF11BDkvyOkXMnvwRwsyZf+62WU3X4Z4FyaRpCy0fT6Kcq8OUUgP+FqfmOgLMi2gbqo8eESaEVSQnmOxQykWP0x2cUvcLYnIMvQA0LkBghzI/X/yTJra8PGwx0hHCh0AhW37qkV3QGoJ8uOP8ahEUIZSrQ2CmEJG8dgEeTLo5H28RBJPFKwdlkm1ndW0Pm/hP3vbVH7O6gbSdJflCCDhBQON/Vj8gauc58k+apLJpb0xc5kD+DAmUTD5Hvfjw1e9SXyZPs3j3kK/8SaIlpQ5Tpeh8e811wfd+0qy2UwJP/Vb5Jp0AtWHHAfgSf5echj1yzhfUOpYtlyyBOI3qzPhKzDAHL0gPTZusGvuUu5iZQrNbSnKnOX8HU3K4cvPcjXOC4E10zFQCO4M4OFWMHNz6nOVOtisuQ9BIwDUyunLExm5IJTO4p3YN1WFEURwo9Puez5L1rSp30BsysFXBmfjmdCFLTuqI1XRo+0BNhS6WykAUdETCWTgVlEOSPbtS19rBw7TbIMamQDgwJBsYTTqQ1xOsrgeaf6QXMXfC/IjsYaDZxi3SCn+bWm+OaugpA4fiQ9awfj2D3lwxFgkoA6zDC9qOzrq7ID3wQ8scsimb9gX2R7Gl25y+KRdAKoAHXgQ0cocHAVMQ6tqAlmAfBty1SreOnRgzXwRN0ZCZhLQa2650AxQscdQaRN7dhoeJX2ld4Aigm0Q/FRC/DzmlZmI47REawIQWU2DHycgmykHTQVMmI/gTDLoGlJj0H3VKbx2IkcIHPBGPNgZxa20JzvA4WvFnOJZWtU4wlc+FwzNDLcW52k5mkGpHRhN5Mnc6uxKE7CJiwobO/cqxiJ WVPmaOXz vqjQklO4XQZHCjR57OI8tpUTPZ50El+9Mn8BUxLg+RhQESbE0yhDeuOnUA+5wZs5HN9loLerabyDF23D80uEECQh0JSMXTX7Qn9G3TyPltiBOL+gJ+PjVVleRway2sGjIsyT0o5p9p7L1FGHvzfkIlrmrp8ejg/2PQ3g5OpzZlwDYW+hczZ8noOfXWk+w7mWJi3zymkfTeoGWiPylQUxshZJHgT1iTixS/CTz9h00znJfN2XyHK3eDgZYyQztp16NMCbiDdAONNFk4XMePB9hUNt/71f6RlWBKr5L 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: As a preparation for supporting shmem large folio swapout, use swap_free_nr() to free some continuous swap entries of the shmem large folio when the large folio was swapped in from the swap cache. Signed-off-by: Baolin Wang --- mm/shmem.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 28ba603d87b8..33af3b2e5ecf 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1950,6 +1950,7 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index, struct address_space *mapping = inode->i_mapping; swp_entry_t swapin_error; void *old; + int nr_pages; swapin_error = make_poisoned_swp_entry(); old = xa_cmpxchg_irq(&mapping->i_pages, index, @@ -1958,6 +1959,7 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index, if (old != swp_to_radix_entry(swap)) return; + nr_pages = folio_nr_pages(folio); folio_wait_writeback(folio); delete_from_swap_cache(folio); /* @@ -1965,8 +1967,8 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index, * won't be 0 when inode is released and thus trigger WARN_ON(i_blocks) * in shmem_evict_inode(). */ - shmem_recalc_inode(inode, -1, -1); - swap_free(swap); + shmem_recalc_inode(inode, -nr_pages, -nr_pages); + swap_free_nr(swap, nr_pages); } /* @@ -1985,7 +1987,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, struct swap_info_struct *si; struct folio *folio = NULL; swp_entry_t swap; - int error; + int error, nr_pages; VM_BUG_ON(!*foliop || !xa_is_value(*foliop)); swap = radix_to_swp_entry(*foliop); @@ -2032,6 +2034,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, goto failed; } folio_wait_writeback(folio); + nr_pages = folio_nr_pages(folio); /* * Some architectures may have to restore extra metadata to the @@ -2050,14 +2053,14 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, if (error) goto failed; - shmem_recalc_inode(inode, 0, -1); + shmem_recalc_inode(inode, 0, -nr_pages); if (sgp == SGP_WRITE) folio_mark_accessed(folio); delete_from_swap_cache(folio); folio_mark_dirty(folio); - swap_free(swap); + swap_free_nr(swap, nr_pages); put_swap_device(si); *foliop = folio;