Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp3000887lqo; Tue, 21 May 2024 04:05:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWIh+V0xxXApOdvqzW7ar5Cg188VlL22XfDsFnOo6nKQCCj3cdhViP6FtnutZxjKRF+zY7D3Oi7nXq2G6L7MD5chk8qm2jSzUCQXzUBbw== X-Google-Smtp-Source: AGHT+IFaBNh2Qo4zlrdWsZj7nJRSGgCVnpDiFFugTnWIx6j8XZap5wLSQgWttA/5qhCre/pAcA/j X-Received: by 2002:a17:90b:2389:b0:2b4:e4d2:e6f0 with SMTP id 98e67ed59e1d1-2b6ccfed0dcmr24259581a91.45.1716289506904; Tue, 21 May 2024 04:05:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716289506; cv=pass; d=google.com; s=arc-20160816; b=hFBdxSK4XfzeiYIXhRG8Xv9biu/3r17QzKtbbuvonBqpdyzIogW2Cj2KuQUd4KsNhA ooqV/XSHlMIIRYU5/eFcfE6CBdMeR05Du4KpfJm0vleJ92ZtAGIYLnwbSVWru5QSdUtD N2mjKAjIxcKpZTG772Rjdm8CMSiOFwlNB6T3/vfw7ygY6f4+/nwGOJuLYR5VMwYUHyml GXoxRoHMkJTwaUFdSK2/D50Q6vmIyrokGM1hgYAVpgoIXX3gmM1V0nQVG3eBWqJAKQk2 pLuzDb3JvR/6BDFk0sVSyvyIYb012r3R8mX+GKmRT160Hg1zQ+yzGWuiTdBKbXPOHJaK fcxw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=/V3DnBye2LjO7u5ouBgBU8nPrUqi/2Egdsz3zKACdwM=; fh=yZfW+BHkES0D7lqXNSviUM/H3M0u/i+axAcBKiPVoLw=; b=Cuh4pf1GqkimbacUNuh4s7Cczql7b8b0Dmi/0+O2ugKReZNo+PX58pmjk+OQHz6CWV D4S1lf/Z684NxMqxpWXyr2ZaTUm8d4J+TPu+SLR8oe0MHzHcMRPTiczWxfInawMCjTzL ZYPLDttkWTA6kKV/MiRkjR4Akl6nADUnLsGHKG55vJLmu5cF/6hu1yI2sMoxvvX+5kEl 4ZMAYAE/eG8BlfaYMA+TIHtRnolqnQ93I3tkd9VNrhlFicqd8Tvk+HGtbhUdrzJAlHEM 9czUR74Vp+9dIa3y+yO/xSl+fzf3fB0dOMW081NgWHYS5Kp0LDej9PDeKVRtgZxKQwwK XC6Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=fUJdX6hW; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-184853-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-184853-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2b67168a409si779558a91.172.2024.05.21.04.05.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 04:05:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-184853-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=fUJdX6hW; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-184853-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-184853-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 8BCF328170C for ; Tue, 21 May 2024 11:05:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ECFEF78B4E; Tue, 21 May 2024 11:03:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="fUJdX6hW" Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D1FC770F3 for ; Tue, 21 May 2024 11:03:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.101 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716289427; cv=none; b=dgC7KlT1aqnaGw1uL4py1opqInU4Hu1IqD3VLHdvGbuAxGRon9afJBuiNDf5jB3qQJbOd70l/k2wD/GgSw4bz8w0UNk4akzy5gtVuKygiitWBK4rY+wbZ8XrAmWSpFNWxE2cAHSbccDghaqEgiGOrKdCC8J+xJrGu2+uKkLQZCg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716289427; c=relaxed/simple; bh=CkVLodKJ9ucWBi7mpVP2iJelihrLRHWS7bUyzqopUjM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=vDLJ40h+i2eq07gOOgQD4zd2mAmzxnRjnbH/VyFW77bXMyYuRhOfdQo2QAAfRcuOFo6FB4Js3dyUPw8oHHFULgTwdAEaLR3ZhVY9bo5sXLKpFY/36xgD1HPdZj6zg6UxMUohRHfT7DPDh3zo5T+ZzqTFF1T6GUFdZKLgLNn4R50= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=fUJdX6hW; arc=none smtp.client-ip=115.124.30.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1716289423; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=/V3DnBye2LjO7u5ouBgBU8nPrUqi/2Egdsz3zKACdwM=; b=fUJdX6hWqHjDussoPyT9DN3O/eSP1VyI5mUQHx5keTV89BRSE3o3E2RJsTSshV+b+JIGO0raC3TK6naifFHJpE+xUlla0YCYIdAlHHTmULJb9TCfZLgw+IdgmZpxUg6Xxo+TSVJ7llXpTFTP6/n/176rElMjaulhKZkoNGCxt34= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R931e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067113;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=17;SR=0;TI=SMTPD_---0W6xl985_1716289419; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W6xl985_1716289419) by smtp.aliyun-inc.com; Tue, 21 May 2024 19:03:41 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, ioworker0@gmail.com, hrisl@kernel.org, p.raghav@samsung.com, da.gomez@samsung.com, wangkefeng.wang@huawei.com, ying.huang@intel.com, 21cnbao@gmail.com, ryan.roberts@arm.com, shy828301@gmail.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 7/8] mm: shmem: use swap_free_nr() to free shmem swap entries Date: Tue, 21 May 2024 19:03:17 +0800 Message-Id: <90fda314a9e966374fe837ae3ebd74708380479d.1716285099.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 b3e39d9cf42c..fdc71e14916c 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1962,6 +1962,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, @@ -1970,6 +1971,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); /* @@ -1977,8 +1979,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); } /* @@ -1997,7 +1999,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); @@ -2044,6 +2046,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 @@ -2062,14 +2065,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; -- 2.39.3