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/CDQgV0kWpHHLcjGNTJzhdLJfLgSptODQrPpL4HmnNmfis5UUVsOrD6O25wb8fb6uz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wCWGwD4vrDuF7coEbhAsehzzKAxTmuXj31ewH82NKeQrf/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.