From patchwork Wed Jul 24 02:00:56 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: 13740551 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 D2331C3DA49 for ; Wed, 24 Jul 2024 02:01:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C5C96B007B; Tue, 23 Jul 2024 22:01:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 54EE76B0082; Tue, 23 Jul 2024 22:01:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C8EA6B0083; Tue, 23 Jul 2024 22:01:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1E1C96B007B for ; Tue, 23 Jul 2024 22:01:14 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B6436140586 for ; Wed, 24 Jul 2024 02:01:13 +0000 (UTC) X-FDA: 82372993626.15.64C621F Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf27.hostedemail.com (Postfix) with ESMTP id E5E8040025 for ; Wed, 24 Jul 2024 02:01:10 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AMn2+1MO; spf=pass (imf27.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.216.44 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=1721786448; 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=LVUcSmjoF8uFIYy2DZhQyn83BKjAD1GneoeqabmtAz8=; b=r3kHPR4AlzOEKqcOkVA/zKW2Oht7RWqVXQBdNST+2OV38KTlIP+UFMO0R2YhasfRajI9Fb /UcQbY9Vk1D9n659E/7xMV7wwAvalShuxg7ed1lLOUV64owOzhKPJC5ZauNhBMy7YG608l mk9WlTV/poPLMM5cK1JafF2HWlxJUhQ= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AMn2+1MO; spf=pass (imf27.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.216.44 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=1721786448; a=rsa-sha256; cv=none; b=GShGbIJqu62BN25vC+C2lBTxF+l4QNX723ciepl85g7VWUf4069uUv5XDKUTtSNLpSkrDQ 2DAH/JnepYhW19uSj5K/6WjgIpV9qbGnc8jAhNxS+WilRbgt2udQOm8ZXnn4Oa8/9MWreB DSMs2QTwuu/om7j7SJeKaNtB3/kLwk4= Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-2cd34c8c588so1857079a91.0 for ; Tue, 23 Jul 2024 19:01:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721786469; x=1722391269; 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=LVUcSmjoF8uFIYy2DZhQyn83BKjAD1GneoeqabmtAz8=; b=AMn2+1MOK6Ie3p6A2PXQ/uPJGqt0EWzF5f9M2m+P9am/Sa7moE7iwCQ9+g6eMTa01E 22FwJ11k8tCPhoNTPE6O5XrRo9oSk0b7fEdwUlo2uOa4sAIxvevIP6Ska/Kkr0oeyl1Z XH9xXXfPIDKXo96Ugwl0gXrAmjTxajozGXKd9RGY6Dm5zYiY0jr2kgaeoqYG9j+ZDyqY iH2ToF+weUSbo7O104rLdmUMt/mJRC+63HXN79s0m8XfZl6v6bpD2C07cQMlB998u4tu FDAmdVkh9yY5cLJHycR1/rGnlwdSZY314m63ypKsPUQ/+DtdU/EjemISWefuLLrFQJ1J HoOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721786469; x=1722391269; 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=LVUcSmjoF8uFIYy2DZhQyn83BKjAD1GneoeqabmtAz8=; b=P1YLuhoczyvBMt2B7beBe+GRKI3FVJJ6Q6axBR8HEQzPY+q5NUkr4sl2fuvWMQftTj uB6IyKjazwH069dEF05Me3iVHy6zGZi0FuC3GqRMs29j/4hQEdfqsvvtEa39fIVeAaZt gi8d8zfLUSD8KwV1R2rIgJjDTQ7bY/5nBqEvoZHxu1mC3aoHrp/Mm/oluCgfMRpmx7UJ vYRyv1naUSwsB+OzFhH6YUTmKWxoajYSl2J7HW6gebu2lqvW1RlEgafWyY3PYMusQtMj bz0Sbr3hufjcO7CE7Z/1Gr/vArFAybHAvlklzA4VxfZ97P6U8O6v/RwCTVXuG+YKypka JIIQ== X-Forwarded-Encrypted: i=1; AJvYcCU4rZoHifVgM6s+/N9RmJ88KtOvnxOAzcx1ysApxqAeRVb8loN4v0wfpM3bPOUjQeoqLVB9IOk6yHTi3u/s/46c7gE= X-Gm-Message-State: AOJu0YwfgEriQ0kbVLrfwzgKDaSv2cKOTgAlVviDjQcTNY+gUfGpFQne iaLdnaXxqVWkhcr08usG32t2DYfbv0Fooc3+FhHiC64NQR2Urw79 X-Google-Smtp-Source: AGHT+IGajzuaNCAxSBXn7gIE6oHhkTvGkNCn2JCeYtx4lkKmPSG7JAN/pWKAhYOO9i7LVKx/K2CQBw== X-Received: by 2002:a17:90a:fa8c:b0:2c9:a3ca:cc98 with SMTP id 98e67ed59e1d1-2cd273ec800mr7829077a91.7.1721786469414; Tue, 23 Jul 2024 19:01:09 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cdb747c703sm323634a91.44.2024.07.23.19.01.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jul 2024 19:01:08 -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 v3] mm: Extend 'usage' parameter so that cluster_swap_free_nr() can be reused Date: Wed, 24 Jul 2024 14:00:56 +1200 Message-Id: <20240724020056.65838-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: E5E8040025 X-Stat-Signature: hxjwzgezs6qqfomisgckxqcpa5t9qg5h X-HE-Tag: 1721786470-613054 X-HE-Meta: U2FsdGVkX1+3pR/h5zU22EHoM2HIf1pQqXhrkXT/e3G8HPniXkLZiqBy1Y7YIe19pYcNXX5fyIRm4peldaNxNZMUteWk3fbdB7zvN7fto08k+lDg7e4bh5rJYuLBZCbFBOcrQ/aWmsF4IZXolLN2KtQiKn2dZMX3jquS2V+f+eyN/qSG5Rjaw1uHmkRRKrmlfmB0NpkP5Qr6KbhyPdFEmpyUXuFkNYUlUvcIwld51STVs9QKmUFSOS0kgMfZYXV2Ll0+Zl/DKi/PXY0PRY253DgIVilhK6F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eHqp8a12pX9C54e7HFk1+I1NOghniFR3Ugq5AnBm7zHUTywO2EE4CcVgn8d1J9TLh1siCITRQ38TyVD/3moO/vGnBX+ciF6QwnDWj4VDy4wLSSKVTKlrZDys2JSF7PPm/CgwTEWGkNPoGcZhbuxa00RrAmVUJdlQZsb/TtfqZASuLyXEyyTQLbuMEwgQS3t/+51yVqWDGzVH0qs3d3CNyw5jXRxkmPokAc3ZRdUHJE2biGZ3dRWK0ztV5zTTxmuhDMbdEKUgSk4q3Uj4dX8y/aowdxhwe3mOuRvKvbLAl7LTVua+lNjnqKgI40465zko5/KRNe89UzLo= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, 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: Kairui Song Cc: David Hildenbrand Cc: Chuanhua Han Reviewed-by: Ryan Roberts Signed-off-by: Barry Song Acked-by: Chris Li --- -v3: resend &collect Ryan's reviewed-by mm/swapfile.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 38bdc439651a..5f73a8553371 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1344,7 +1344,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 }; @@ -1354,7 +1355,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)) { @@ -1388,7 +1389,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; } @@ -3472,15 +3473,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)