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 9BD2FC433EF for ; Fri, 28 Jan 2022 09:03:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0ED9B6B0072; Fri, 28 Jan 2022 04:03:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 09D226B0074; Fri, 28 Jan 2022 04:03:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F00B76B0072; Fri, 28 Jan 2022 04:03:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0003.hostedemail.com [216.40.44.3]) by kanga.kvack.org (Postfix) with ESMTP id E2E666B0072 for ; Fri, 28 Jan 2022 04:03:25 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id AADB492767 for ; Fri, 28 Jan 2022 09:03:25 +0000 (UTC) X-FDA: 79079107170.20.17E37A1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 1E45CC001B for ; Fri, 28 Jan 2022 09:03:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643360604; 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=k6fRFZaCxJ9/sKr7eukzgsxP2eZihqtSLhrBXhP7zxA=; b=GfDddd73q9tt9uPHozJOcVxY51iVwyDXqkMZbqw2DArnLJJsGLv9iQlVS7peL+adRJ0JzJ LhlTCqHaUZP8mwaIcKJNhCefRer3fGEbBDm9586Wm/CZbTah/GV79ousSYMExEeuV+weXV zxKaXqf776jnH/WWz9/PHrzY6kuhQIE= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-70-he52x2LtOdOTxZn8iM8Zuw-1; Fri, 28 Jan 2022 04:03:23 -0500 X-MC-Unique: he52x2LtOdOTxZn8iM8Zuw-1 Received: by mail-ed1-f69.google.com with SMTP id j1-20020aa7c341000000b0040417b84efeso2728536edr.21 for ; Fri, 28 Jan 2022 01:03:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=k6fRFZaCxJ9/sKr7eukzgsxP2eZihqtSLhrBXhP7zxA=; b=zc0pctdhVMVt9RACn3ZFwPWzaVrzVUETb8BG6UTdsoxCOHMtY85mSgHZHFMmizip+H iszxx0upNTtViBhHOnHOBimf35ZqH2/P2hbffhSGMYKiMH/NBs5fM3lvPN+JfO3yXt5O LcWP+TFSo66/uD7GwKTaH+/nFzOdyWfr4TnEYUJFK/41pqVv/KSqA97GMLjWwIIzmrgf gGPPS6ba1/FhExBMqd+egQ6tb4OeWXJ1Uea5Z7xnwbFMYnNg2JMTaC4dSI2MUXaTRS49 OYO97+7vcRV5lMXzbVYwvg69fO75YUTZY1JwRSCn0cK5cPS8DU8BvpeKDh7vAj8FPQ9R 6wrg== X-Gm-Message-State: AOAM532jLpDd/YJQ2CNA4v8RUNISk1DjmkLD1CoLH17LY9mfV7n1bbPD hTNyO1ha8p0ljjN1w8c5grWsULjNMev59PBwrVKCUOBdgsPz1FqD8g39veUPFtqiTqLTceUDMLO 56e+Q0Moiq2A= X-Received: by 2002:aa7:d313:: with SMTP id p19mr7550083edq.380.1643360601824; Fri, 28 Jan 2022 01:03:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJzwLTfB+FQpW/Kh46RzIU62HlxvCR6hkBiYhxXWrkOPDyzrf6sUvdJ0chSBKeGemvbFZzeuFw== X-Received: by 2002:aa7:d313:: with SMTP id p19mr7550062edq.380.1643360601598; Fri, 28 Jan 2022 01:03:21 -0800 (PST) Received: from ?IPV6:2003:cb:c70e:5c00:522f:9bcd:24a0:cd70? (p200300cbc70e5c00522f9bcd24a0cd70.dip0.t-ipconnect.de. [2003:cb:c70e:5c00:522f:9bcd:24a0:cd70]) by smtp.gmail.com with ESMTPSA id u12sm12634499edq.8.2022.01.28.01.03.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 28 Jan 2022 01:03:21 -0800 (PST) Message-ID: <847ceb80-d379-b704-8b47-0d662468370b@redhat.com> Date: Fri, 28 Jan 2022 10:03:20 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH v3 3/4] mm: Change zap_details.zap_mapping into even_cows To: Peter Xu , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Alistair Popple , Andrew Morton , Andrea Arcangeli , Matthew Wilcox , John Hubbard , Hugh Dickins , Vlastimil Babka , Yang Shi , "Kirill A . Shutemov" References: <20220128045412.18695-1-peterx@redhat.com> <20220128045412.18695-4-peterx@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20220128045412.18695-4-peterx@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 1E45CC001B X-Stat-Signature: kzsha84nytse9n75ndr9z77yxw89jp8p X-Rspam-User: nil Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GfDddd73; spf=none (imf10.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1643360604-443752 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 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/ > > 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, }; -- Thanks, David / dhildenb