From patchwork Mon Sep 23 23:11:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 13809995 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 1A2DFCF9C5B for ; Mon, 23 Sep 2024 23:11:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A30A96B0088; Mon, 23 Sep 2024 19:11:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 96B666B0089; Mon, 23 Sep 2024 19:11:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7980F6B008A; Mon, 23 Sep 2024 19:11:47 -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 5A2596B0088 for ; Mon, 23 Sep 2024 19:11:47 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id CB3DDAC24A for ; Mon, 23 Sep 2024 23:11:46 +0000 (UTC) X-FDA: 82597552212.19.ECA1392 Received: from mail-yb1-f176.google.com (mail-yb1-f176.google.com [209.85.219.176]) by imf18.hostedemail.com (Postfix) with ESMTP id 048331C0010 for ; Mon, 23 Sep 2024 23:11:44 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UWt4OwkU; spf=pass (imf18.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.219.176 as permitted sender) smtp.mailfrom=nphamcs@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=1727132987; 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=LPDqT4tYuF6YjiitP1AaWuH6hXZ6wk6au/QNmRqOg+Q=; b=40K8/ZR7YjLGzeGjgGbF7IWRTgkTpvjT8o3H4BygTfZ3JlC7C/bpL/jKabwfASwV2t7Sxm pSRrUHumw768y0sK2u2odq8XzcVwKJH/rjRGC2MMA67wqS6UVVtBWOU+O+SqtfnGEjIB5i tlRPZqFlKIUHAti/+Lc6kSxu9DXa3s0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727132987; a=rsa-sha256; cv=none; b=R3XVO/IwsS+SAdzhMaYLif39myS2imv+359OINrP0Zb+hu83UjyvAkbtdCD+3Oqb7QL2LO 9ShU0fImaXA6elMwJz1XvqdK3+ZHAekQnxvSgNFoE2/WVuZhrxDoCreSTj3uWFAMexIwjq gYvt6I6g7trgGrqkc8C4sJ72cbX3feI= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UWt4OwkU; spf=pass (imf18.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.219.176 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-yb1-f176.google.com with SMTP id 3f1490d57ef6-e03caab48a2so4197308276.1 for ; Mon, 23 Sep 2024 16:11:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727133104; x=1727737904; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LPDqT4tYuF6YjiitP1AaWuH6hXZ6wk6au/QNmRqOg+Q=; b=UWt4OwkUuzlvxgZr3Pyj5f3iEKYU/zZiyAfSOgHbAA5EspyHGF7Bi23i/eCVoAdut0 5nfM9x8xB1ivAOjfDztpJ/01+jayLjm8PiQhE/FJW2u+wH8MjpuLN73fl+T7LO3016zH ge0QkQUtyJemqhBt1BBtkTHkF65XWrQlpnYcBGUOXfoLWLaGKwRJdFSZs0eWgK17c641 a+KD0b159K+Blg6YcR+GfXcI9Pg48PweGKJkOel0i7YiVaeTPCEM10Uq3loaencV/ch2 7vIHVwZ70zJTPZTJ1sFPAfHp7tQJieyqsvR7jBPgA35ttEgxw7fwcsaGTD99mICLHoKs K84A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727133104; x=1727737904; h=content-transfer-encoding:mime-version: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=LPDqT4tYuF6YjiitP1AaWuH6hXZ6wk6au/QNmRqOg+Q=; b=apiDfYzOZwGXy7T3fJp0D477SZxyCdDw/2yI/4iJrAIXGeDvnzILbQ7vVNO3NZ3EB2 liA+YeM0BK1BRSmPmAboT50c8kDri89Vxh61D9lw2naCgJlPJdbTNKZqXYClq8M7CHCS gltpfro98A6xvjIC1pDwqt1cKpflnohVUu7go+V8LEfOP/MlHdb7fWRa0baMNs7XV6NG LsLRc10pvdrtrY7IOw2GiRIzkKavYXpj6qbKMRGCH4wMpBAYM5jS05jtbRESQ2W3JEGu eE3BRrf/wYeNx+E6fUu2/OkXnQUMTsEyahpOrVGnlxciA5JzdlUI2HrVuQWuP69IaslH IWQw== X-Forwarded-Encrypted: i=1; AJvYcCUjRBEppA+uAhODoPo99RybPcvZ5OXKubWpqqEGZaQJE7013ZRjwexQm5UTGMEH2wDDBKZvgEu98w==@kvack.org X-Gm-Message-State: AOJu0YwvMurihLNdkC2E0LW0p+okvVw9i3zygQHOeyCQluBC83QYEOjF pYwsTN/rm9iejHRTVw8nT7eM1SJbmUWrYVsaZalK0NvvXmTnyQAJRxPVKA== X-Google-Smtp-Source: AGHT+IFcssM6pnQQDk/NRr4NihPaeFHiGgxFPtmnmmYpIunNZgYl6WAQdDvridjor3AWUUXZ9mYN5w== X-Received: by 2002:a05:6902:150a:b0:e1f:aec0:4e6d with SMTP id 3f1490d57ef6-e24978b67eemr1107670276.14.1727133103972; Mon, 23 Sep 2024 16:11:43 -0700 (PDT) Received: from localhost (fwdproxy-nha-114.fbsv.net. [2a03:2880:25ff:72::face:b00c]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e2499c6226csm50606276.43.2024.09.23.16.11.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2024 16:11:43 -0700 (PDT) From: Nhat Pham To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, yosryahmed@google.com, hughd@google.com, shakeel.butt@linux.dev, ryan.roberts@arm.com, ying.huang@intel.com, chrisl@kernel.org, david@redhat.com, kasong@tencent.com, willy@infradead.org, viro@zeniv.linux.org.uk, baohua@kernel.org, chengming.zhou@linux.dev, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/2] swapfile: add a batched variant for swap_duplicate() Date: Mon, 23 Sep 2024 16:11:41 -0700 Message-ID: <20240923231142.4155415-2-nphamcs@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240923231142.4155415-1-nphamcs@gmail.com> References: <20240923231142.4155415-1-nphamcs@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 048331C0010 X-Stat-Signature: 1xs99mxkdcr71xtxnqm3qid8ffem84m7 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1727133104-63230 X-HE-Meta: U2FsdGVkX1/P0I6QqqglWLEepev10mAOsaVJ0gHkzhArfm0oQP01kNl0QwFZXITej/YN+gXaWxrIgj1Rs0qUc90nKtbr35SZdvXSkFsTVbGu1wBxhxmbP0loH/Vy85ZuXr/g0O3dPzSz53cFvNmArShREBYMmWz6OGEk4ePLmWxzv5KRGXj+XPc4+NDPMDVbpQ1kDbB7MBuzp+wdwFQL3DhNmDpC6528pe+hSvblnHUsI6jPYwAISLsdSKRkSXME8Yzq966UMSc6czqFqFda25hS+mJLmsS1IwggfTL2DuCXQ5kzR631G1GsD7OUFCChFc/17Db5eMWyGrlekqv+y3poIo6nvpCg8dlEwh+mP1tEQiu9cPHg46Yy5w+I8NkEF4moslV0ONz1huB2dN2CErse1YhuhIWUfuxwzRrg2uUJitWFlRhWMvuRVN9Hrm4Kq1jtnDbq9Fq0VGLU9jlFLcthlauUsbdHQ/P2GQKvrysY3PYmuuHN6KxFVEhumjdk2uqhmgEhGLzKFTlPf3GCWS4PfSkPOTvDLfsFZlIx7U5oGKs4vghctzv/29Iaw9C1vxunIfwMBal9Vf3vPUMtrW8kYkO6Npmk99Sn3CmzOVN6P7FoiiJWmXU/+kXqcwHJ6Vt4Uh1Hji1dYj6XZ3TB56ICHcyBbIwUxJU+YrFohMIFRo4r4BQd9NfV3bkk/Clfqs3Y9GvvT2F0o7XI8xGCxhRiora4Otx75PbyFbxL7fDrIad/dmR/7Ab4deDl6N/8Z+G1pVVQ9Av5hw31V9ZDqo9duDLvLbUTR8QB9UizBDL1uzTSoblcC07SmnktwUY8rAyJYgSosdECg+cvoidNQdMcI3upUmiaWxvEpy2XpZp4GxwfdCLt9j8lckNWzo2+aJTiLe+US36nvMFDhufFIuLHRM226dmUGJ6GUk5E72g78PeKC11TAw3xbIe15oQ0FdarRo4ufIgjpGDTqQX sp4ORPGA pcDodyrYsRCVWz4Fft+rIusXB+TjJoQnT6Z+n8nsFdFZ3u2wO0dpIsqENMYHsuxrLvLRpt1KvxLJIsKxCfvLXn/rFQd6ZN/WJ+hbRD6ixBA30S9KYCgAsTitBjeQxNA/rGK0EQRnjzMHPls+W7jAYDleon3nxsajLlJrDx+wVrRLJWMRkQ969+iFwX7+w6fanNJ8pYloje0wHvuifGwKK+/yYekgl6kZLQ5lVyGc/mOCbH0T3jZc40/LXgzmL7gSH/bDgvj9Si3ivW5QaBzwGIRiLqrC271OX0qPGf37i5HOdC9gNPOf4c4kZPeiUn189zw+SON4B7EeUo+kfmcz7VH3sqDa1Z4ZZClfSYsMiESKI9m5wNJGNjTM6PzVdfTAsDuruyHtIlsRVyGheDAHR6xNwsg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add swap_duplicate_nr(), the batched variant of swap_duplicate(), that operates on multiple contiguous swap entries. This will be used in the following patch to remove SWAP_MAP_SHMEM. Signed-off-by: Nhat Pham --- include/linux/swap.h | 10 ++++++++-- mm/swapfile.c | 13 +++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index ca533b478c21..e6ab234be7be 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -483,7 +483,7 @@ 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, int); -extern int swap_duplicate(swp_entry_t); +extern int swap_duplicate_nr(swp_entry_t, int); extern int swapcache_prepare(swp_entry_t entry, int nr); extern void swap_free_nr(swp_entry_t entry, int nr_pages); extern void swapcache_free_entries(swp_entry_t *entries, int n); @@ -553,7 +553,7 @@ static inline void swap_shmem_alloc(swp_entry_t swp, int nr) { } -static inline int swap_duplicate(swp_entry_t swp) +static inline int swap_duplicate_nr(swp_entry_t swp, int nr) { return 0; } @@ -606,6 +606,12 @@ static inline int add_swap_extent(struct swap_info_struct *sis, } #endif /* CONFIG_SWAP */ +static inline int swap_duplicate(swp_entry_t entry) +{ + return swap_duplicate_nr(entry, 1); +} + + static inline void free_swap_and_cache(swp_entry_t entry) { free_swap_and_cache_nr(entry, 1); diff --git a/mm/swapfile.c b/mm/swapfile.c index 0cded32414a1..47a2cd5f590d 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3695,18 +3695,23 @@ void swap_shmem_alloc(swp_entry_t entry, int nr) __swap_duplicate(entry, SWAP_MAP_SHMEM, nr); } -/* - * Increase reference count of swap entry by 1. +/** + * swap_duplicate_nr() - Increase reference count of nr contiguous swap entries + * by 1. + * + * @entry: first swap entry from which we want to increase the refcount. + * @nr: Number of entries in range. + * * Returns 0 for success, or -ENOMEM if a swap_count_continuation is required * but could not be atomically allocated. Returns 0, just as if it succeeded, * if __swap_duplicate() fails for another reason (-EINVAL or -ENOENT), which * might occur if a page table entry has got corrupted. */ -int swap_duplicate(swp_entry_t entry) +int swap_duplicate_nr(swp_entry_t entry, int nr) { int err = 0; - while (!err && __swap_duplicate(entry, 1, 1) == -ENOMEM) + while (!err && __swap_duplicate(entry, 1, nr) == -ENOMEM) err = add_swap_count_continuation(entry, GFP_ATOMIC); return err; } From patchwork Mon Sep 23 23:11:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 13809996 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 4C1C2CF9C71 for ; Mon, 23 Sep 2024 23:11:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 949B26B008A; Mon, 23 Sep 2024 19:11:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D0CD6B008C; Mon, 23 Sep 2024 19:11:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D5F76B0092; Mon, 23 Sep 2024 19:11:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 3F69F6B008A for ; Mon, 23 Sep 2024 19:11:49 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0B7104162A for ; Mon, 23 Sep 2024 23:11:49 +0000 (UTC) X-FDA: 82597552338.05.C658AC6 Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) by imf03.hostedemail.com (Postfix) with ESMTP id B0ABB20019 for ; Mon, 23 Sep 2024 23:11:45 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DGaIbdLr; spf=pass (imf03.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.219.180 as permitted sender) smtp.mailfrom=nphamcs@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=1727132988; 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=8gPbe3KNGXZnnS8+FFZzqNPtSCfvfbRnB6uu/A9bSpc=; b=Gl4FdyI1uI5SFA7+UIa5asHQmCa0ET4JQErODfNbTyg7hiqZqMZsCfm6bAEMMz9Mq/g4Ay KvSrtOBDejDwCvIk7bBDhvgkCRkR0GMjDaY2CcQtPKbmrIjKkxits0wbXlvHOz9Z86+Vwl WFoP7LkIBk775QeDF8JjnZASab0NgPA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727132988; a=rsa-sha256; cv=none; b=XDH7njAJwaInLpUsqMQjlxrXgMQXx4khRBDRwVmYirS1dR1hl9CWDu+AsS1m5NXBNB3y3I HFhIq3B4yfcaBJI2/k7+pTnLFZE1BmWluoKHQLKkKPoDab8GFIzZFYGcwPoAm0mRtMI/vD 6pXF/c18DA7+fZTEUKsgXIBRGTmGrL4= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DGaIbdLr; spf=pass (imf03.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.219.180 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-e026a2238d8so4207127276.0 for ; Mon, 23 Sep 2024 16:11:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727133105; x=1727737905; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8gPbe3KNGXZnnS8+FFZzqNPtSCfvfbRnB6uu/A9bSpc=; b=DGaIbdLrN86Osb83ERI+RxlDAdp3fvBPtRRQMrcRXpg2CShpSLwabWGOEEiqsDGIHP 3SBaE1uTrpeY4lueW4bbY1NdraAoip9K3dLHnvlCIlhNjwj13VvxqSXL83MD60DfsXXb 5hlbQezzOTSwUKTJGyKpZnlnrMm7oO49VwmwV+1Bta3MUVvLHGFriAF1o8jFXYz+vPMb cFNLYd41wh6VIKEBhD867zPH2PUd2buDfSnq2o5siKzmdOp3KJYwAVWZX6DVl3uSI+GZ ZEwyru+cn2przowbL2jlnXvEpaMf/qZmq9FWppvCdbZnNE+sWpc/Wn0oNWljwrp7rlM3 dNMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727133105; x=1727737905; h=content-transfer-encoding:mime-version: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=8gPbe3KNGXZnnS8+FFZzqNPtSCfvfbRnB6uu/A9bSpc=; b=Gikr16N0JgpJPpsOogsW+pIpajxx4PF9PYwqMhrRGrBGPIZ3dMqumrZ6V3GlmQyms4 lyJvlaqWx4kCQkhXfBus2ADaxFIsqNr+8PurBRpH/zCoFO7mTtv92qhZ3jyc2+ORCYLG zopLkldiEGD7H2WG+p8xi9QB1qH+kb5xf+i1hXwTiHBUZ3ReYRvceM216PQC27Pgy62W 5pxcaJ5T2Zkloy9A46b55AJwn6DVQK4kukk16OSQeWTQsyIgQV8J+yt2N5p8RmP5ovHV bEWKlL/dxNBzOQ5U+gaO0NjWCa9ikQqjatStHsWEIKpgI2AN3k5Tp+OuFMmky6SGNTW2 du5w== X-Forwarded-Encrypted: i=1; AJvYcCWuS6FFMKGT45hpk59GGTcpl/0m9izvCjlpX7mFYoESqZOoX1sLnCScfyDApU4fDs/YfiiGl/xOSA==@kvack.org X-Gm-Message-State: AOJu0Yyk95wbnAi8LaHqdTD8A1+NHwk619s1PVX+uyuhQgfR8hDCmXbk xRXsae+nli8sm76JMvgug+phIlzWqa3X5BXbeGDyHE4N8V+WEAjO X-Google-Smtp-Source: AGHT+IFlyb1PljXDzq/V7UeC9hqJSsT1MOj/S9VfhqqJ+Q0LEEGkENMIw9m5hji2q2AQZgaGNfV2PQ== X-Received: by 2002:a05:6902:102e:b0:e1d:436c:3b4f with SMTP id 3f1490d57ef6-e2250cc504cmr10944928276.50.1727133104733; Mon, 23 Sep 2024 16:11:44 -0700 (PDT) Received: from localhost (fwdproxy-nha-115.fbsv.net. [2a03:2880:25ff:73::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6e20d15d44esm555897b3.100.2024.09.23.16.11.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2024 16:11:44 -0700 (PDT) From: Nhat Pham To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, yosryahmed@google.com, hughd@google.com, shakeel.butt@linux.dev, ryan.roberts@arm.com, ying.huang@intel.com, chrisl@kernel.org, david@redhat.com, kasong@tencent.com, willy@infradead.org, viro@zeniv.linux.org.uk, baohua@kernel.org, chengming.zhou@linux.dev, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org Subject: [RFC PATCH 2/2] swap: shmem: remove SWAP_MAP_SHMEM Date: Mon, 23 Sep 2024 16:11:42 -0700 Message-ID: <20240923231142.4155415-3-nphamcs@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240923231142.4155415-1-nphamcs@gmail.com> References: <20240923231142.4155415-1-nphamcs@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: B0ABB20019 X-Stat-Signature: 9ujkaee99sqeejj33pt35uh4totcjfkp X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1727133105-41167 X-HE-Meta: U2FsdGVkX18pXFT9CvqMTfbzsB97y1ljn8LLlTiQsqZo7kp9YRH/V7PVdK8dBJMpcb6ARcWMMrBwnBa/CDQgV0kWpHHLcjGNTJzhdLJfLgSptODQrPpL4HmnNmfis5UUVsOrD6O25wb8fb6uzr3qZH5nET0POE7P8Km0qHui/whIu9un1nFI4uAvX3Zo0qTgHbsAMLlRX6l2fs3Sa0IYLjo0ogORQLATgatkW8bJGFRSD8uvKcGn0+A/ZLx2wdrNbTIpXOuy3SpYOeJqxv4YQyQ8GkquSPP27ctCVkm0VFd+5KIbYWvo4wJBlXrV0DD9M4drnpa+mdbPlNkLtVnHOe/POUwEWRkgKKc5DQPaMlmaZw+7BU+x+fK+VnUIfFoV3jvdQn6d8lbcYBDhz7Ich2KGCiizuiBO+VCjQDUDA37SUwq8c3KgVTN8sQmIZxKWtjXzxYX80Er3PDkrW+beobiHV0+s11kLA/jZDUjc+jKvb003G0gjYNJ6pDIP66dCL8bpKZRRNkWFlZ898XWg6ZLc9y40CbFyK31gAQnDUzld/X7QD/vywHMnHA2cEh17MRBafv4n+mrbFg9o94CgtlVCa5RAbQvRJoBF2OhzMtxU/q+FevPkSI4ZaCv74ZghqY03neVK1bMHOABpPnIv2+uaaKyuYAGjibuUgjV50Hrb2j5BpeZctuXy46otITv8RgiudnfsH3A0aRrtZ6ghkCcdgs1yJC+9Rb8tRbdD5ic6Tag1+ynlH0TrCV6ZkHgyRWNKz794RL5QbRtGkXBoJ/ddxwMvv9N9Xqi1cV64MicFt4/ygzBHVA2GsXat8oEs1ozxZcDFib/00kqPlpTCuKFekDhpa/m0EP4lNesXv1aHZVKj8tMvvX0Asp6w+LBUTWoqrpQbHfZ5gc+6uekN3KkMhRJg3RkiuJLSQM+ZUGp/+pAhD1WTWfy0y9C4We+KTLWeHopTlNjUbW+S7HI BF68dKHZ IRYaizQOClBgA0Pcfw0slZFZ5BWxCp0puBMS/i2Oe3SU0HlgGyITMyvUpG4iRViffWnrfpIctCPkKTDBCjfqGbjc2iRw6xRt9euXHuiv6nr73Qnqd7UVN1QP9XI6pZE/D4JJnv5UNzhkcBHVTK2XGGszZzYvWNDbxmTN6GGhIccxAvTy+7rvcR+VLEntBFXk9cnsOjwTny8NQD2hRq6lBNoY9MhrcC5d1WtW9dwCWGwD4vrDuF7coEbhAsehzzKAxTmuXj31ewH82NKeQrf/LmDTkO7iULx5tJM5rBjiajsiXxFK/6xVScpupZsy7CM39xrUoY1u4Gc4KTkIPmAzkJfJN49zFzEStse04MtGkK2+ZGX+nd73/SeMkF8lGSNCEq14/qT7OzyHStFEBjpiPZLSmKg== 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: The SWAP_MAP_SHMEM state was introduced in the commit aaa468653b4a ("swap_info: note SWAP_MAP_SHMEM"), to quickly determine if a swap entry belongs to shmem during swapoff. However, swapoff has since been rewritten in the commit b56a2d8af914 ("mm: rid swapoff of quadratic complexity"). Now having swap count == SWAP_MAP_SHMEM value is basically the same as having swap count == 1, and swap_shmem_alloc() behaves analogously to swap_duplicate(). Remove this state and the associated helper to simplify the state machine (both mentally and in terms of actual code). We will also have an extra state/special value that can be repurposed (for swap entries that never gets re-duplicated). Signed-off-by: Nhat Pham --- include/linux/swap.h | 6 ------ mm/shmem.c | 2 +- mm/swapfile.c | 15 --------------- 3 files changed, 1 insertion(+), 22 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index e6ab234be7be..017f3c03ff7a 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -232,7 +232,6 @@ enum { /* Special value in first swap_map */ #define SWAP_MAP_MAX 0x3e /* Max count */ #define SWAP_MAP_BAD 0x3f /* Note page is bad */ -#define SWAP_MAP_SHMEM 0xbf /* Owned by shmem/tmpfs */ /* Special value in each swap_map continuation */ #define SWAP_CONT_MAX 0x7f /* Max count */ @@ -482,7 +481,6 @@ 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, int); extern int swap_duplicate_nr(swp_entry_t, int); extern int swapcache_prepare(swp_entry_t entry, int nr); extern void swap_free_nr(swp_entry_t entry, int nr_pages); @@ -549,10 +547,6 @@ 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, int nr) -{ -} - static inline int swap_duplicate_nr(swp_entry_t swp, int nr) { return 0; diff --git a/mm/shmem.c b/mm/shmem.c index 361affdf3990..1875f2521dc6 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1559,7 +1559,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) __GFP_HIGH | __GFP_NOMEMALLOC | __GFP_NOWARN, NULL) == 0) { shmem_recalc_inode(inode, 0, nr_pages); - swap_shmem_alloc(swap, nr_pages); + swap_duplicate_nr(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 47a2cd5f590d..cebc244ee60f 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1381,12 +1381,6 @@ static unsigned char __swap_entry_free_locked(struct swap_info_struct *si, if (usage == SWAP_HAS_CACHE) { VM_BUG_ON(!has_cache); has_cache = 0; - } else if (count == SWAP_MAP_SHMEM) { - /* - * Or we could insist on shmem.c using a special - * swap_shmem_free() and free_shmem_swap_and_cache()... - */ - count = 0; } else if ((count & ~COUNT_CONTINUED) <= SWAP_MAP_MAX) { if (count == COUNT_CONTINUED) { if (swap_count_continued(si, offset, count)) @@ -3686,15 +3680,6 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage, int nr) return err; } -/* - * 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, int nr) -{ - __swap_duplicate(entry, SWAP_MAP_SHMEM, nr); -} - /** * swap_duplicate_nr() - Increase reference count of nr contiguous swap entries * by 1.