From nobody Sun Dec 14 21:37:40 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BEDF22A805 for ; Wed, 5 Feb 2025 09:27:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747661; cv=none; b=GHpmnE23rWkpIX1pAalGNKXfsFX3ZMxDzbbky2NfE8zehdWQnLEHBOuRVggcyETZuZfZTu7YkDyr6HbbGJAzeXO4bO+godoh2yyaQOJc1wAmedPzsGTXXtWD3nVtFckwTMI+Fxsczln3aBiw8U8twi1ziGN9WxZmDA+JC2XngSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747661; c=relaxed/simple; bh=3QJj2ATHGlTaz/6pj+vvdZyvAhks2vwRPV0D027mm9E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=Zfhp/OhN9FCgO8HQoAlB2kESbup6uUO/LzdCOfqKODqnzftNqv2E6GJ2IPT581xzzZww4fjsJxd1/bkqo6R7EzPB43FEIcaYlYbwOWVOx7QGhf3rMrdwKI5VltVCLCgmx40HR1i6Gy+RWv9BF+pSRQhtlostfrgBxoO3deXmVmM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=XAU1pNK4; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XAU1pNK4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738747659; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=90rRcO0x8Pvov1XWHGz55JZuNeq5fISSOHzEENgRMag=; b=XAU1pNK4zy9U1Q3GVcFIShZPP9DSiZwY3zvKjoZvXBIALy59HouX6+DaqggKABdGCGHEdF kfnKd+G46x2Oeb0Sg4ClrVenmsVYkvHoY187x/wCrIG/Rqpn6dsr1D3wWCSxt6PRsnQzw0 EtLmPkg0rIIvh9WOiUuwfbP69N1Bc9I= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-524-w343ZRs9MHuMWo5S_cZR1g-1; Wed, 05 Feb 2025 04:27:35 -0500 X-MC-Unique: w343ZRs9MHuMWo5S_cZR1g-1 X-Mimecast-MFC-AGG-ID: w343ZRs9MHuMWo5S_cZR1g Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1A3301800879; Wed, 5 Feb 2025 09:27:34 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.112.190]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4501F300018D; Wed, 5 Feb 2025 09:27:29 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, ryncsn@gmail.com, chrisl@kernel.org, Baoquan He Subject: [PATCH 01/12] mm/swap_state.c: fix the obsolete code comment Date: Wed, 5 Feb 2025 17:27:10 +0800 Message-ID: <20250205092721.9395-2-bhe@redhat.com> In-Reply-To: <20250205092721.9395-1-bhe@redhat.com> References: <20250205092721.9395-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Since commit 85a1333417a7 ("mm/swap: use dedicated entry for swap in folio"), there's a dedicated field in folio for swap entry. Let's update the code comment above add_to_swap_cache() accordingly. Signed-off-by: Baoquan He Reviewed-by: Kairui Song --- mm/swap_state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index ca42b2be64d9..59acb55174c8 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -85,7 +85,7 @@ void *get_shadow_from_swap_cache(swp_entry_t entry) =20 /* * add_to_swap_cache resembles filemap_add_folio on swapper_space, - * but sets SwapCache flag and private instead of mapping and index. + * but sets SwapCache flag and 'swap' instead of mapping and index. */ int add_to_swap_cache(struct folio *folio, swp_entry_t entry, gfp_t gfp, void **shadowp) --=20 2.41.0 From nobody Sun Dec 14 21:37:40 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FD1922ACDB for ; Wed, 5 Feb 2025 09:27:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747664; cv=none; b=nBztgI2VXED9xNs1RP0vOVYKDh2gsH5LaN/jUjfNoiEkGqrFFTLAu2QFNmjNXOark/XVnFvoySIPWJxdS76mE7jXXpzgH/4xCFCObpTvKrzi7jMVXmif56T7xqrCSoIFI+GulTC2nnzQoq6dNr98NCd4PcSa1Gb2flgWEecWNiU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747664; c=relaxed/simple; bh=htxj+bWHENt32tzdhENMjig1Xiq7Vr7xxUAtVgbBj+c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=ixp9VOiZ3uA3B8gNaU1B1hM+WpuXY0BfrCmBtmdVvA3JkR95wxWiUSDDh8GYZfiFGWTgwDkg5g/X+F6KuL9ZK2hU7McliLqAt1LDqu3Dy0FlFnnSuoJMuPsZxYfXiNKWA4yAnW6Y4XMM5WLJC+Zgaa3rZavfFCvk6O9BtOkGyBg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=AUm5kpmL; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="AUm5kpmL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738747661; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PEv2tk/qqvPIGyGgURFAveF2/GO9Pp83Lj9RTkxNFck=; b=AUm5kpmLadP+EmKsRtd/OaTyC53H4X3NU/+cghB0qvfp5T6JxhmD5rPLpFv/A8N4YlGbTU dm54aCfXhIsN8F49//Aaf8LAYXjdglT4xTt+8yrocK4YrCci9XnTrGnWR7Nt9OeIqYLlDw vywjPHz7tMj8ZmB4xc3nKSs0wVzO1s4= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-502-U3GOdD5xNBmPUDlD5LmxzQ-1; Wed, 05 Feb 2025 04:27:40 -0500 X-MC-Unique: U3GOdD5xNBmPUDlD5LmxzQ-1 X-Mimecast-MFC-AGG-ID: U3GOdD5xNBmPUDlD5LmxzQ Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DD8991956086; Wed, 5 Feb 2025 09:27:38 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.112.190]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 01736300018D; Wed, 5 Feb 2025 09:27:34 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, ryncsn@gmail.com, chrisl@kernel.org, Baoquan He Subject: [PATCH 02/12] mm/swap_state.c: optimize the code in clear_shadow_from_swap_cache() Date: Wed, 5 Feb 2025 17:27:11 +0800 Message-ID: <20250205092721.9395-3-bhe@redhat.com> In-Reply-To: <20250205092721.9395-1-bhe@redhat.com> References: <20250205092721.9395-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Use ALIGN to achieve the same effect and simplify the code. Signed-off-by: Baoquan He Reviewed-by: Kairui Song --- mm/swap_state.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index 59acb55174c8..d7cbf5bb2450 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -270,9 +270,7 @@ void clear_shadow_from_swap_cache(int type, unsigned lo= ng begin, xa_unlock_irq(&address_space->i_pages); =20 /* search the next swapcache until we meet end */ - curr >>=3D SWAP_ADDRESS_SPACE_SHIFT; - curr++; - curr <<=3D SWAP_ADDRESS_SPACE_SHIFT; + curr =3D ALIGN((curr + 1), SWAP_ADDRESS_SPACE_PAGES); if (curr > end) break; } --=20 2.41.0 From nobody Sun Dec 14 21:37:40 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4681922A7E2 for ; Wed, 5 Feb 2025 09:27:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747670; cv=none; b=SwMHNCvqsS3TST5c0pTd0LM5tHwcFPdsg+i+TjEohNaWYOY5IEkrcTb1Jw0oNd6+OYFwV8QlnRlsrDL2iZt3UlVi3v6cuANuKhVdfiFcb2rV8u8mc+anhcpyGheRvQ9FMEPF8HnHSCQLRE/NFo1DQMGkSQmLM44z8paBumhVG9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747670; c=relaxed/simple; bh=rH9uqqW7zoZZHLlRdOhy7KJzkID/K/4qLZMQozalwPk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=uqGnzKsPpP7DLX8QA0mp2HXe0NU3ARSYrCIcdif1+++7kI1m+Saby4o5PTjyWpd+PI7vwq48nhWnRM+qvqBlc7hvti+yd0nASittR1WkDtys1bx6gLfq9OgXBv9Wprjv8fBRN7pxGNw/tNAudkztkzhrrQFL9oMZ2N/MUyvrD94= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=edx0bBOS; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="edx0bBOS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738747668; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FIOS+/tyiatrDoGbeFH0VR1TEwzBCwvdDVquOSZT3r0=; b=edx0bBOSawWwYb8EW3pgqRjK2bf46ES9G6fxIPjRr5IynWbTcF8qrKiBrwRGfWzMbfyq4U z3qxPg2xjYMgD2rL8vQ3WRtFssubDFIjLxXNHlNpiFNaW5WuC/UXTlHtfsd2f5Ba6mUZsW 4D3sjBVOy8ewfzVchrCsW8ci5kjsP4k= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-626-BmsBWnX8OmGC-bxlcS6guQ-1; Wed, 05 Feb 2025 04:27:46 -0500 X-MC-Unique: BmsBWnX8OmGC-bxlcS6guQ-1 X-Mimecast-MFC-AGG-ID: BmsBWnX8OmGC-bxlcS6guQ Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A05631801A3D; Wed, 5 Feb 2025 09:27:43 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.112.190]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C4E203000199; Wed, 5 Feb 2025 09:27:39 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, ryncsn@gmail.com, chrisl@kernel.org, Baoquan He Subject: [PATCH 03/12] mm/swap: remove SWAP_FLAG_PRIO_SHIFT Date: Wed, 5 Feb 2025 17:27:12 +0800 Message-ID: <20250205092721.9395-4-bhe@redhat.com> In-Reply-To: <20250205092721.9395-1-bhe@redhat.com> References: <20250205092721.9395-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" It doesn't make sense to have a zero value of shift. Remove it to avoid confusion. Signed-off-by: Baoquan He Reviewed-by: Kairui Song --- include/linux/swap.h | 1 - mm/swapfile.c | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index b13b72645db3..20bfedc8c4f2 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -24,7 +24,6 @@ struct pagevec; =20 #define SWAP_FLAG_PREFER 0x8000 /* set if swap priority specified */ #define SWAP_FLAG_PRIO_MASK 0x7fff -#define SWAP_FLAG_PRIO_SHIFT 0 #define SWAP_FLAG_DISCARD 0x10000 /* enable discard for swap */ #define SWAP_FLAG_DISCARD_ONCE 0x20000 /* discard swap area at swapon-time= */ #define SWAP_FLAG_DISCARD_PAGES 0x40000 /* discard page-clusters after use= */ diff --git a/mm/swapfile.c b/mm/swapfile.c index ba19430dd4ea..9c9a4ec6d4c6 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3449,8 +3449,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialf= ile, int, swap_flags) mutex_lock(&swapon_mutex); prio =3D -1; if (swap_flags & SWAP_FLAG_PREFER) - prio =3D - (swap_flags & SWAP_FLAG_PRIO_MASK) >> SWAP_FLAG_PRIO_SHIFT; + prio =3D swap_flags & SWAP_FLAG_PRIO_MASK; enable_swap_info(si, prio, swap_map, cluster_info, zeromap); =20 pr_info("Adding %uk swap on %s. Priority:%d extents:%d across:%lluk %s%s= %s%s\n", --=20 2.41.0 From nobody Sun Dec 14 21:37:40 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B5BA22A7F6 for ; Wed, 5 Feb 2025 09:27:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747678; cv=none; b=AbYnes3/dKIooWK3Ci3lk1SymRIuAv+3HuQ84mwhg95GihJgRf5FPr2boCuI29XpgfUJpg0scTPKv5y85JDrx8n+Gx6KAN6Yah4EsMPLcDFF+dYWRGdCFREZdiezb6xd7hiBdb4lNzRzmskvGnM98jmU/ZO1isUbvfuXGXGTZ98= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747678; c=relaxed/simple; bh=JKq/u3TB5ClLQq1auU3QmTor7N2cvlGqSJu5d/umTgA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=FgI8kNUFAHS5/i90J5cFaLNgDdSod5irX1URqxUOHxQ/cEFeOEfuHrMJNTWIYJzDx3LoznquPQzTYlfSFzj9WO4h78dEaDLZjBMfbGkzFZx/plloXos6wAnzaHRT0CwzL+a5zaBkDoJhH5WJhA9Q3CpLy+IQCw1zJQSbl/fzybM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=PW05TksU; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PW05TksU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738747676; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=baZcIm7AlnLIRm7Dd7CyR7YXStnIxeq19AKgfb6y8wo=; b=PW05TksUdSHuosAU43QAXSbEfQR9IZG+kxHEHOjJXQyQGwFnGhNj2UtmPwGx+LeiSMO+8e zZLH9ovqsNgeQX7bb1c/mBupJ4SQmZG6JAnRSq5t0FKIIbsylPH66D+qMY2ekYuXpUrZCb AqUwUsFIUcgmB6BsOApruINvcQ2Vw0U= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-548-WOpEV56FPm2xOHG6ElSdSA-1; Wed, 05 Feb 2025 04:27:53 -0500 X-MC-Unique: WOpEV56FPm2xOHG6ElSdSA-1 X-Mimecast-MFC-AGG-ID: WOpEV56FPm2xOHG6ElSdSA Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A0616195D6AC; Wed, 5 Feb 2025 09:27:48 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.112.190]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 94030300019E; Wed, 5 Feb 2025 09:27:44 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, ryncsn@gmail.com, chrisl@kernel.org, Baoquan He Subject: [PATCH 04/12] mm/swap: skip scanning cluster range if it's empty cluster Date: Wed, 5 Feb 2025 17:27:13 +0800 Message-ID: <20250205092721.9395-5-bhe@redhat.com> In-Reply-To: <20250205092721.9395-1-bhe@redhat.com> References: <20250205092721.9395-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Since ci->lock has been taken when isolating cluster from si->free_clusters or taking si->percpu_cluster->next[order], it's unnecessary to scan and check the cluster range availability if i'ts empty cluster, and this can accelerate the huge page swapping. Signed-off-by: Baoquan He Reviewed-by: Kairui Song --- mm/swapfile.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/swapfile.c b/mm/swapfile.c index 9c9a4ec6d4c6..61efde853eea 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -729,6 +729,9 @@ static bool cluster_scan_range(struct swap_info_struct = *si, unsigned long offset, end =3D start + nr_pages; unsigned char *map =3D si->swap_map; =20 + if (cluster_is_empty(ci)) + return true; + for (offset =3D start; offset < end; offset++) { switch (READ_ONCE(map[offset])) { case 0: --=20 2.41.0 From nobody Sun Dec 14 21:37:40 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E257922A7F6 for ; Wed, 5 Feb 2025 09:28:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747683; cv=none; b=cy3iNMWgPfAOEsVtHJBNAZnVxrmDlRQzPdmVaN46nFWAJcB5rWKEwbKiWQi+u7vTIA985tuK8aayFo8fH9k+FHfWW5WcZ3hgkeG5EeQlbdKg398uTpbAA7x8NptjqMP61SkdKERwv/6LPAlJGGnpTBJP2gob6VoqcF0QQUhGbzQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747683; c=relaxed/simple; bh=wNhf7XUUgQ3kmQA81fx0E5cWJPTz9i5xPoSFlHQOsaw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=Wj1xZWKgz+sYGH5zdifaH1z2DdFtDw95zFV8/mLvC2QwSfmtsQdcJXkKGJhlU1Sxpq06Ukw4Ku9wGBg8BX3/qNAv6jN4nZZQIO+ww3nQ40ORb6DwNs9XX3B82Q5wwsoSBAxC2Q7AnissfmyeQReMxCE5iKdeCVISGOKO1h3dBM0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=OfDysnf9; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OfDysnf9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738747680; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R7Vvp9EGlv2TMusLr7Im3+AMRbyPEdy+5VUuaPm2KpI=; b=OfDysnf9aKMgygDqUQKnwiFtMSYDjA029mp8M8BjlAEelx3qbSNYV/ya6aeZXoI2laKrLR ZL3P0DfbZxxGjRSM4AR/Nh6TkBjwuMopZtpzS+7Qn7qEVKIbRyfCvhJAb87cZ43aKmQnxS e4l5JlzFvDXp5/Jp5z3UBi1qyXLvOFQ= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-343-SbABTzTlOh2KRzsfQVnkxA-1; Wed, 05 Feb 2025 04:27:55 -0500 X-MC-Unique: SbABTzTlOh2KRzsfQVnkxA-1 X-Mimecast-MFC-AGG-ID: SbABTzTlOh2KRzsfQVnkxA Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 153DD1955D86; Wed, 5 Feb 2025 09:27:53 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.112.190]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4E542300018D; Wed, 5 Feb 2025 09:27:48 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, ryncsn@gmail.com, chrisl@kernel.org, Baoquan He Subject: [PATCH 05/12] mm/swap: rename swap_is_has_cache() to swap_only_has_cache() Date: Wed, 5 Feb 2025 17:27:14 +0800 Message-ID: <20250205092721.9395-6-bhe@redhat.com> In-Reply-To: <20250205092721.9395-1-bhe@redhat.com> References: <20250205092721.9395-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" There are two predicates in the name of swap_is_has_cache() which is confusing. Renaming it to remove the confusion and can better reflect its functionality. Signed-off-by: Baoquan He Reviewed-by: Kairui Song --- mm/swapfile.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 61efde853eea..bf284ba16198 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -161,7 +161,7 @@ static long swap_usage_in_pages(struct swap_info_struct= *si) /* Reclaim directly, bypass the slot cache and don't touch device lock */ #define TTRS_DIRECT 0x8 =20 -static bool swap_is_has_cache(struct swap_info_struct *si, +static bool swap_only_has_cache(struct swap_info_struct *si, unsigned long offset, int nr_pages) { unsigned char *map =3D si->swap_map + offset; @@ -243,7 +243,7 @@ static int __try_to_reclaim_swap(struct swap_info_struc= t *si, * reference or pending writeback, and can't be allocated to others. */ ci =3D lock_cluster(si, offset); - need_reclaim =3D swap_is_has_cache(si, offset, nr_pages); + need_reclaim =3D swap_only_has_cache(si, offset, nr_pages); unlock_cluster(ci); if (!need_reclaim) goto out_unlock; @@ -1572,7 +1572,7 @@ void put_swap_folio(struct folio *folio, swp_entry_t = entry) return; =20 ci =3D lock_cluster(si, offset); - if (swap_is_has_cache(si, offset, size)) + if (swap_only_has_cache(si, offset, size)) swap_entry_range_free(si, ci, entry, size); else { for (int i =3D 0; i < size; i++, entry.val++) { --=20 2.41.0 From nobody Sun Dec 14 21:37:40 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA64022A80E for ; Wed, 5 Feb 2025 09:28:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747685; cv=none; b=I5sqib2tx/xfTeTyWVytc9a/2PfA3AV+HJ8tHEd44L5pLPpqcgxOTINMcborRbzMNywwKR4W76rQuo2lwJM4szL402iXQ9zPDWW9eCf33rFZF6Z4wLJ88fjJYv4VtBVpygBB/paEoMtWy/AbyQjjiEuJFbj5pkGARFEFv3Oi8jU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747685; c=relaxed/simple; bh=pFCf3XiARpVif3NNdiBg5rjaSRsI/kNvNA2UffU7WNk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=Lv4wWPVE4SmdQo40W6AVw4467oXf5GmYjnI4zIznkQeUbl7jmz92XmW/PamIWOKEDqUFYAokntBxngV5VA10h449Ne35oZA4+uC6XVRclGPFMJJZYKYwuiLEZw0OAwGsY0ZtlpEGLzOrsDS2sv/rSncoI/92W6PrH1jN4ltgsFI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=U6FgY4a7; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="U6FgY4a7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738747682; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tfQRbrAPzJ//p+aZcAFopIE6B9AWo00nZkaqbYuuJ/4=; b=U6FgY4a7AwFocMCVXQYNlswwF9Z/TmsrqIYk7cpR+8Ee3qYphzsWyge3g3wBl3Tc9B4Heg yAZey3k6UAeP1IXHkRMwtDvQfvvDnw2IJ2HvAV2l/1qh/ODvh0VURUM+pc8qVAM7/AOY5m Ey9Hxr32KsmedfZBoo6hg6dgYZw6/cs= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-653-EwIqPDUzPAGcwC0RIUNX0A-1; Wed, 05 Feb 2025 04:27:58 -0500 X-MC-Unique: EwIqPDUzPAGcwC0RIUNX0A-1 X-Mimecast-MFC-AGG-ID: EwIqPDUzPAGcwC0RIUNX0A Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B08E019560BE; Wed, 5 Feb 2025 09:27:57 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.112.190]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F0C94300018D; Wed, 5 Feb 2025 09:27:53 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, ryncsn@gmail.com, chrisl@kernel.org, Baoquan He Subject: [PATCH 06/12] mm/swapfile.c: update the code comment above swap_count_continued() Date: Wed, 5 Feb 2025 17:27:15 +0800 Message-ID: <20250205092721.9395-7-bhe@redhat.com> In-Reply-To: <20250205092721.9395-1-bhe@redhat.com> References: <20250205092721.9395-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Now, swap_count_continued() has two callers, __swap_duplicate() and __swap_entry_free_locked(), the relevant code comment is stale. Update it to reflect the current situation. Signed-off-by: Baoquan He Reviewed-by: Kairui Song --- mm/swapfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index bf284ba16198..9ee2238042a5 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3789,8 +3789,8 @@ int add_swap_count_continuation(swp_entry_t entry, gf= p_t gfp_mask) * into, carry if so, or else fail until a new continuation page is alloca= ted; * when the original swap_map count is decremented from 0 with continuatio= n, * borrow from the continuation and report whether it still holds more. - * Called while __swap_duplicate() or swap_entry_free() holds swap or clus= ter - * lock. + * Called while __swap_duplicate() or caller of __swap_entry_free_locked() + * holds swap or cluster lock. */ static bool swap_count_continued(struct swap_info_struct *si, pgoff_t offset, unsigned char count) --=20 2.41.0 From nobody Sun Dec 14 21:37:40 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C34D322B8B1 for ; Wed, 5 Feb 2025 09:28:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747689; cv=none; b=c2MpXKh1Vv9dvUn1PVh/SoZZVQhDtQuBPPs3juYwGuSfFQPjn1Qgjeny/83MKsbfxASkC0bBEnhipEr49BN5++Ak1E3SX0RLrYXXBUghTX695tSSzb36mtA9RPMijpOp4HtyoyT7Xqvs0RRI0hqJMyBXUxOwTh9GI5HvQX9cXpE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747689; c=relaxed/simple; bh=t1Ijx+z7mRobmwC7nM30+fpI4l4f4a8oBa+BWgm53Gc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=W7e3ZLgpfcZOEY+OhPfR0n1qKUSsFfzO3pfFIsGFGdxFKhwFlpu6/PIGPcDxGJE9JRCrHUsxoT1Z0PcG1XmDb4QDg7w427MvPbPGwqMF7pcQKhMhKrQ4BAVfzkChEbrMBWMqt8Eq1RCBU9mn2eUNVBHw9i34iSV/INClAmh4fZY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Brfr4VAg; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Brfr4VAg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738747686; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LKc3fZumFCD/91JO2q/vgJ8rLFG0/4maedUYtaTx5XI=; b=Brfr4VAgaalv/1jPsVYluE059fWnHJsZzo7jelDs24h9GgIBzS5INrYbaXyON6eWM7HZze 2vEmwjWg94QHd8qClAiphf34Omx6RL7a4jUc5DXMeTjdW18kJRj/AhM+oMu8LlDU9QpukO rPUxcRwpoVw1A54W+xHkfRL0h8Jp+eE= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-111-EEDgiAEAOjaQS-4j2v0Clg-1; Wed, 05 Feb 2025 04:28:03 -0500 X-MC-Unique: EEDgiAEAOjaQS-4j2v0Clg-1 X-Mimecast-MFC-AGG-ID: EEDgiAEAOjaQS-4j2v0Clg Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5172E1955D83; Wed, 5 Feb 2025 09:28:02 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.112.190]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9B0A2300018D; Wed, 5 Feb 2025 09:27:58 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, ryncsn@gmail.com, chrisl@kernel.org, Baoquan He Subject: [PATCH 07/12] mm/swapfile.c: optimize code in setup_clusters() Date: Wed, 5 Feb 2025 17:27:16 +0800 Message-ID: <20250205092721.9395-8-bhe@redhat.com> In-Reply-To: <20250205092721.9395-1-bhe@redhat.com> References: <20250205092721.9395-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" In the last 'for' loop inside setup_clusters(), using two local variable 'k' and 'j' are obvisouly redundant. Using 'j' is enough and simpler. And also move macro SWAP_CLUSTER_COLS close to its only user setup_clusters(). Signed-off-by: Baoquan He Reviewed-by: Kairui Song --- mm/swapfile.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 9ee2238042a5..78b7329ad2c7 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3123,13 +3123,6 @@ static unsigned long read_swap_header(struct swap_in= fo_struct *si, return maxpages; } =20 -#define SWAP_CLUSTER_INFO_COLS \ - DIV_ROUND_UP(L1_CACHE_BYTES, sizeof(struct swap_cluster_info)) -#define SWAP_CLUSTER_SPACE_COLS \ - DIV_ROUND_UP(SWAP_ADDRESS_SPACE_PAGES, SWAPFILE_CLUSTER) -#define SWAP_CLUSTER_COLS \ - max_t(unsigned int, SWAP_CLUSTER_INFO_COLS, SWAP_CLUSTER_SPACE_COLS) - static int setup_swap_map_and_extents(struct swap_info_struct *si, union swap_header *swap_header, unsigned char *swap_map, @@ -3169,13 +3162,20 @@ static int setup_swap_map_and_extents(struct swap_i= nfo_struct *si, return nr_extents; } =20 +#define SWAP_CLUSTER_INFO_COLS \ + DIV_ROUND_UP(L1_CACHE_BYTES, sizeof(struct swap_cluster_info)) +#define SWAP_CLUSTER_SPACE_COLS \ + DIV_ROUND_UP(SWAP_ADDRESS_SPACE_PAGES, SWAPFILE_CLUSTER) +#define SWAP_CLUSTER_COLS \ + max_t(unsigned int, SWAP_CLUSTER_INFO_COLS, SWAP_CLUSTER_SPACE_COLS) + static struct swap_cluster_info *setup_clusters(struct swap_info_struct *s= i, union swap_header *swap_header, unsigned long maxpages) { unsigned long nr_clusters =3D DIV_ROUND_UP(maxpages, SWAPFILE_CLUSTER); struct swap_cluster_info *cluster_info; - unsigned long i, j, k, idx; + unsigned long i, j, idx; int cpu, err =3D -ENOMEM; =20 cluster_info =3D kvcalloc(nr_clusters, sizeof(*cluster_info), GFP_KERNEL); @@ -3236,8 +3236,7 @@ static struct swap_cluster_info *setup_clusters(struc= t swap_info_struct *si, * Reduce false cache line sharing between cluster_info and * sharing same address space. */ - for (k =3D 0; k < SWAP_CLUSTER_COLS; k++) { - j =3D k % SWAP_CLUSTER_COLS; + for (j =3D 0; j < SWAP_CLUSTER_COLS; j++) { for (i =3D 0; i < DIV_ROUND_UP(nr_clusters, SWAP_CLUSTER_COLS); i++) { struct swap_cluster_info *ci; idx =3D i * SWAP_CLUSTER_COLS + j; --=20 2.41.0 From nobody Sun Dec 14 21:37:40 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 629D822B8BF for ; Wed, 5 Feb 2025 09:28:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747695; cv=none; b=kNoKhABVFI6fZQlA7dJ8HHQE08K+AFkp0odd1XaVEOJ3qfWy1tRDi84l7u0o4jl/8q9yeJFo+9UCLaY2pgeV432d49vP3yDla6V4L1ROpL+NPelbgkWUOGwrduKUCokbGU0IG0j7I6KvLi5s9/cfqMS/kgzDZVYVR07g3wdsGow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747695; c=relaxed/simple; bh=AN2UcnAy08VF3/WUmP5xZ8yMQfcDHf4MeyLqXvvStyY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=L8S5ZSBkqg9RH0pG5Rlm/Ma2XznljrIDrZm3B6VDUhuTEGrK+EjChiIjG+RqhtCt4V6Zw/Skvd3ffAio3SnEUtss9bxKBA3b7ojtMKb9F8ZvCk7mXt9Lb/O6AfBjKky3GEqTvdcMwZdnsyR0orS4Zhc/S4NeNYl7V1Td/qTUSC4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=cSgaJ0sB; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cSgaJ0sB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738747692; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LKdSXZcqnstZAkYV6ff74HG8BN8BooEUO78YRxCe8Tc=; b=cSgaJ0sB7sdPe7nF9c6xMBpKptimws7D61S1UTElQft/oYZB8toMAQIQlZ0ugArOOHJz01 islKEdNvW39Dq2+AO+QlqrBdpJHMtMayBAAqsvD4gpCkbngsT1WlWKEq8T6U8G7NyV4fyp S6XgOpGcX0t6jvTUChNX5Xk2qxQTc3U= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-179-cXFiB-0CPGi7ksJUR4_nxw-1; Wed, 05 Feb 2025 04:28:08 -0500 X-MC-Unique: cXFiB-0CPGi7ksJUR4_nxw-1 X-Mimecast-MFC-AGG-ID: cXFiB-0CPGi7ksJUR4_nxw Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1900819560B2; Wed, 5 Feb 2025 09:28:07 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.112.190]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 394AE300018D; Wed, 5 Feb 2025 09:28:02 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, ryncsn@gmail.com, chrisl@kernel.org, Baoquan He Subject: [PATCH 08/12] mm/swap_state.c: remove the meaningless code comment Date: Wed, 5 Feb 2025 17:27:17 +0800 Message-ID: <20250205092721.9395-9-bhe@redhat.com> In-Reply-To: <20250205092721.9395-1-bhe@redhat.com> References: <20250205092721.9395-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Since commit 8d93b41c09d1 ("mm: Convert add_to_swap_cache to XArray"), there's no returned _EEXIT, so the code comment doesn't make sense any more. Signed-off-by: Baoquan He Reviewed-by: Kairui Song --- mm/swap_state.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index d7cbf5bb2450..b393cefb3be0 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -203,10 +203,6 @@ bool add_to_swap(struct folio *folio) err =3D add_to_swap_cache(folio, entry, __GFP_HIGH|__GFP_NOMEMALLOC|__GFP_NOWARN, NULL); if (err) - /* - * add_to_swap_cache() doesn't return -EEXIST, so we can safely - * clear SWAP_HAS_CACHE flag. - */ goto fail; /* * Normally the folio will be dirtied in unmap because its --=20 2.41.0 From nobody Sun Dec 14 21:37:40 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 111ED22B8B1 for ; Wed, 5 Feb 2025 09:28:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747696; cv=none; b=FV/dc9/VA1FEjPJni2BjNL06CIjiGYt5+ANtSqPD6AGV8/QfwSiwjwUTIUCfs8VYJAms6TEmKq7co6l+8pYxyC90BIWASA2ISQ6UVhepBUoXvqIvYTQF1V8eb1dv4nhN56LDwrwawucDQ04yJt7TiLViS9DhCU7PzN/AUdRLgOQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747696; c=relaxed/simple; bh=2tr8cmcSyVR5q821duRqH1xcWSdZ38okRoTKi/rzdlQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=ElzyjvSHuH66Ax9EFJ8ZCjoKx2UXbyUfvFwsdmvFNeSY3kRe76r1IBMeBW7ST7HKVaRxQjPYfEHUNu4/3gMXHVhEeXBf7O2RCIbZueiQWTA30z3g7QXS4Bx4o6HMuvpdtnIMxwjd8yF4StOhDTNHCFt0q8SEelAAPYBxG0rmaMU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Stcs3UkU; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Stcs3UkU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738747694; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/m9fIb5RUGdXyEtpozVsgbTSVCO5CREUbIcsYzkG8Js=; b=Stcs3UkU65NhpfXVPryNll/whe7m9R91K4cktzI+kAxmQXeHQF7tSfTQ808EJGoz9z7BRP tofFEQyq8JzfUqJNFJqg9UXAPRqsQAzVlpAbJXEeM4476C1i1ZcpTaAi8u57P4Z/Wiq05d tp0kKxQQsc6Fa3FbCGC/jNss5mH0gtI= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-461-ipAmL9EeOJ-YRtbTyRkJew-1; Wed, 05 Feb 2025 04:28:12 -0500 X-MC-Unique: ipAmL9EeOJ-YRtbTyRkJew-1 X-Mimecast-MFC-AGG-ID: ipAmL9EeOJ-YRtbTyRkJew Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B3CBF1800871; Wed, 5 Feb 2025 09:28:11 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.112.190]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 000243000197; Wed, 5 Feb 2025 09:28:07 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, ryncsn@gmail.com, chrisl@kernel.org, Baoquan He Subject: [PATCH 09/12] mm/swapfile.c: remove the unneeded checking Date: Wed, 5 Feb 2025 17:27:18 +0800 Message-ID: <20250205092721.9395-10-bhe@redhat.com> In-Reply-To: <20250205092721.9395-1-bhe@redhat.com> References: <20250205092721.9395-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" In free_swap_and_cache_nr(), invocation of get_swap_device() has done the checking if it's a swap entry. So remove the redundant checking here. Signed-off-by: Baoquan He Reviewed-by: Kairui Song --- mm/swapfile.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 78b7329ad2c7..2a25ff5f31c8 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1784,9 +1784,6 @@ void free_swap_and_cache_nr(swp_entry_t entry, int nr) bool any_only_cache =3D false; unsigned long offset; =20 - if (non_swap_entry(entry)) - return; - si =3D get_swap_device(entry); if (!si) return; --=20 2.41.0 From nobody Sun Dec 14 21:37:40 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C28CC22C35B for ; Wed, 5 Feb 2025 09:28:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747701; cv=none; b=oTJcbMU+p0dL188fPCWxysV/+39KTUnLxmF2nII83DxPGvW5hR/ZHj+B5A0ER1ym4MyVovwgdMhWYmSt1wUgTk52dXni0OmR2eR3qCpgSgbd/r+3IWbX9fh2gJl/42o0nMiMtcOqYanNH6pLgVW0O7aGuL8A3FKomsvbV/2ETSw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747701; c=relaxed/simple; bh=VX26HNiWwpD9kN42atTc9oahPw/TvYNOdYXjy3VIo38=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=IeZo/G/kEqDF2CjQ4a9pQATIHQ0VvtZT8LlCZMPoUlwYRqix8v4tYnMFJ4bNpTqpwJvL5n5qDwmYOGQzSlZpcpmerzta+ua/R5irK6ia3+zBHmGfYhmC4GpKhjLpYFHaWDnmR9jlZ4kAuhh2VxsUjyUBQARB1MisVVigBoRPqpA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=KwJAzmz/; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KwJAzmz/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738747698; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8vVxPS21csuuvYhubTDPbniUZC89uu0FzC8UHkUR7f4=; b=KwJAzmz/QERzAaTDvjLl3lJRgG1JxnYa7R85NMTUAgx2eiUrMKlWJW9TadZJNRXfqtUzXi ns6pSLoxQPcIE2wGLNH8N9Uhtt5hexiMUm5bVhMBt2Pi1bQhx5A5TmLMIdw8mZtDDSgPED CKq8chg3e4S2hzpXtIddd4P760caxpQ= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-626-YcE78HehONax1pGIvqF0gQ-1; Wed, 05 Feb 2025 04:28:17 -0500 X-MC-Unique: YcE78HehONax1pGIvqF0gQ-1 X-Mimecast-MFC-AGG-ID: YcE78HehONax1pGIvqF0gQ Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4F6261800877; Wed, 5 Feb 2025 09:28:16 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.112.190]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9B8CA3000197; Wed, 5 Feb 2025 09:28:12 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, ryncsn@gmail.com, chrisl@kernel.org, Baoquan He Subject: [PATCH 10/12] mm/swap: rename swap_swapcount() to swap_entry_swapped() Date: Wed, 5 Feb 2025 17:27:19 +0800 Message-ID: <20250205092721.9395-11-bhe@redhat.com> In-Reply-To: <20250205092721.9395-1-bhe@redhat.com> References: <20250205092721.9395-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" The new function name can reflect the real behaviour of the function more clearly and more accurately. And the renaming avoids the confusion between swap_swapcount() and swp_swapcount(). Signed-off-by: Baoquan He Reviewed-by: Kairui Song --- include/linux/swap.h | 6 +++--- mm/swap_state.c | 2 +- mm/swapfile.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 20bfedc8c4f2..395d41cf9676 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -500,7 +500,7 @@ int find_first_swap(dev_t *device); extern unsigned int count_swap_pages(int, int); extern sector_t swapdev_block(int, pgoff_t); extern int __swap_count(swp_entry_t entry); -extern int swap_swapcount(struct swap_info_struct *si, swp_entry_t entry); +extern bool swap_entry_swapped(struct swap_info_struct *si, swp_entry_t en= try); extern int swp_swapcount(swp_entry_t entry); struct swap_info_struct *swp_swap_info(swp_entry_t entry); struct backing_dev_info; @@ -583,9 +583,9 @@ static inline int __swap_count(swp_entry_t entry) return 0; } =20 -static inline int swap_swapcount(struct swap_info_struct *si, swp_entry_t = entry) +static inline bool swap_entry_swapped(struct swap_info_struct *si, swp_ent= ry_t entry) { - return 0; + return false; } =20 static inline int swp_swapcount(swp_entry_t entry) diff --git a/mm/swap_state.c b/mm/swap_state.c index b393cefb3be0..3dba6eb164db 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -457,7 +457,7 @@ struct folio *__read_swap_cache_async(swp_entry_t entry= , gfp_t gfp_mask, * as SWAP_HAS_CACHE. That's done in later part of code or * else swap_off will be aborted if we return NULL. */ - if (!swap_swapcount(si, entry) && swap_slot_cache_enabled) + if (!swap_entry_swapped(si, entry) && swap_slot_cache_enabled) goto put_and_return; =20 /* diff --git a/mm/swapfile.c b/mm/swapfile.c index 2a25ff5f31c8..93fd12c12bba 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1615,7 +1615,7 @@ int __swap_count(swp_entry_t entry) * This does not give an exact answer when swap count is continued, * but does include the high COUNT_CONTINUED flag to allow for that. */ -int swap_swapcount(struct swap_info_struct *si, swp_entry_t entry) +bool swap_entry_swapped(struct swap_info_struct *si, swp_entry_t entry) { pgoff_t offset =3D swp_offset(entry); struct swap_cluster_info *ci; @@ -1624,7 +1624,7 @@ int swap_swapcount(struct swap_info_struct *si, swp_e= ntry_t entry) ci =3D lock_cluster(si, offset); count =3D swap_count(si->swap_map[offset]); unlock_cluster(ci); - return count; + return !!count; } =20 /* @@ -1710,7 +1710,7 @@ static bool folio_swapped(struct folio *folio) return false; =20 if (!IS_ENABLED(CONFIG_THP_SWAP) || likely(!folio_test_large(folio))) - return swap_swapcount(si, entry) !=3D 0; + return swap_entry_swapped(si, entry); =20 return swap_page_trans_huge_swapped(si, entry, folio_order(folio)); } --=20 2.41.0 From nobody Sun Dec 14 21:37:40 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 493D422AE4E for ; Wed, 5 Feb 2025 09:28:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747708; cv=none; b=iYp0kVbhIqhz9cNXiAbYRinUNWNXo1gek4YV9zLWfDR6pgQQxeKzZ9oVydfECVMZXsl2UnaisgiW/eB/X3mSnaLwgPa54DNOJG5FPv7dRXeHacp/K4CwUkbzPWAhs7kFAcB+zMMGGvyukApAoVzg4eYGsrSulrjoBjk0wr34OX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747708; c=relaxed/simple; bh=COzovgz55oiFlywVeq1OO7mG8nLNBb5YtLKNQVd6/2M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=nC2SNORRoYeV1dQG2FL2F/1Pole+CGXS/0ilv+lhVQSQigq4L/ug2zTNMNvPxlsnwb+UWOhpDqPiLmCAU8bjulwJMLRqC6q4nhBDLgr/BYnh6gNJhr3AqNtWuzR6bW2u2NwPRNQryTbskhQgP3U0XPb7OvEsgq3lBSc/e04fgbw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=DczsXbZD; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DczsXbZD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738747706; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v1QWMGz/t53y8nWqSpKCm2XX0aS+6vebfqdvYfQONWo=; b=DczsXbZDbwDCg7eQ6Y3idG5xc+LKZ/12Knh7E1JgkOiXiw8Ckz9TgnaZXOqz9bzWvjSuHq G8WLeBDtJNGqFBErgO52ux4Bxbi7AaEQ7IrQBmNlYBTpviUs1aPPkCbbA20aKlI2eqQJfC j9NcWnQ35wWKgygBWuRxQB4hIo69Ipg= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-368-2cv8CABvMBWC8Bt0PVaXnw-1; Wed, 05 Feb 2025 04:28:22 -0500 X-MC-Unique: 2cv8CABvMBWC8Bt0PVaXnw-1 X-Mimecast-MFC-AGG-ID: 2cv8CABvMBWC8Bt0PVaXnw Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EBDC8195608C; Wed, 5 Feb 2025 09:28:20 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.112.190]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 36D32300018D; Wed, 5 Feb 2025 09:28:16 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, ryncsn@gmail.com, chrisl@kernel.org, Baoquan He Subject: [PATCH 11/12] mm/swapfile.c: remove the incorrect code comment Date: Wed, 5 Feb 2025 17:27:20 +0800 Message-ID: <20250205092721.9395-12-bhe@redhat.com> In-Reply-To: <20250205092721.9395-1-bhe@redhat.com> References: <20250205092721.9395-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Since commit eb085574a752 ("mm, swap: fix race between swapoff and some swap operations"), the non_swap_entry() checking has been taken off from function __swap_duplicate(). Hence, in the kernel-doc comment, the line 'swp_entry is migration entry -> EINVAL' is obsolete. Remove that line to avoid misleading people. Signed-off-by: Baoquan He Reviewed-by: Kairui Song --- mm/swapfile.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 93fd12c12bba..12bb7556c7f1 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3525,7 +3525,6 @@ void si_swapinfo(struct sysinfo *val) * Returns error code in following case. * - success -> 0 * - swp_entry is invalid -> EINVAL - * - swp_entry is migration entry -> EINVAL * - swap-cache reference is requested but there is already one. -> EEXIST * - swap-cache reference is requested but the entry is not used. -> ENOENT * - swap-mapped reference requested but needs continued swap count. -> EN= OMEM --=20 2.41.0 From nobody Sun Dec 14 21:37:40 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05D1822CBD6 for ; Wed, 5 Feb 2025 09:28:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747712; cv=none; b=UyHNqE63QGenu0IS+X8jVZcI0f5LroapDs+YJjto+alpNiniqSge0Ilo26aqWNJSgF8CTBHt7t/akZlgqKY5vAwONKRfkI22cKm/cb4SLzKE0kBdFrod9kcFLspFvwq6drHfP8/1YL1DvIrkxJQbCcXfLO/xUiNxBxRNtoaVQ5c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738747712; c=relaxed/simple; bh=hpqBJBwb47MHOoGFyd/KF46dfDxV+GtQ8s3DgjwCeNM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=JWGVaYyVY6g2QdJUY59MNkuiGwh8bh4RTT/hIUCwMiVfI1NooXaWwKakOD2JlhXMWY2fjPgdKHy8SgzW62Jwpqhui9VLwsMYu9H4mGS8YdyMHnpsm+gQ7AwaVDGjp555nI5elOmWwi5R+KScA6bdxHjganO53DFRc7C7jkmxJjs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ZpnRlDte; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZpnRlDte" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738747710; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eJxZpNwhXiHzAqXXfk54vRZnvA5qQBJ34Wvs1FodgiE=; b=ZpnRlDtevZOYaFZXU8Gaow153cA6gOIgtqM/HZCy4m1jsS7JjTWrRxLZ61pzmSiYZlBJbl DKsCGQ2//bFINl1rg+Qn+c5xwPTsB7fA+aGHp4m06Mijaw5hm5mS94saVWnScrqxOWDGmE OyoDfOCS+k2D3UeTTpxJ1Yw4kOj9R4s= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-34-gOIRUj3mNiWKdkWAHtpU_w-1; Wed, 05 Feb 2025 04:28:26 -0500 X-MC-Unique: gOIRUj3mNiWKdkWAHtpU_w-1 X-Mimecast-MFC-AGG-ID: gOIRUj3mNiWKdkWAHtpU_w Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8B858195608B; Wed, 5 Feb 2025 09:28:25 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.112.190]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D381C300018D; Wed, 5 Feb 2025 09:28:21 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, ryncsn@gmail.com, chrisl@kernel.org, Baoquan He Subject: [PATCH 12/12] mm/swapfile.c: open code cluster_alloc_swap() Date: Wed, 5 Feb 2025 17:27:21 +0800 Message-ID: <20250205092721.9395-13-bhe@redhat.com> In-Reply-To: <20250205092721.9395-1-bhe@redhat.com> References: <20250205092721.9395-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" It's only called in scan_swap_map_slots(). And also remove the stale code comment in scan_swap_map_slots() because it's not fit for the current cluster allocation mechanism. Signed-off-by: Baoquan He Reviewed-by: Kairui Song --- mm/swapfile.c | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 12bb7556c7f1..7448a387621d 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1158,39 +1158,13 @@ static void swap_range_free(struct swap_info_struct= *si, unsigned long offset, swap_usage_sub(si, nr_entries); } =20 -static int cluster_alloc_swap(struct swap_info_struct *si, - unsigned char usage, int nr, - swp_entry_t slots[], int order) -{ - int n_ret =3D 0; - - while (n_ret < nr) { - unsigned long offset =3D cluster_alloc_swap_entry(si, order, usage); - - if (!offset) - break; - slots[n_ret++] =3D swp_entry(si->type, offset); - } - - return n_ret; -} - static int scan_swap_map_slots(struct swap_info_struct *si, unsigned char usage, int nr, swp_entry_t slots[], int order) { unsigned int nr_pages =3D 1 << order; + int n_ret =3D 0; =20 - /* - * We try to cluster swap pages by allocating them sequentially - * in swap. Once we've allocated SWAPFILE_CLUSTER pages this - * way, however, we resort to first-free allocation, starting - * a new cluster. This prevents us from scattering swap pages - * all over the entire swap partition, so that we reduce - * overall disk seek times between swap pages. -- sct - * But we do now try to find an empty cluster. -Andrea - * And we let swap pages go all over an SSD partition. Hugh - */ if (order > 0) { /* * Should not even be attempting large allocations when huge @@ -1210,7 +1184,15 @@ static int scan_swap_map_slots(struct swap_info_stru= ct *si, return 0; } =20 - return cluster_alloc_swap(si, usage, nr, slots, order); + while (n_ret < nr) { + unsigned long offset =3D cluster_alloc_swap_entry(si, order, usage); + + if (!offset) + break; + slots[n_ret++] =3D swp_entry(si->type, offset); + } + + return n_ret; } =20 static bool get_swap_device_info(struct swap_info_struct *si) --=20 2.41.0