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/g0O3dPzSz53cFvNmArShREBYMmWz6OGEk4ePLmW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/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; }