From mboxrd@z Thu Jan 1 00:00:00 1970 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 C7FB0C433F5 for ; Wed, 9 Mar 2022 18:48:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 52E518D0002; Wed, 9 Mar 2022 13:48:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4DE5A8D0001; Wed, 9 Mar 2022 13:48:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A5E48D0002; Wed, 9 Mar 2022 13:48:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 292318D0001 for ; Wed, 9 Mar 2022 13:48:38 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E0F252453D for ; Wed, 9 Mar 2022 18:48:37 +0000 (UTC) X-FDA: 79225733874.03.08DA6FD Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by imf13.hostedemail.com (Postfix) with ESMTP id 8A0CA2000A for ; Wed, 9 Mar 2022 18:48:36 +0000 (UTC) Received: by mail-pl1-f180.google.com with SMTP id p17so2740505plo.9 for ; Wed, 09 Mar 2022 10:48:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=lvs4wUkEI3AtSweELbG0/fXXinq75WyLekwDxmjo0Pc=; b=YlzjEPe1xEmK+sY/CImJXAlfj9ZDiWWMlWq/1+rmGwLnPSArxZVHBK74+hSNPw7JIw yj2X8+VH0+WOt3SSXKiIVHVvKY7AaM6uDCBII9/qOl1vIP8SONFtgN0kx1abVQAIf1Rp OVa7e+k9y4s6Kyk0dc3larGnr8KxDnThJvACaTM2HnhzIKtMjljD0HWjLh1eDYAhBhca pohsGzEjrouJgnSjrPPT6wwOOqyphzaNYcZc7FzFJsBGOIvo+hbBEyMs+YFvPsoBIj9g iZpCJNblczziVOJjA67euin7YRsHsZjTP0eLZQRKJ5ni0/8vGTgiC7RlMDof+sFZp31i 1AiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=lvs4wUkEI3AtSweELbG0/fXXinq75WyLekwDxmjo0Pc=; b=dJi4j/V+9yCEFdG3X+jX2tPTivVyaDvow0T4pCOxuqaBuG6btuWv8pXX7hdpjpwJo0 Ne5DrK3tTnVThXDyTrvDEj5jOX2CGlfDdIv05Qj0bxypuIKOVewZC4kKJjOtA6kQ209z v1TbVxmQD+C/BWVnUNrK49xyysS2IH4J6bqkvsKfiHvWuswggS/L/pa4fCRtcQPcXDyg 6gMvC2uu1IlqzYLaFgVuyE4Ae0Yfji6dw3Alf4ZAgIfv10vLW3xrmnwb7hPjgY09qFxZ 42k8Ca2MtrFYYKYICG9p02dnajm3YUpNk0KqpRIBa/1hm8Toy7mnvKzgyOsXJ+L5ZbU4 ssjQ== X-Gm-Message-State: AOAM532oZ1ryfKPXCnwfRBXxtxetsdyQ5rJlhroymUk7q5rG+5tDkyd5 WkR79c9Yrvu0KocdE5XcxQ8fm2yDSuu608OYEt0= X-Google-Smtp-Source: ABdhPJwLizqpQx/dAQGBodHku7mkZHsuWBpMHCTfVyID0S6V6MXHIR++YHIHgjK1Wb/aVVol1fHbcw3tIJL86iV+msg= X-Received: by 2002:a17:903:124a:b0:151:99fe:1a10 with SMTP id u10-20020a170903124a00b0015199fe1a10mr847964plh.87.1646851715266; Wed, 09 Mar 2022 10:48:35 -0800 (PST) MIME-Version: 1.0 References: <20220131162940.210846-1-david@redhat.com> <20220131162940.210846-4-david@redhat.com> In-Reply-To: <20220131162940.210846-4-david@redhat.com> From: Yang Shi Date: Wed, 9 Mar 2022 10:48:23 -0800 Message-ID: Subject: Re: [PATCH v3 3/9] mm: slightly clarify KSM logic in do_swap_page() To: David Hildenbrand Cc: Linux Kernel Mailing List , Andrew Morton , 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 Content-Type: text/plain; charset="UTF-8" X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 8A0CA2000A X-Stat-Signature: wp55uwonk4uj1etbddbbpbsirr1ji3jg Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=YlzjEPe1; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf13.hostedemail.com: domain of shy828301@gmail.com designates 209.85.214.180 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-HE-Tag: 1646851716-920510 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: 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? > - * 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)) && swapcache) > - goto out_page; > - > - page = ksm_might_need_to_copy(page, vma, vmf->address); > - if (unlikely(!page)) { > - ret = VM_FAULT_OOM; > - page = swapcache; > - goto out_page; > + 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. > + */ > + if (unlikely(!PageSwapCache(page) || > + page_private(page) != entry.val)) > + goto out_page; > + > + /* > + * KSM sometimes has to copy on read faults, for example, if > + * page->index of !PageKSM() pages would be nonlinear inside the > + * anon VMA -- PageKSM() is lost on actual swapout. > + */ > + page = ksm_might_need_to_copy(page, vma, vmf->address); > + if (unlikely(!page)) { > + ret = VM_FAULT_OOM; > + page = swapcache; > + goto out_page; > + } > } > > cgroup_throttle_swaprate(page, GFP_KERNEL); > -- > 2.34.1 >