From mboxrd@z Thu Jan 1 00:00:00 1970 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 B149A182B8 for ; Thu, 18 Dec 2025 03:37: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=1766029064; cv=none; b=iQGlXEck9DZ6y8+2ATYMMhvw+zf5P/WbSKpuGdDKtSBFPzt+f8XhU9rxe6xocx77eGUsovpb+hOoFWnueCRP4sLLej2LNirJu2F2nj81znjjxzqbI+RC7DfMT3thElagBR5YbWXJdPRBtLxwt926ppDqTJrVsHahWxSBASh5GDU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766029064; c=relaxed/simple; bh=gnf0SgDqrZSiYkGjwi8A7TqZvyrlwUXo7vIwdU5vcBY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PQZh0P+YPPKtGTfCVYzzmF3LBEMVdNk2iexE3+LLnUpsFLr8fFsjll9k1G3AkQM751QCDyGuUpjRmZtwHoVp8ahm42rphZ6hGzVbJ5c4AXf4Ua22P6EJbImEKry9UfNZpj2dJZyOuE+g2Q2P8US8AailSJ/lpoAVwo8k3A9Zges= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=EQ2wRe+t; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="EQ2wRe+t" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1766029061; 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: in-reply-to:in-reply-to:references:references; bh=3qTD9MZk8GDLip2qcSZRvcJaRYYv76lWRQR+PrOB//U=; b=EQ2wRe+tW2GXld91RFdtGF2WxS57wlpSaQo41L2tVWhUaYaGVlJvYR05jEliz7/uzQSyRv Mgk2nErlRZXJcQXvxkKfeGMY75uFFlHXgGGDimCHO2Lt7MYDQfNctg/YkqRci4go9p17lB beze4OIyNZKkOAkABYGfwIskpnk5REs= 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-422-4gkqZ1yrM2if8ZS1n76vxQ-1; Wed, 17 Dec 2025 22:37:36 -0500 X-MC-Unique: 4gkqZ1yrM2if8ZS1n76vxQ-1 X-Mimecast-MFC-AGG-ID: 4gkqZ1yrM2if8ZS1n76vxQ_1766029053 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 50FE91955F34; Thu, 18 Dec 2025 03:37:33 +0000 (UTC) Received: from localhost (unknown [10.72.112.95]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EBD6E30001A2; Thu, 18 Dec 2025 03:37:30 +0000 (UTC) Date: Thu, 18 Dec 2025 11:37:25 +0800 From: Baoquan He To: Kairui Song Cc: linux-mm@kvack.org, Andrew Morton , Barry Song , Chris Li , Nhat Pham , Yosry Ahmed , David Hildenbrand , Johannes Weiner , Youngjun Park , Hugh Dickins , Baolin Wang , Ying Huang , Kemeng Shi , Lorenzo Stoakes , "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org, Kairui Song Subject: Re: [PATCH v4 13/19] mm, swap: remove workaround for unsynchronized swap map cache state Message-ID: References: <20251205-swap-table-p2-v4-0-cb7e28a26a40@tencent.com> <20251205-swap-table-p2-v4-13-cb7e28a26a40@tencent.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251205-swap-table-p2-v4-13-cb7e28a26a40@tencent.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 On 12/05/25 at 03:29am, Kairui Song wrote: > From: Kairui Song > > Remove the "skip if exists" check from commit a65b0e7607ccb ("zswap: > make shrinking memcg-aware"). It was needed because there is a tiny time > window between setting the SWAP_HAS_CACHE bit and actually adding the > folio to the swap cache. If a user is trying to add the folio into the > swap cache but another user was interrupted after setting SWAP_HAS_CACHE > but hasn't added the folio to the swap cache yet, it might lead to a > deadlock. > > We have moved the bit setting to the same critical section as adding the > folio, so this is no longer needed. Remove it and clean it up. > > Signed-off-by: Kairui Song > --- > mm/swap.h | 2 +- > mm/swap_state.c | 27 ++++++++++----------------- > mm/zswap.c | 2 +- > 3 files changed, 12 insertions(+), 19 deletions(-) Reviewed-by: Baoquan He > > diff --git a/mm/swap.h b/mm/swap.h > index b5075a1aee04..6777b2ab9d92 100644 > --- a/mm/swap.h > +++ b/mm/swap.h > @@ -260,7 +260,7 @@ int swap_cache_add_folio(struct folio *folio, swp_entry_t entry, > void swap_cache_del_folio(struct folio *folio); > struct folio *swap_cache_alloc_folio(swp_entry_t entry, gfp_t gfp_flags, > struct mempolicy *mpol, pgoff_t ilx, > - bool *alloced, bool skip_if_exists); > + bool *alloced); > /* Below helpers require the caller to lock and pass in the swap cluster. */ > void __swap_cache_del_folio(struct swap_cluster_info *ci, > struct folio *folio, swp_entry_t entry, void *shadow); > diff --git a/mm/swap_state.c b/mm/swap_state.c > index df7df8b75e52..1a69ba3be87f 100644 > --- a/mm/swap_state.c > +++ b/mm/swap_state.c > @@ -445,8 +445,6 @@ void swap_update_readahead(struct folio *folio, struct vm_area_struct *vma, > * @folio: folio to be added. > * @gfp: memory allocation flags for charge, can be 0 if @charged if true. > * @charged: if the folio is already charged. > - * @skip_if_exists: if the slot is in a cached state, return NULL. > - * This is an old workaround that will be removed shortly. > * > * Update the swap_map and add folio as swap cache, typically before swapin. > * All swap slots covered by the folio must have a non-zero swap count. > @@ -457,8 +455,7 @@ void swap_update_readahead(struct folio *folio, struct vm_area_struct *vma, > */ > static struct folio *__swap_cache_prepare_and_add(swp_entry_t entry, > struct folio *folio, > - gfp_t gfp, bool charged, > - bool skip_if_exists) > + gfp_t gfp, bool charged) > { > struct folio *swapcache = NULL; > void *shadow; > @@ -478,7 +475,7 @@ static struct folio *__swap_cache_prepare_and_add(swp_entry_t entry, > * might return a folio that is irrelevant to the faulting > * entry because @entry is aligned down. Just return NULL. > */ > - if (ret != -EEXIST || skip_if_exists || folio_test_large(folio)) > + if (ret != -EEXIST || folio_test_large(folio)) > goto failed; > > swapcache = swap_cache_get_folio(entry); > @@ -511,8 +508,6 @@ static struct folio *__swap_cache_prepare_and_add(swp_entry_t entry, > * @mpol: NUMA memory allocation policy to be applied > * @ilx: NUMA interleave index, for use only when MPOL_INTERLEAVE > * @new_page_allocated: sets true if allocation happened, false otherwise > - * @skip_if_exists: if the slot is a partially cached state, return NULL. > - * This is a workaround that would be removed shortly. > * > * Allocate a folio in the swap cache for one swap slot, typically before > * doing IO (e.g. swap in or zswap writeback). The swap slot indicated by > @@ -525,8 +520,7 @@ static struct folio *__swap_cache_prepare_and_add(swp_entry_t entry, > */ > struct folio *swap_cache_alloc_folio(swp_entry_t entry, gfp_t gfp_mask, > struct mempolicy *mpol, pgoff_t ilx, > - bool *new_page_allocated, > - bool skip_if_exists) > + bool *new_page_allocated) > { > struct swap_info_struct *si = __swap_entry_to_info(entry); > struct folio *folio; > @@ -547,8 +541,7 @@ struct folio *swap_cache_alloc_folio(swp_entry_t entry, gfp_t gfp_mask, > if (!folio) > return NULL; > /* Try add the new folio, returns existing folio or NULL on failure. */ > - result = __swap_cache_prepare_and_add(entry, folio, gfp_mask, > - false, skip_if_exists); > + result = __swap_cache_prepare_and_add(entry, folio, gfp_mask, false); > if (result == folio) > *new_page_allocated = true; > else > @@ -577,7 +570,7 @@ struct folio *swapin_folio(swp_entry_t entry, struct folio *folio) > unsigned long nr_pages = folio_nr_pages(folio); > > entry = swp_entry(swp_type(entry), round_down(offset, nr_pages)); > - swapcache = __swap_cache_prepare_and_add(entry, folio, 0, true, false); > + swapcache = __swap_cache_prepare_and_add(entry, folio, 0, true); > if (swapcache == folio) > swap_read_folio(folio, NULL); > return swapcache; > @@ -605,7 +598,7 @@ struct folio *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, > > mpol = get_vma_policy(vma, addr, 0, &ilx); > folio = swap_cache_alloc_folio(entry, gfp_mask, mpol, ilx, > - &page_allocated, false); > + &page_allocated); > mpol_cond_put(mpol); > > if (page_allocated) > @@ -724,7 +717,7 @@ struct folio *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask, > /* Ok, do the async read-ahead now */ > folio = swap_cache_alloc_folio( > swp_entry(swp_type(entry), offset), gfp_mask, mpol, ilx, > - &page_allocated, false); > + &page_allocated); > if (!folio) > continue; > if (page_allocated) { > @@ -742,7 +735,7 @@ struct folio *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask, > skip: > /* The page was likely read above, so no need for plugging here */ > folio = swap_cache_alloc_folio(entry, gfp_mask, mpol, ilx, > - &page_allocated, false); > + &page_allocated); > if (unlikely(page_allocated)) > swap_read_folio(folio, NULL); > return folio; > @@ -847,7 +840,7 @@ static struct folio *swap_vma_readahead(swp_entry_t targ_entry, gfp_t gfp_mask, > continue; > } > folio = swap_cache_alloc_folio(entry, gfp_mask, mpol, ilx, > - &page_allocated, false); > + &page_allocated); > if (si) > put_swap_device(si); > if (!folio) > @@ -869,7 +862,7 @@ static struct folio *swap_vma_readahead(swp_entry_t targ_entry, gfp_t gfp_mask, > skip: > /* The folio was likely read above, so no need for plugging here */ > folio = swap_cache_alloc_folio(targ_entry, gfp_mask, mpol, targ_ilx, > - &page_allocated, false); > + &page_allocated); > if (unlikely(page_allocated)) > swap_read_folio(folio, NULL); > return folio; > diff --git a/mm/zswap.c b/mm/zswap.c > index a7a2443912f4..d8a33db9d3cc 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -1015,7 +1015,7 @@ static int zswap_writeback_entry(struct zswap_entry *entry, > > mpol = get_task_policy(current); > folio = swap_cache_alloc_folio(swpentry, GFP_KERNEL, mpol, > - NO_INTERLEAVE_INDEX, &folio_was_allocated, true); > + NO_INTERLEAVE_INDEX, &folio_was_allocated); > put_swap_device(si); > if (!folio) > return -ENOMEM; > > -- > 2.52.0 >