From patchwork Tue Jun 18 23:26:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13703157 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 7967FC27C4F for ; Tue, 18 Jun 2024 23:27:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC2716B03D4; Tue, 18 Jun 2024 19:27:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D47296B03D6; Tue, 18 Jun 2024 19:27:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE8CC6B03D7; Tue, 18 Jun 2024 19:27:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9DC5C6B03D4 for ; Tue, 18 Jun 2024 19:27:02 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 450B7A26AF for ; Tue, 18 Jun 2024 23:27:02 +0000 (UTC) X-FDA: 82245597084.11.D5E407E Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf29.hostedemail.com (Postfix) with ESMTP id B056312000C for ; Tue, 18 Jun 2024 23:27:00 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf29.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718753214; 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; bh=8rhHmrdIQQp7zLMWL//6xeZhYwQubqijSMco3o0xBWo=; b=Hebg2usqUiR0/feAVu4fDjtu9TscKIy3gv4/MKt5LUVmLhMkgTHrwXQbY/4zYeHJDRUYjD i8W++V4gDmFu0V3WT/FGdsXiuMG5VC4YAVRRdrdkw8HSXki5JDwguZGRLsICZU1D3vmVgW u1ug12zUBmRTgVeJ3eHZMlEzGGKXn+M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718753214; a=rsa-sha256; cv=none; b=FvTceEq8YriVsCJeXEuPTyW78tKN4x5CgLjlHVvI81NI4RR0xS5HwwuyE9iZ/wabzHVu7Y xbT9gJazDQ8d1dEuzcrsnR8VbvJNLeCg2YFdiJQwt37mzJhkP8aX2HM/+T2K0Aku92or9u qjs+Es6EudIP29ukiIKmq7vGUOFmsXw= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf29.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5CD461042; Tue, 18 Jun 2024 16:27:24 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EECF83F64C; Tue, 18 Jun 2024 16:26:57 -0700 (PDT) From: Ryan Roberts To: Andrew Morton , Chris Li , Kairui Song , "Huang, Ying" , Kalesh Singh , Barry Song , Hugh Dickins , David Hildenbrand Cc: Ryan Roberts , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v1 1/5] mm: swap: Simplify end-of-cluster calculation Date: Wed, 19 Jun 2024 00:26:41 +0100 Message-ID: <20240618232648.4090299-2-ryan.roberts@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240618232648.4090299-1-ryan.roberts@arm.com> References: <20240618232648.4090299-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: B056312000C X-Stat-Signature: nk1g4zfyzbtoi8i3wwrfmy8jj4okq6as X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1718753220-411802 X-HE-Meta: U2FsdGVkX1+yTDrZcQ5JikBqfgbF43UIlUtv64sSxW7UlVbuR4i6KHuWr6ZjUTGKWhbSR1Usjg8Of9OF8qDKCfO4dDWg1AhZiZsN4W++gCS7CWTj73uniWb+rywmjiWxq8oaVSFAS2kMyiRlCGLCiv/aIWZ1rT4Cs4C29TDDtJ5xz8MzHCIwLxXT728SriZ3IwRtuZlgkz1Q0V5NRxWGKsbgI7A/zQvAgBRKdZVRvV2RVP0SkAJSUYjJ3f87BGAdmznAFRSNxKfQmBUnaJsHYPgzJXfORlRICtHAbobja+ms0pfpomg8HWAEdLz3cBmT8JYMPKOe4pAsVARnTIPY2mPDZiBnQWN1R8/+o2pkHzAu0CTX12N1ikbrn38VLVHWa8MDU12C6PpIEgypRuauAjVHh8FVq5Cu2AMSPkFi8izSbkhQcvfxsaH5ROJ2Zc96DxfVI53UWO5pAlFMY/JnEbX3dOapo6igTRgRuOnJhazXnhCsTWc+eLP6XuwpZmzA+SzUiwVNk+ehzRTpI+O2bcGSofk/e3iZvY4lAArylSasYAAE6swBrxbBtCXHmi8F+5dw8/t4cQ8lsa0PaEsEBjGUhy3Bq0zvGNSrHJ1mm+L2Y/5ruixvTZnJxsTfmp4mICTicB6SrzU75uqdeRzsfCdIAwg9KWvaXcGfx0koHjX4qRsE4YsoXwN/sM9aMZoMFcG38m75XqZTSfNDK+nOzOFcB+9jtmEUf5e+5HEMBeR8dcBNy3bvuE3LLxgdlWFMO9q2kO5zXcs8+LmRPjZ/JgLURfccw9wPokzdHi74nr4Gx7341fQi8i9P7HpYtxLf7N7hag+Grv23etOTvla3puynQua9yDgw1B5ZbWvvWwPWeIf26kqQdL0w3bXExPSRTPJW8ngW29XvKP9YHurGlBTxdRdAhcXSCkx/6fL38rEcsQB8hwXYFrgWuaOXYr/gGhl0f5cFB8/TEn3GUTL 43bktwip T+mfcPKzUvsz75yDmh1yYS3cGYMkqWH4p85CMSjm/a/gKGrG9ZPulPmq6iASr+4H8et3YRBShrmYadY5WwUb3QSVT/IO0rh5yVqj91r8eqshShmJGsR5QipdwiqQ/gGy4cPLKAjCcSONa3cABVsY7Yz8O+w== 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: Its possible that a swap file will have a partial cluster at the end, if the swap size is not a multiple of the cluster size. But this partial cluster will never be marked free and so scan_swap_map_try_ssd_cluster() will never see it. Therefore it can always consider that a cluster ends at the next cluster boundary. This leads to a simplification of the endpoint calculation and removal of an unnecessary conditional. This change has the useful side effect of making lock_cluster() unconditional, which will be used in a later commit. Signed-off-by: Ryan Roberts --- mm/swapfile.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) -- 2.43.0 diff --git a/mm/swapfile.c b/mm/swapfile.c index b3e5e384e330..30e79739dfdc 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -677,16 +677,14 @@ static bool scan_swap_map_try_ssd_cluster(struct swap_info_struct *si, * check if there is still free entry in the cluster, maintaining * natural alignment. */ - max = min_t(unsigned long, si->max, ALIGN(tmp + 1, SWAPFILE_CLUSTER)); - if (tmp < max) { - ci = lock_cluster(si, tmp); - while (tmp < max) { - if (swap_range_empty(si->swap_map, tmp, nr_pages)) - break; - tmp += nr_pages; - } - unlock_cluster(ci); + max = ALIGN(tmp + 1, SWAPFILE_CLUSTER); + ci = lock_cluster(si, tmp); + while (tmp < max) { + if (swap_range_empty(si->swap_map, tmp, nr_pages)) + break; + tmp += nr_pages; } + unlock_cluster(ci); if (tmp >= max) { cluster->next[order] = SWAP_NEXT_INVALID; goto new_cluster;