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 28DE5C433FE for ; Fri, 28 Jan 2022 09:17:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 98F216B0071; Fri, 28 Jan 2022 04:17:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 93EC26B0072; Fri, 28 Jan 2022 04:17:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8062D6B0073; Fri, 28 Jan 2022 04:17:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0152.hostedemail.com [216.40.44.152]) by kanga.kvack.org (Postfix) with ESMTP id 70B7C6B0071 for ; Fri, 28 Jan 2022 04:17:35 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 28B1A95199 for ; Fri, 28 Jan 2022 09:17:35 +0000 (UTC) X-FDA: 79079142870.22.5982A65 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 973218003A for ; Fri, 28 Jan 2022 09:17:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643361453; 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=HELvDGfjkvgKy1/ohwPlGG55+ChCuadaIUai4Iw6WCU=; b=P1yy39Sbrl7LuxnCTZ8pO5V+EK/gOP5vFFE66ykqgukj1vOfIvIogiy807SUOcoZADp9O0 ygqfddXFiBl/h0q5TG7KRLzwyS3GcKR/ru4kf/5yrqdFAvwVotA9EQsQ5aCdojS/0ktkB6 uILrIXHMI7bjLTXjQ2853xX2i1AE/+A= Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-47-SnxBGIlJMcecSXGCZAEZtA-1; Fri, 28 Jan 2022 04:17:30 -0500 X-MC-Unique: SnxBGIlJMcecSXGCZAEZtA-1 Received: by mail-pl1-f197.google.com with SMTP id y3-20020a170902ed4300b0014c958855acso1033199plb.20 for ; Fri, 28 Jan 2022 01:17:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=HELvDGfjkvgKy1/ohwPlGG55+ChCuadaIUai4Iw6WCU=; b=NCCejcLDvQJmIAfRpsx8hA4kpWJm7rNQQSM1a6MKoBZMscVmSe66QRA8gSB22V2WfT 6WFy81yihfEl6P36/U7CLo+c2NvflMV+2lecyDJjtr9FGzZLE6NrQrQ6gk2mjWWcL2GC /UWOWPlVv73WrVtc+Kb0Y+8gqJC1cZuLQS2Ll+aXXJ7nqTybQjLbvOysoKQcz1pNQMI5 jv2uIqoGIU66fSpDd6fa4gcPtFwa5TL6eQwIpDBTZHLxAsAKojYopmkaTueVOz2JayEl DMsD4uQjNYGzkqBZwlzgp67Z3HwKMXfqi+koNhKGyUR2AJOj+u8nGtpm2HBDJz81HRsy Eqww== X-Gm-Message-State: AOAM532j0PPBwBlqXFyST6yFaLKUg6rd3uLWGK/6uAlbTOA37XQj9x84 XAlLIyZaKOaW75fhovbkf3Kfdy0M7nOqe6U3LNHU5I6uekWbMKBPH3FGsoFvhI7MMmMJaIzFzWG Q0a8qp2+b5/s= X-Received: by 2002:a62:b618:: with SMTP id j24mr7053573pff.42.1643361449167; Fri, 28 Jan 2022 01:17:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJwJUib2tg8TssIShjoWPInQTxWLqWGZsk7gmVYgnhQsPD7E9YoVX10D9JX6mFLaZs+6SCVmCQ== X-Received: by 2002:a62:b618:: with SMTP id j24mr7053536pff.42.1643361448715; Fri, 28 Jan 2022 01:17:28 -0800 (PST) Received: from xz-m1.local ([94.177.118.75]) by smtp.gmail.com with ESMTPSA id h13sm5804420pfv.188.2022.01.28.01.17.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jan 2022 01:17:28 -0800 (PST) Date: Fri, 28 Jan 2022 17:17:21 +0800 From: Peter Xu To: David Hildenbrand Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Alistair Popple , Andrew Morton , Andrea Arcangeli , Matthew Wilcox , John Hubbard , Hugh Dickins , Vlastimil Babka , Yang Shi , "Kirill A . Shutemov" Subject: Re: [PATCH v3 3/4] mm: Change zap_details.zap_mapping into even_cows Message-ID: References: <20220128045412.18695-1-peterx@redhat.com> <20220128045412.18695-4-peterx@redhat.com> <847ceb80-d379-b704-8b47-0d662468370b@redhat.com> MIME-Version: 1.0 In-Reply-To: <847ceb80-d379-b704-8b47-0d662468370b@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 973218003A X-Stat-Signature: 6irfxojzzx3io9fy5rmt9ysiu35rdu8h Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=P1yy39Sb; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf30.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=peterx@redhat.com X-Rspam-User: nil X-HE-Tag: 1643361454-794670 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 Fri, Jan 28, 2022 at 10:03:20AM +0100, David Hildenbrand wrote: > On 28.01.22 05:54, Peter Xu wrote: > > Currently we have a zap_mapping pointer maintained in zap_details, when it is > > specified we only want to zap the pages that has the same mapping with what the > > caller has specified. > > > > But what we want to do is actually simpler: we want to skip zapping > > private (COW-ed) pages in some cases. We can refer to unmap_mapping_pages() > > callers where we could have passed in different even_cows values. The other > > user is unmap_mapping_folio() where we always want to skip private pages. > > > > According to Hugh, we used a mapping pointer for historical reason, as > > explained here: > > > > https://lore.kernel.org/lkml/391aa58d-ce84-9d4-d68d-d98a9c533255@google.com/ > > > > Quotting partly from Hugh: > > s/Quotting/Quoting/ Will fix. > > > > > Which raises the question again of why I did not just use a boolean flag > > there originally: aah, I think I've found why. In those days there was a > > horrible "optimization", for better performance on some benchmark I guess, > > which when you read from /dev/zero into a private mapping, would map the zero > > page there (look up read_zero_pagealigned() and zeromap_page_range() if you > > dare). So there was another category of page to be skipped along with the > > anon COWs, and I didn't want multiple tests in the zap loop, so checking > > check_mapping against page->mapping did both. I think nowadays you could do > > it by checking for PageAnon page (or genuine swap entry) instead. > > > > This patch replaced the zap_details.zap_mapping pointer into the even_cows > > boolean, then we check it against PageAnon. > > > > Suggested-by: Hugh Dickins > > Signed-off-by: Peter Xu > > --- > > mm/memory.c | 16 +++++++--------- > > 1 file changed, 7 insertions(+), 9 deletions(-) > > > > diff --git a/mm/memory.c b/mm/memory.c > > index 14d8428ff4db..ffa8c7dfe9ad 100644 > > --- a/mm/memory.c > > +++ b/mm/memory.c > > @@ -1309,8 +1309,8 @@ copy_page_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma) > > * Parameter block passed down to zap_pte_range in exceptional cases. > > */ > > struct zap_details { > > - struct address_space *zap_mapping; /* Check page->mapping if set */ > > struct folio *single_folio; /* Locked folio to be unmapped */ > > + bool even_cows; /* Zap COWed private pages too? */ > > }; > > > > /* Whether we should zap all COWed (private) pages too */ > > @@ -1321,13 +1321,10 @@ static inline bool should_zap_cows(struct zap_details *details) > > return true; > > > > /* Or, we zap COWed pages only if the caller wants to */ > > - return !details->zap_mapping; > > + return details->even_cows; > > } > > > > -/* > > - * We set details->zap_mapping when we want to unmap shared but keep private > > - * pages. Return true if we should zap this page, false otherwise. > > - */ > > +/* Decides whether we should zap this page with the page pointer specified */ > > static inline bool should_zap_page(struct zap_details *details, struct page *page) > > { > > /* If we can make a decision without *page.. */ > > @@ -1338,7 +1335,8 @@ static inline bool should_zap_page(struct zap_details *details, struct page *pag > > if (!page) > > return true; > > > > - return details->zap_mapping == page_rmapping(page); > > + /* Otherwise we should only zap non-anon pages */ > > + return !PageAnon(page); > > } > > > > static unsigned long zap_pte_range(struct mmu_gather *tlb, > > @@ -3403,7 +3401,7 @@ void unmap_mapping_folio(struct folio *folio) > > first_index = folio->index; > > last_index = folio->index + folio_nr_pages(folio) - 1; > > > > - details.zap_mapping = mapping; > > + details.even_cows = false; > > Already initialized to 0 via struct zap_details details = { }; > > We could think about > > struct zap_details details = { > .single_folio = folio, > }; > > > details.single_folio = folio; > > > > i_mmap_lock_write(mapping); > > @@ -3432,7 +3430,7 @@ void unmap_mapping_pages(struct address_space *mapping, pgoff_t start, > > pgoff_t first_index = start; > > pgoff_t last_index = start + nr - 1; > > > > - details.zap_mapping = even_cows ? NULL : mapping; > > + details.even_cows = even_cows; > > if (last_index < first_index) > > last_index = ULONG_MAX; > > > > Eventually > > struct zap_details details = { > .even_cows = even_cows, > }; I think in the very initial version I have had that C99 init format but I dropped it for some reason, perhaps when rebasing to the single_page work to avoid touching the existing code. Since as you mentioned single_folio is another.. let's do the cleanup on top? Thanks, -- Peter Xu