From patchwork Tue Jul 9 01:21:22 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: 13727160 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 DB45BC3DA45 for ; Tue, 9 Jul 2024 01:21:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 738676B00A1; Mon, 8 Jul 2024 21:21:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E8336B00A2; Mon, 8 Jul 2024 21:21:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 587D96B00A3; Mon, 8 Jul 2024 21:21:41 -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 358A26B00A1 for ; Mon, 8 Jul 2024 21:21:41 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BA3C8A4E20 for ; Tue, 9 Jul 2024 01:21:40 +0000 (UTC) X-FDA: 82318461960.28.124636A Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf08.hostedemail.com (Postfix) with ESMTP id 04834160002 for ; Tue, 9 Jul 2024 01:21:38 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=VqsyNB3+; spf=pass (imf08.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.175 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=1720488083; a=rsa-sha256; cv=none; b=oeqbHxAYDTvZ6w1S23vjZLk7e3yLbUFgPIrFbYxflxS0j0CKBNvGPCNTi7MuZqTESb9Oj3 rOa4aA0rAUcMdzdEjUxY8iGbWKdD402lUmkKlneU0Aqqv8rzsLMHn+hL2zcJiGSBLlghla uiOU7LKCAkUGARK0TSC+EMbYNIIbi3I= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=VqsyNB3+; spf=pass (imf08.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.175 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=1720488083; 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=rp5LIY/csjN1lG+GtCfJFxmKq047kymV7T1r6/i6YSU=; b=0RWzB5QNqIS4EP/4l7VCHaX8R0cpsk6OMtJX82QykwX7ywhsU7xQ5GzLGnKmWxVZNvPMYs 3Iyp5Cye7cvHw43Qb55QBSoziHWtJiIt2ONRcWY+K9TmfsyyTYSwC68a6fTjvlzuHIqc39 XmtrBfP4ICTGJBr/Z5DB/RNX9sNdF9w= Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1fb3cf78ff3so29027025ad.0 for ; Mon, 08 Jul 2024 18:21:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720488098; x=1721092898; 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=rp5LIY/csjN1lG+GtCfJFxmKq047kymV7T1r6/i6YSU=; b=VqsyNB3+tLKhrq37tIpU6pZAiIkR9IZmkFwpmniMYBtSfoS3ZGhnVzdxBVlgWmDNKG 1w7uDS+GVJWT1mjwK47WvirEmOTMe3jb4TLv4Nzl8MCeO5qJywWd9gbUPVAJc0iT/opE HJrgwiWvseIlMQe+wgDoMdsIJpn2aAzA//XicnIHT0y/em3GGifv9MV1n8X4sOnVw9+J C6dtEz5BBMPO1BLXwuMqtnxVPn9iZpKIvEHzjz2Vaz9MzyXbymUbujTyaJ1MT+TlcUEy xztqhzzSEbZcXT88QTu1VwiANy3ZmR3M5AmNfGZNPSmNVGW2uYdiWsGtyRIdwHZ3j+29 5fiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720488098; x=1721092898; 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=rp5LIY/csjN1lG+GtCfJFxmKq047kymV7T1r6/i6YSU=; b=gCFSe6hNgz4+Wx7p3tcBUkLbhBNaFZQDlqfREnGuTahdnaeDR+i0jadg9JIawP7BmU b8CjXw5L23Nr7y+GFcB7MDdTY1l91J1eLVV9rKcqacmSdiRNt+Qy1V467L+A2lX73gLQ /ULnKzJ/tDO+vNxsbmKzb9lXBy0AGrdV0UeNVFiTlQBX14ln+nok63GhAVDm0CohUOuj sHJNeWpv7WiEKo9hV1/y3u1E/S/nRxhP2QcbMI/8ZBksaPgKQfugEugBVqseYX+o26Yl pyjUZzSqmXGwDR4EqMbpbGz1HoMhBHxpMNsbD+cbdjCKXsf7y8hcNkoysKS6gl0wAuKx nDKw== X-Forwarded-Encrypted: i=1; AJvYcCUxgRS+4e3RWlSpAjVXs6BGKulTlgmP9Bp+tEM9LV1RZ9/fnhPKDmkHbytNJuwwSTAb2x70ct3OoRS6u/m2sIj9rKE= X-Gm-Message-State: AOJu0YyLSU+EXSNExL6vZXCYMphjm/erYyR1EzQitzG7NxRLDoXUKvlW XMN3vwqrMsAWK5uK3h2pZDMp9Lcs5fOo+pfWVyfZIHCgsaj7sYdb X-Google-Smtp-Source: AGHT+IFwt7lbvTqeTvAwSBA7I39AeW+RkqFofI4QK5RRnNC/qFaLuMwKyyKjN4ysz3LU5RPkMqmueg== X-Received: by 2002:a17:902:e549:b0:1fb:46a7:dbda with SMTP id d9443c01a7336-1fbb6d89a46mr9779605ad.47.1720488097664; Mon, 08 Jul 2024 18:21:37 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fbb6a2a72csm4792395ad.77.2024.07.08.18.21.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jul 2024 18:21:37 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: chrisl@kernel.org, david@redhat.com, hanchuanhua@oppo.com, kasong@tencent.com, linux-kernel@vger.kernel.org, ryan.roberts@arm.com, v-songbaohua@oppo.com, ying.huang@intel.com Subject: [PATCH v2] mm: Extend 'usage' parameter so that cluster_swap_free_nr() can be reused Date: Tue, 9 Jul 2024 13:21:22 +1200 Message-Id: <20240709012122.16994-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Stat-Signature: jb4qit3ub3bfs3by7yj79nrs6mobwyie X-Rspamd-Queue-Id: 04834160002 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1720488098-924047 X-HE-Meta: U2FsdGVkX1+Bk2daIAqnFdaYww0rflZjUY75C+XfnbTsvFk/tj+xatIZt3815FH8K4lIXfpnVFlF+J4G5IsEsO2/9TCnhnTy+Mb0zkup0geg3XM6+DxMMnmuhGwNsFweN9cv/ur9G/nx8IT1tDHUd21ZfsBr1xwCdlhIAVSm3s0c/+Z9h6UVq0jeZadgg/3PiNp5ccWH6ePzgid6Xe1Oi9e7ZdURSv+IFJ2m/yQq1n6lQXARtmFis1g2K/aTxh2LkpqpkrVTYKIOI4DWRerW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o+vWtg9G6zsurAA8zIif7z8ZEITpDCbQBQmihjLGZWV37KFyrJscdTS7RcP7M4OLUIVXFKhZH3ig5vzx9dM8WhCZXwE4VB62Lvl+V/KzKa2q+mBpgm6Ao/znBTvJyrYyNsHF4/g034FvIRW/l9/iv8p4cwKzP3hHXP9VA6lZTmCtMGYYujiL7HyqwRFCuachq/D75pWUXghNecUJ0O6e7xpmpYsw4LftuFUrSuqRAuhnW0cG2WxR2vikC+J5ckoMPlaNLAe8KJZP+TsQV6EkhgaKpbeAWgypkhDpXSiFwbBAd1uH5CGZWDwYFrXhMebRFl4lz 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 Reviewed-by: Ryan Roberts --- mm/swapfile.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index f7224bc1320c..c097c513db02 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 }; @@ -1362,7 +1363,7 @@ static void cluster_swap_free_nr(struct swap_info_struct *sis, while (nr_pages) { nr = min(BITS_PER_LONG, nr_pages); for (i = 0; i < nr; i++) { - if (!__swap_entry_free_locked(sis, offset + i, 1)) + if (!__swap_entry_free_locked(sis, offset + i, usage)) bitmap_set(to_free, i, 1); } if (!bitmap_empty(to_free, BITS_PER_LONG)) { @@ -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)