From patchwork Tue Jun 18 06:54:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13701838 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 217C9C27C4F for ; Tue, 18 Jun 2024 06:54:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 266D86B0148; Tue, 18 Jun 2024 02:54:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C4E96B014A; Tue, 18 Jun 2024 02:54:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 015F08D0001; Tue, 18 Jun 2024 02:54:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D09166B0148 for ; Tue, 18 Jun 2024 02:54:37 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7F240804BA for ; Tue, 18 Jun 2024 06:54:37 +0000 (UTC) X-FDA: 82243096194.27.D249057 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by imf27.hostedemail.com (Postfix) with ESMTP id 702DE40018 for ; Tue, 18 Jun 2024 06:54:35 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=kzN8QKL4; spf=pass (imf27.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.132 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=1718693669; 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=oU/PcFIl06vSDqEtjZujhmAzGqRrrYre+wfF0/f2UwU=; b=MFTkQN6RQf9dZQDcvlMQFSHeJ2tbptirGhfdhe5jAg4MhyJCpjXjk8WMiR0bJMa3eRi5i3 mDqfUejIJhhDFswRGQOUaJvKL3Qf2gKlpbITZN7mIDTHxy3bKhl595fu9UlMAUWevVdch4 NQj11SYAtdtZcnplHH47WG6hgRt7uxg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718693669; a=rsa-sha256; cv=none; b=yy7RD1w7LGwNoqQvXrFmqIo/BYwBKjQL3p2yFjw7rYe/7FzmmnI5V0zVzVLslhL5ssxYDv u4DZXyzLN2dwk/lzErEMbgXpDrfVaHtzPOuuTiuZr6lMc86BIhL9WZMdnGnriHxFmXkFJm EZ7ctNStBnlgEV1itDmpyIvJJarvEC4= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=kzN8QKL4; spf=pass (imf27.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.132 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1718693672; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=oU/PcFIl06vSDqEtjZujhmAzGqRrrYre+wfF0/f2UwU=; b=kzN8QKL4HqHEkDyChBPWZYhwgAemYiLzM/NES7nFLQsMialpNZY3Mvpl1CdyuBfpsc1u8u6gPdIFi0suB/cMYPAv2fvn/xLy0rxZM7yqwFBe136kCncXEVnohlr2shwnHj4528Z2EgYf1KismQSB5b5/idVp0u83tzJcz6tnBaU= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R861e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045075189;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=17;SR=0;TI=SMTPD_---0W8jFFL._1718693671; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W8jFFL._1718693671) by smtp.aliyun-inc.com; Tue, 18 Jun 2024 14:54:31 +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 v2 4/9] mm: shmem: return number of pages beeing freed in shmem_free_swap Date: Tue, 18 Jun 2024 14:54:16 +0800 Message-Id: <6e567bfbb6bac0bfbdd63e60718bd1aaf8eade6c.1718690645.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-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 702DE40018 X-Stat-Signature: r3znm9y1z7x9o7suptzkncqcojyhymgp X-HE-Tag: 1718693675-957502 X-HE-Meta: U2FsdGVkX19glpTEPLxhF+5R8jS1OlhDADcI+IiwIJ5WIfNfgUhCfJmlWFxuGxAvmQhoI3CTZ6rMX73VdQPFLhtIuf8ZmaLis2FPlTXtigtqbzOD4g0Da7a0yOaMwrSfUApN3JqYWzHmV6r85V3I5eNwiqb3zqrVd+6ySWrKKvTbYBe/II/bw1P3OSIZK6R7EYiLpgz7m9L/8m7lYikvOWFt3ZbH+UfaQKCobLz8JKyX0WiHj0nLoDwdapkIRJBgt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gV6Jk3WTSHROXYK3r4OwfCybEjNIIkHbd6DQtorqjABA== 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: Daniel Gomez Both shmem_free_swap callers expect the number of pages being freed. In the large folios context, this needs to support larger values other than 0 (used as 1 page being freed) and -ENOENT (used as 0 pages being freed). In preparation for large folios adoption, make shmem_free_swap routine return the number of pages being freed. So, returning 0 in this context, means 0 pages being freed. While we are at it, changing to use free_swap_and_cache_nr() to free large order swap entry by Baolin Wang. Suggested-by: Matthew Wilcox Signed-off-by: Daniel Gomez Signed-off-by: Baolin Wang --- mm/shmem.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 012a06ef39aa..a73d2da54897 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -836,18 +836,22 @@ static void shmem_delete_from_page_cache(struct folio *folio, void *radswap) } /* - * Remove swap entry from page cache, free the swap and its page cache. + * Remove swap entry from page cache, free the swap and its page cache. Returns + * the number of pages being freed. 0 means entry not found in XArray (0 pages + * being freed). */ -static int shmem_free_swap(struct address_space *mapping, - pgoff_t index, void *radswap) +static long shmem_free_swap(struct address_space *mapping, + pgoff_t index, void *radswap) { + int order = xa_get_order(&mapping->i_pages, index); void *old; old = xa_cmpxchg_irq(&mapping->i_pages, index, radswap, NULL, 0); if (old != radswap) - return -ENOENT; - free_swap_and_cache(radix_to_swp_entry(radswap)); - return 0; + return 0; + free_swap_and_cache_nr(radix_to_swp_entry(radswap), 1 << order); + + return 1 << order; } /* @@ -999,7 +1003,7 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, if (xa_is_value(folio)) { if (unfalloc) continue; - nr_swaps_freed += !shmem_free_swap(mapping, + nr_swaps_freed += shmem_free_swap(mapping, indices[i], folio); continue; } @@ -1066,14 +1070,17 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, folio = fbatch.folios[i]; if (xa_is_value(folio)) { + long swaps_freed; + if (unfalloc) continue; - if (shmem_free_swap(mapping, indices[i], folio)) { + swaps_freed = shmem_free_swap(mapping, indices[i], folio); + if (!swaps_freed) { /* Swap was replaced by page: retry */ index = indices[i]; break; } - nr_swaps_freed++; + nr_swaps_freed += swaps_freed; continue; }