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 X-Spam-Level: X-Spam-Status: No, score=-28.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D4C2C433EF for ; Fri, 24 Sep 2021 04:44:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E24A761241 for ; Fri, 24 Sep 2021 04:44:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E24A761241 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 76035900002; Fri, 24 Sep 2021 00:44:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E83F6B0071; Fri, 24 Sep 2021 00:44:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 56155900002; Fri, 24 Sep 2021 00:44:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0027.hostedemail.com [216.40.44.27]) by kanga.kvack.org (Postfix) with ESMTP id 42EAD6B006C for ; Fri, 24 Sep 2021 00:44:31 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id EC6311816BB65 for ; Fri, 24 Sep 2021 04:44:30 +0000 (UTC) X-FDA: 78621225900.16.ADB5E0B Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) by imf04.hostedemail.com (Postfix) with ESMTP id AED8550000A8 for ; Fri, 24 Sep 2021 04:44:30 +0000 (UTC) Received: by mail-qt1-f180.google.com with SMTP id e16so8304877qte.13 for ; Thu, 23 Sep 2021 21:44:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=gPYCuDbvMf79tood1FE9hbAIqwGfw8AvWs2PSHrUP8o=; b=MQ1By/FYcRqrJFVcfIJGhCzjmDszrwSAaqQFDn1/gQGouwH3HYOpSD99NH659wh8xr ew9MRvm8WsUzGDCYsUThcQyfw1nqULNGEjPujVeUDWZiB70M5Lj06tBfEA/EC2grdItn qVU08IUDBy7/SZgV1oXjIJWqzGY3aKrBw3pnViFtoaPhOOyeYWFik64BfZU3nDFrvfG2 TpUlBkPAyi2XuKHDUnET8Ps/Nj3Pya/ztiSR8Iz2PVE4cdtOwLBMDQ1g7zErlagII2ZN UdzCjWPOnO0i94N0y1p3W6DmiMxX0bGU9d6SWwGtGGxhCFl+Uk5bHYLD3uc/AkKfRgSG gl1w== 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:in-reply-to:message-id :references:mime-version; bh=gPYCuDbvMf79tood1FE9hbAIqwGfw8AvWs2PSHrUP8o=; b=aP1+wDohc6yIm/T+/qpiZqWiWsuoU8S1IYoVHW/PIAm7T6eG8AzYHIKVUGf8bBt9Xy GyrnIen7ITT8n1PNfPV1zmcVY7fOLK4u9HhZrZaFV+3ynWvc98HEkBupojf1HaZzyTbt sQJlCfhCc8m6jt+IUImAu2pbhHGt8P93xxAb0OfXsRP10o6l13jRA2eVTv8HNWGbnZ/O EoGUUK83hGYOBVmhaHQwARI/2BmGPK8xojqgPIsO4ncZz8SFNRWmHhjwAazmjE2FKqPp 0+Mas+tVvPpVykHgr/8VWukG77uJe5taEVNo+qtopLaUq5G4ShC7VTzgnJhvl2xskNFj sOYg== X-Gm-Message-State: AOAM5307zA3kqTJdB8ZS1e5qGX06lidAg7Crtq6yh43ynUUnMxERKvL7 NyHNWBpO2qLVbclE1YbP3/iCDQ== X-Google-Smtp-Source: ABdhPJz0Jk6U9SixoASSKntjzJqscl0+BZsorWyeWOkuooX+jtgVtPnjzWRtZ3vV4tgLFctUDPGr3w== X-Received: by 2002:ac8:13c4:: with SMTP id i4mr2254076qtj.350.1632458669817; Thu, 23 Sep 2021 21:44:29 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id s18sm4888880qtn.46.2021.09.23.21.44.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Sep 2021 21:44:29 -0700 (PDT) Date: Thu, 23 Sep 2021 21:44:27 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Peter Xu cc: linux-kernel@vger.kernel.org, Andrew Morton , linux-mm@kvack.org, Hugh Dickins , David Hildenbrand , Liam Howlett , Mike Rapoport , Alistair Popple , Matthew Wilcox , Yang Shi , "Kirill A . Shutemov" , Jerome Glisse , Miaohe Lin , Andrea Arcangeli Subject: Re: [PATCH v4 4/4] mm: Add zap_skip_check_mapping() helper In-Reply-To: <20210915181538.11288-1-peterx@redhat.com> Message-ID: <4746b58e-34e9-619d-fb16-afa1fb7fff8c@google.com> References: <20210915181456.10739-1-peterx@redhat.com> <20210915181538.11288-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="MQ1By/FY"; spf=pass (imf04.hostedemail.com: domain of hughd@google.com designates 209.85.160.180 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: AED8550000A8 X-Stat-Signature: xwwhg3dsuyt9hw8xa7mf9uitrceqz7ty X-HE-Tag: 1632458670-123375 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 Wed, 15 Sep 2021, Peter Xu wrote: > Use the helper for the checks. Rename "check_mapping" into "zap_mapping" > because "check_mapping" looks like a bool but in fact it stores the mapping > itself. When it's set, we check the mapping (it must be non-NULL). When it's > cleared we skip the check, which works like the old way. > > Move the duplicated comments to the helper too. > > Reviewed-by: Alistair Popple > Signed-off-by: Peter Xu Again, I won't NAK, but I have no enthusiasm for this at all: our tastes clearly differ. I don't find the new name helpful, I don't find the separated "helper" helpful, and you have hidden the helpful comment (but I'd be on firmer ground if the unmap_shared_mapping_pages() it referred to had ever existed! perhaps it was in an intermediate tree). But then I would feel this way, wouldn't I? See dd9fd0e03de ("[PATCH] rmap: nonlinear truncation") in //git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git I'm glad to see that you have dropped 5/5 for now: I was not keen on that one either. Hugh > --- > include/linux/mm.h | 16 +++++++++++++++- > mm/memory.c | 29 ++++++----------------------- > 2 files changed, 21 insertions(+), 24 deletions(-) > > diff --git a/include/linux/mm.h b/include/linux/mm.h > index d1126f731221..ed44f31615d9 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -1721,10 +1721,24 @@ extern void user_shm_unlock(size_t, struct ucounts *); > * Parameter block passed down to zap_pte_range in exceptional cases. > */ > struct zap_details { > - struct address_space *check_mapping; /* Check page->mapping if set */ > + struct address_space *zap_mapping; /* Check page->mapping if set */ > struct page *single_page; /* Locked page to be unmapped */ > }; > > +/* > + * We set details->zap_mappings when we want to unmap shared but keep private > + * pages. Return true if skip zapping this page, false otherwise. > + */ > +static inline bool > +zap_skip_check_mapping(struct zap_details *details, struct page *page) > +{ > + if (!details || !page) > + return false; > + > + return details->zap_mapping && > + (details->zap_mapping != page_rmapping(page)); > +} > + > struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr, > pte_t pte); > struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr, > diff --git a/mm/memory.c b/mm/memory.c > index a7e427177817..8db8ce0ca6ce 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -1333,16 +1333,8 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, > struct page *page; > > page = vm_normal_page(vma, addr, ptent); > - if (unlikely(details) && page) { > - /* > - * unmap_shared_mapping_pages() wants to > - * invalidate cache without truncating: > - * unmap shared but keep private pages. > - */ > - if (details->check_mapping && > - details->check_mapping != page_rmapping(page)) > - continue; > - } > + if (unlikely(zap_skip_check_mapping(details, page))) > + continue; > ptent = ptep_get_and_clear_full(mm, addr, pte, > tlb->fullmm); > tlb_remove_tlb_entry(tlb, pte, addr); > @@ -1375,17 +1367,8 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, > is_device_exclusive_entry(entry)) { > struct page *page = pfn_swap_entry_to_page(entry); > > - if (unlikely(details && details->check_mapping)) { > - /* > - * unmap_shared_mapping_pages() wants to > - * invalidate cache without truncating: > - * unmap shared but keep private pages. > - */ > - if (details->check_mapping != > - page_rmapping(page)) > - continue; > - } > - > + if (unlikely(zap_skip_check_mapping(details, page))) > + continue; > pte_clear_not_present_full(mm, addr, pte, tlb->fullmm); > rss[mm_counter(page)]--; > > @@ -3369,7 +3352,7 @@ void unmap_mapping_page(struct page *page) > first_index = page->index; > last_index = page->index + thp_nr_pages(page) - 1; > > - details.check_mapping = mapping; > + details.zap_mapping = mapping; > details.single_page = page; > > i_mmap_lock_write(mapping); > @@ -3398,7 +3381,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.check_mapping = even_cows ? NULL : mapping; > + details.zap_mapping = even_cows ? NULL : mapping; > if (last_index < first_index) > last_index = ULONG_MAX; > > -- > 2.31.1