From patchwork Wed Oct 2 01:20: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: 13819171 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 AF73CCF3189 for ; Wed, 2 Oct 2024 01:20:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3700568004A; Tue, 1 Oct 2024 21:20:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 32BA1680048; Tue, 1 Oct 2024 21:20:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 17275440168; Tue, 1 Oct 2024 21:20:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E21FD680046 for ; Tue, 1 Oct 2024 21:20:46 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 157A5818BD for ; Wed, 2 Oct 2024 01:20:46 +0000 (UTC) X-FDA: 82626907692.14.AE707AA Received: from mail-yb1-f172.google.com (mail-yb1-f172.google.com [209.85.219.172]) by imf14.hostedemail.com (Postfix) with ESMTP id 4F80010000F for ; Wed, 2 Oct 2024 01:20:44 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="QR6d36/z"; spf=pass (imf14.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.219.172 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=1727831875; 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:references:dkim-signature; bh=3DDiG/7V3reVxLK4DbYXQt0ki9kjoNNk0OLn5oS4hQM=; b=pZ1EbR9apiPiK7d3beB7Py3kRgw/3AWUi8U/ihBcvIpLQcBK7bpjmpM1+Zn+/yjWn8JfWz Id5mzlwWx+P3R5VwT93BD85ifycNmoUvO7bqF9jjzfNO/99JzGWuHQhARQeju1i8EAYoAR xv82arRa0c5tueQM8v8wGvGERT9ggfI= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="QR6d36/z"; spf=pass (imf14.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.219.172 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727831875; a=rsa-sha256; cv=none; b=n3KIe7CILcYeSJcYBDRhf6bdXU9zl9xNe3ZIvZVg+oWUQH0mkd/pcvO6t/yX0wutzhg3Fg Wjtu9dQu19f9AqRZIdzPHMtSMb4Rn4qUEuQKAZvaZuR8HLdJHvGWQhqFlmLwG+1Ow6vNz7 8r9vgnjf/O5EHnHto1FKzJ8l/OKh7eg= Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-e0b7efa1c1bso6364107276.3 for ; Tue, 01 Oct 2024 18:20:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727832043; x=1728436843; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3DDiG/7V3reVxLK4DbYXQt0ki9kjoNNk0OLn5oS4hQM=; b=QR6d36/zQKKjhlS+AQS9C05fzrIDn87M437ajT4wLB/1pym6Af3SFZT5A8Z51Brsnc Ph7psGsfOdCeoPVdzTw2vANBBlevVnqnALkP9Tjx/54T1yTobViCLpzwf/hl3T5S6v6+ psFbHXHJnpaQZLtnHcba/yE8u8jFPwKFw2ggC/re81+Y9YNdm2a5e21/ad8TGl2dcPBk z7khkFuMD//ulGp1OApyT0ie77NFGBBfzimoJe8MAqhURtVaJTWo5TTF9GMUi3sd/Jmc LAJ88vz4b1nZ69mQoOh09k12wqvpHdP2GjRLVsn96fRdHtMR5pOnNlhWUc4lkEm5ftsV 3aYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727832043; x=1728436843; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3DDiG/7V3reVxLK4DbYXQt0ki9kjoNNk0OLn5oS4hQM=; b=WujIVavJ5T8IibSgLr/zLCm4xwzcSm143QGx0pPjtOSYNrjR2CdNzNhAcjGhuNVT0a 7/f2hmdKUZSoWleMhWMHv/bNSxQHZyG2wYS0nkE99Ot8S3c8PPfQfUDziyJZ6vvLXCV+ tCRe7DQyZwa/LlhKv9l8p1SaO+5h9rIuEG0H41nQlz20O45l0OCm3YcyalztckxWKyND bkYat/whxI6zx4M5cMZioJx9y5m6HB8kgaANZtb26sxJTqYpMDfNZJBcN00PBdahxg7Q b+QxSRhWWdrwybP/Ecau56tmjAIxqUIJ/BZOqPufnm/OBeBE29Uzq1oOtDsMKih9WwA4 p0dw== X-Forwarded-Encrypted: i=1; AJvYcCXBHWbDMy8nw8twIKyFJfPpyI4salkZjhNeTNOxc6wkwBzNnKq2YZVOMnNxR0p+Q9yQZMriG8i8hA==@kvack.org X-Gm-Message-State: AOJu0Ywt9Wp7cFPu0kcIYO20w+0tL+m9zD9FcAVpSTfKh7iapSx+Amep VmTB1Du//0H4XxYtA4fX1lXiafxfBHCYpcsoiaelYXxC4m63zoEZ X-Google-Smtp-Source: AGHT+IE+VkbWY85UvGhcoEeS/0Hg8lVKhDIQRFI1/JH3RTdc3UlUKEQz5QC0zrEGImxYEq96f20gtA== X-Received: by 2002:a25:c5cd:0:b0:e28:67b3:d731 with SMTP id 3f1490d57ef6-e2867b3d8a4mr48695276.9.1727832043182; Tue, 01 Oct 2024 18:20: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-e25e3ef8ee8sm3566914276.1.2024.10.01.18.20.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 18:20:42 -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, v-songbaohua@oppo.com, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 0/1] remove SWAP_MAP_SHMEM Date: Tue, 1 Oct 2024 18:20:41 -0700 Message-ID: <20241002012042.2753174-1-nphamcs@gmail.com> X-Mailer: git-send-email 2.43.5 MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 4F80010000F X-Stat-Signature: swy4gespqzmonzf7fg48c3j1tabk6ctz X-Rspam-User: X-HE-Tag: 1727832044-228400 X-HE-Meta: U2FsdGVkX18y4dyWGrKwozaLxoElNVGs9H40pS4qF4+LJeVWKQQJaYylTvyd+Y8S/LogwKXsAr3MAcq19AIHKgipYUt7xmi7PaFgWeMYqUh6Xwe3PP05aLfkXhxBo20uvz2WN9YUxwIxNq99vV2wOi9cfe3xGtT5IN8FDfNp9xraXLy9T8y6/1zn4E7wTABWQvXbZOHoin+NDyXnEaFtVyVYAHQ+xRaa4i00sjYV4Kceg6J/Q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PvE/TEbv9n2lQdplQzRa3IbbHooNz2ild0ff9F9grdXZUAAnBBaSE9gPe9c943tGApDAEbalFr/0XzsF8dIb2szD2Q2Qkz3Av7ylH6apyaifwgdMMk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000078, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Changelog: v2: * Fix a WARN in the shmem THP swap path. Thanks Baolin, Yosry, and Barry for the report and the discussion on how to solve it. * Squash the two patches into one. RFC v1: https://lore.kernel.org/all/20240923231142.4155415-1-nphamcs@gmail.com/ The SWAP_MAP_SHMEM state was originally 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 drastically 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() This RFC proposes the removal of this state and the associated helper to simplify the state machine (both mentally and code-wise). We will also have an extra state/special value that can be repurposed (for swap entries that never gets re-duplicated). Another motivation is the new swap abstraction I am currently working on, that would allow for swap/zswap decoupling, swapoff optimization, etc. The fewer states and swap API functions there are, the simpler the conversion will be. Nhat Pham (1): swap: shmem: remove SWAP_MAP_SHMEM include/linux/swap.h | 16 ++++++++-------- mm/shmem.c | 2 +- mm/swapfile.c | 41 +++++++++++++++++++++-------------------- 3 files changed, 30 insertions(+), 29 deletions(-) base-commit: 391cad4424af8bb563e1504c5adaef0155b4abb6 Tested-by: Baolin Wang