From patchwork Mon Jul 8 06:15:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13726179 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 374C6C3271E for ; Mon, 8 Jul 2024 06:15:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A1406B007B; Mon, 8 Jul 2024 02:15:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4518C6B0082; Mon, 8 Jul 2024 02:15:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 33FE66B0083; Mon, 8 Jul 2024 02:15:21 -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 15EF26B007B for ; Mon, 8 Jul 2024 02:15:21 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 894F5C1121 for ; Mon, 8 Jul 2024 06:15:20 +0000 (UTC) X-FDA: 82315573200.12.6E72865 Received: from mail-il1-f180.google.com (mail-il1-f180.google.com [209.85.166.180]) by imf03.hostedemail.com (Postfix) with ESMTP id C29F220009 for ; Mon, 8 Jul 2024 06:15:18 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Vgl69MHw; spf=pass (imf03.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.166.180 as permitted sender) smtp.mailfrom=21cnbao@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=1720419296; 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=EQIqWVaUpLW7tNHj4brQfTw/7FKBab3/cxzq1ObVSc8=; b=14d6ZoQsjAGEvpQlVpjNz2AkA21+n98TNDZ9iov+rRaAOYQ5S5IOe39W6RSIfyh9TOyQ3W 9UJFXQamJp02csfvtDaVXEXo7S77otDbxGM6iB0EDrb11WmlFIPRm3Y2rxdEUXltUhuKK3 xh9gWpIKPC9ir79odoJ9B707Aszt8XQ= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Vgl69MHw; spf=pass (imf03.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.166.180 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720419296; a=rsa-sha256; cv=none; b=b3pb7fnmRT0LawyoPnZGKZcNsP+zsmluMBvY9+YpjWJh7NHr1eP813uJxsP6Xrhsl7yNtY xh4HMjYckDO/6G0E2Uhz4dPkFodcpHIvMYNOuVxiW43HK3FzECsSazuVmK8sBN7r1iMbGz gY2heUVhGkSeRdwbvqZkwgNqs4Zx/BA= Received: by mail-il1-f180.google.com with SMTP id e9e14a558f8ab-3817084f7dbso17084395ab.2 for ; Sun, 07 Jul 2024 23:15:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720419318; x=1721024118; 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=EQIqWVaUpLW7tNHj4brQfTw/7FKBab3/cxzq1ObVSc8=; b=Vgl69MHw90buE52j8p/a9d2TvC9v3up6LTtEZG1ccbqnChI0z4eXqDzmMkMdZrsKdL WJWSwsSORZFw6XVPar1ygYOHjsvxNZuA6nGE2rmdK/CyJE8HODIhAu+3wz8MvK4CmdEu xKU+omQTNOD0x3a9Zn/Bk058n8b37N0kf++jm8K69kQ3sTLzhOzphe6NEkztmEu6nE1P m2wa6Afb/X4Qyl5oxlBLGx9WsSY0YOhcOD0p6x4NWesUhgkW/wz7S0H7sp1iF9kAhsv9 ssVL0GgHSj2xfZRs1tmEuWaQ2bmorTGO9J/rOgpC4bVIU+sbLoO4FWeE7aEKtT4JFbfw 899Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720419318; x=1721024118; 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=EQIqWVaUpLW7tNHj4brQfTw/7FKBab3/cxzq1ObVSc8=; b=IJMBejVL254v9ohpiXfFTnBswKBc6kQ6LtA7gl01bQYUcmV+SZbcRYNLN4nDuMnMAE 1BChBhDxfgeXlxdswW4TY3BEmejbxuxN8dIlw6lMHyD3Ks8/4eSDDItVv3YZK0WWUaRY n2X+mG9mbiY88/GO1ysqdQdzdNB8g0ehpY4nvAgY05mcc7geC9yB9mPJN0ejKRH1OvR3 4yp/H1jExaeA8cvwQFnncwiPhfvDO76JJu+SJP4nHVqkdLV7p3mqeGRq4TXKGK9l4hiT iXQfT/hv64Y6pa8fbQfI3suDXYtOmZvs20E5GDUNax5QEQ69uuqxkFzNZpsTD1N3mXFr EQrA== X-Forwarded-Encrypted: i=1; AJvYcCU4QjBFKNXN8VdfngwSE8gtcOHm1HETAt3oaIlOK7NkTX0c6+X/+O+zjxxrqJVuHUgiym+ikXsrYPo9XCEhbWlGKGo= X-Gm-Message-State: AOJu0YyI8IsesG7Ew79hcovwcMSjpy5ZFtH7pO+2jjaEivtBlrXrceSV FCVbfbbOhheo/HMgIsGkJeu9K1jNu6g02qDHSOG58qO0FdWM6PMS X-Google-Smtp-Source: AGHT+IGHGlicSVY55FROKSe9KZmtjkxvug0KMI9c/n0YLb3ZClpmuNJ7SGyya4Xv5GO73u8uYJv2lg== X-Received: by 2002:a05:6e02:20ed:b0:375:a3d8:97a5 with SMTP id e9e14a558f8ab-38398b02a27mr156595925ab.5.1720419317691; Sun, 07 Jul 2024 23:15:17 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70b2585e8c7sm2425736b3a.171.2024.07.07.23.15.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jul 2024 23:15:17 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Barry Song , "Huang, Ying" , Chris Li , Ryan Roberts , Kairui Song , David Hildenbrand , Chuanhua Han Subject: [PATCH] mm: Extend 'usage' parameter so that cluster_swap_free_nr() can be reused Date: Mon, 8 Jul 2024 18:15:02 +1200 Message-Id: <20240708061502.9006-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Stat-Signature: nyehiyezk4ukdiaj96bj8zr4rm9busx5 X-Rspam-User: X-Rspamd-Queue-Id: C29F220009 X-Rspamd-Server: rspam02 X-HE-Tag: 1720419318-152221 X-HE-Meta: U2FsdGVkX1+1xnoDQlklIZRQEGr3DJQgbVzd/lppE/24eJ1ugpLJnvVq9BgRSHUZk6p5MUQ3CrRhVLSUeGwU8KlivTcKObDusL9iupWbbiqJn5y29oWece2s9ToONOpZ2n7+mGu+eSimhiDvN2e/EJtSmFeI4rytZcp8UhY6qfDnWxtTG2gA0TxA0/NNoOW4NK6rWrN895pGYUlfLeVo+4/pDaPldzNcdAKydmaRula63zupjJ7T6rtGhOuQP9w5rvJregiDHV0E5o5oWYtzxTeUgKSaznjpEv3vG6Zu58+WL1ee1LVP6cD5oNq5580BLggCRawUSx3T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yiHi7R9SU8BKDtcZh7ueJapKmF67t8GphT2MoZwZ6/vtNKh1rqjYAzf6LKuffmUsYbjjEVkYjzQLwjnc301bfxP2QT7DZdogU+EG7USM0RImMMf2FlEnwOyHE7g9VM0CyIdu+7SoS6zP+NMDsEyU0UnXpBBUAtV25GR2ZIfFOY/8YGpjv4dGgFZcUaRlY4l3JguVOeLH4i5R7yqp1knDPFIvCc8P14ybeGcCXYmDXZqRZAyclOJPYT3Djh+KpwchkkCbXToRqBcGMY+pkQfZx7z6/Y337IM9veCZBxqE= 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: Barry Song Extend a usage parameter so that cluster_swap_free_nr() can be reused by both swapcache_clear() and swap_free(). __swap_entry_free() is quite similar but more tricky as it requires the return value of __swap_entry_free_locked() which cluster_swap_free_nr() doesn't support. Cc: "Huang, Ying" Cc: Chris Li Cc: Ryan Roberts Cc: Kairui Song Cc: David Hildenbrand Cc: Chuanhua Han Signed-off-by: Barry Song --- mm/swapfile.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index f7224bc1320c..70c4a9132672 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1352,7 +1352,8 @@ static void swap_entry_free(struct swap_info_struct *p, swp_entry_t entry) } static void cluster_swap_free_nr(struct swap_info_struct *sis, - unsigned long offset, int nr_pages) + unsigned long offset, int nr_pages, + unsigned char usage) { struct swap_cluster_info *ci; DECLARE_BITMAP(to_free, BITS_PER_LONG) = { 0 }; @@ -1363,7 +1364,7 @@ static void cluster_swap_free_nr(struct swap_info_struct *sis, nr = min(BITS_PER_LONG, nr_pages); for (i = 0; i < nr; i++) { if (!__swap_entry_free_locked(sis, offset + i, 1)) - bitmap_set(to_free, i, 1); + bitmap_set(to_free, i, usage); } if (!bitmap_empty(to_free, BITS_PER_LONG)) { unlock_cluster_or_swap_info(sis, ci); @@ -1396,7 +1397,7 @@ void swap_free_nr(swp_entry_t entry, int nr_pages) while (nr_pages) { nr = min_t(int, nr_pages, SWAPFILE_CLUSTER - offset % SWAPFILE_CLUSTER); - cluster_swap_free_nr(sis, offset, nr); + cluster_swap_free_nr(sis, offset, nr, 1); offset += nr; nr_pages -= nr; } @@ -3492,15 +3493,9 @@ int swapcache_prepare(swp_entry_t entry) void swapcache_clear(struct swap_info_struct *si, swp_entry_t entry) { - struct swap_cluster_info *ci; unsigned long offset = swp_offset(entry); - unsigned char usage; - ci = lock_cluster_or_swap_info(si, offset); - usage = __swap_entry_free_locked(si, offset, SWAP_HAS_CACHE); - unlock_cluster_or_swap_info(si, ci); - if (!usage) - free_swap_slot(entry); + cluster_swap_free_nr(si, offset, 1, SWAP_HAS_CACHE); } struct swap_info_struct *swp_swap_info(swp_entry_t entry)