Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp841702pxp; Wed, 9 Mar 2022 13:57:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJwDwdV3ZGRnIYpHcNSrzf7g61C1FrI1uvqLDQOecu8NsCvsbRIwcRJlu4TXnAvU17MfCUyy X-Received: by 2002:a17:90b:314:b0:1be:dc22:62f2 with SMTP id ay20-20020a17090b031400b001bedc2262f2mr12571142pjb.102.1646863029410; Wed, 09 Mar 2022 13:57:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646863029; cv=none; d=google.com; s=arc-20160816; b=f5riRoiZY0aLJ7VwADXb+iD8MTNQ0wE3Q34RW4jwuoeAghjkYxnxz/AY2ag6GW6iJE 6LP6fvA7Mtvj3EY1fOFiCkJlUP/jSvdeFlBmoHRt7iExwcYFTqauzp2SqJQ15m0XsxsU cD3Hs4l0VU2w1pAwy23iV/dHFJ3Vmmed5OPHnRRDxi49Md+9bXXnR7C6drqv5kfQaUBM kp4BMaxhqrnuCfBCJB2xh6CCvAKLLncria0BBm+/WMnuyaJhpQF6rkvK0jjUqilqBHW+ 7b19NFWM+3U2kzHI/8BISKcREKH5MfvbPVyXAw+sjzQdUNGwwYN8E+N5J71WwuDoGzoN x82w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=LcuKWqfsB4FekqxQFYP0QrWf6X2XXdV+m09YgaHeXxY=; b=W/LVhaeG3O7AQbCYqsLpJFv0J5uu3OrwleprI0zVi5P/WmCqvMUhTQGT0shF+HyOTx c9jB1OXE8v6072StzXejFOESLvwYHaz+FhD/TI+QRsI6wirEJZ8oBbMpcTTmID6/ysEd OCukgk/rO3zGBPSXRLdJ6SgsLOikaCXkNdu5HCmRGfg9gSdGKaJmWY8UZr6+Hs/RarRG 2EaNRjN3ZfEKuw+WV7ikVqEin7x2kLZKupSG3keNRWx7oAu6UwrGIwMKkFmI+gkcP2iJ FRMZP3wQ0ejNX21GOdNsLhHYwAKWpXEfCS73HOWUHwcPoTMmatXiaogxUY0RGUxKIubw tHJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=QRaMnKng; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c21-20020a056a00249500b004f77417312csi16177pfv.113.2022.03.09.13.56.53; Wed, 09 Mar 2022 13:57:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=QRaMnKng; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238199AbiCIUvy (ORCPT + 99 others); Wed, 9 Mar 2022 15:51:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238214AbiCIUvt (ORCPT ); Wed, 9 Mar 2022 15:51:49 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04F0065499 for ; Wed, 9 Mar 2022 12:50:49 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8407DB823CF for ; Wed, 9 Mar 2022 20:50:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45758C340F3; Wed, 9 Mar 2022 20:50:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1646859047; bh=OgKg/0vp35QJf41JfruLbYi6bvW8ZM/QnzZq2U4YFCY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=QRaMnKngT/vueTUdBgVKEAtGsWlVUdZXX+uG41GutJ9FLINk1O67xy3/cWX3W7oPn jircwk4P6VKvPxc64gnZagjIAZ1t6ChGboVcx9qnAkdD3LwH/eZksTQh2mD/9pzlLJ jxBmjx/d1KMvw6qMDBV9EEaWDJAUejijZv8WaFK8= Date: Wed, 9 Mar 2022 12:50:45 -0800 From: Andrew Morton To: David Hildenbrand Cc: Yang Shi , Linux Kernel Mailing List , Hugh Dickins , Linus Torvalds , David Rientjes , Shakeel Butt , John Hubbard , Jason Gunthorpe , Mike Kravetz , Mike Rapoport , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Jann Horn , Michal Hocko , Nadav Amit , Rik van Riel , Roman Gushchin , Andrea Arcangeli , Peter Xu , Donald Dutile , Christoph Hellwig , Oleg Nesterov , Jan Kara , Liang Zhang , Linux MM Subject: Re: [PATCH v3 3/9] mm: slightly clarify KSM logic in do_swap_page() Message-Id: <20220309125045.b04d20235a7260afceaf04d6@linux-foundation.org> In-Reply-To: References: <20220131162940.210846-1-david@redhat.com> <20220131162940.210846-4-david@redhat.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 9 Mar 2022 20:15:54 +0100 David Hildenbrand wrote: > On 09.03.22 19:48, Yang Shi wrote: > > On Mon, Jan 31, 2022 at 8:33 AM David Hildenbrand wrote: > >> > >> Let's make it clearer that KSM might only have to copy a page > >> in case we have a page in the swapcache, not if we allocated a fresh > >> page and bypassed the swapcache. While at it, add a comment why this is > >> usually necessary and merge the two swapcache conditions. > >> > >> Signed-off-by: David Hildenbrand > >> --- > >> mm/memory.c | 38 +++++++++++++++++++++++--------------- > >> 1 file changed, 23 insertions(+), 15 deletions(-) > >> > >> diff --git a/mm/memory.c b/mm/memory.c > >> index 923165b4c27e..3c91294cca98 100644 > >> --- a/mm/memory.c > >> +++ b/mm/memory.c > >> @@ -3615,21 +3615,29 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > >> goto out_release; > >> } > >> > >> - /* > >> - * Make sure try_to_free_swap or reuse_swap_page or swapoff did not > > > > We could remove the reference to "reuse_swap_page", right? > > > Yes, I noticed this a couple of days ago as well and already have a > patch prepared for that ("mm: adjust stale comment in do_swap_page() > mentioning reuse_swap_page()" at > https://github.com/davidhildenbrand/linux/commits/cow_fixes_part_3) > > If Andrew wants, we can fix that up directly before sending upstream or > I'll simply include that patch when sending out part2 v2. > > (I want to avoid sending another series just for this) Thanks, I did this. The same change plus gratuitous comment reflowing. --- a/mm/memory.c~mm-slightly-clarify-ksm-logic-in-do_swap_page-fix +++ a/mm/memory.c @@ -3609,11 +3609,11 @@ vm_fault_t do_swap_page(struct vm_fault if (swapcache) { /* - * Make sure try_to_free_swap or reuse_swap_page or swapoff did - * not release the swapcache from under us. The page pin, and - * pte_same test below, are not enough to exclude that. Even if - * it is still swapcache, we need to check that the page's swap - * has not changed. + * Make sure try_to_free_swap or swapoff did not release the + * swapcache from under us. The page pin, and pte_same test + * below, are not enough to exclude that. Even if it is still + * swapcache, we need to check that the page's swap has not + * changed. */ if (unlikely(!PageSwapCache(page) || page_private(page) != entry.val)) _