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=-23.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,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 B240CC433F5 for ; Fri, 24 Sep 2021 04:14:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 60BD4610D1 for ; Fri, 24 Sep 2021 04:14:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 60BD4610D1 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 8673D6B006C; Fri, 24 Sep 2021 00:14:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 817206B0071; Fri, 24 Sep 2021 00:14:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6DDE46B0073; Fri, 24 Sep 2021 00:14:45 -0400 (EDT) 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 5F5E36B006C for ; Fri, 24 Sep 2021 00:14:45 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 163BD1828B5D0 for ; Fri, 24 Sep 2021 04:14:45 +0000 (UTC) X-FDA: 78621150930.20.788CC2C Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by imf13.hostedemail.com (Postfix) with ESMTP id C425A149CB91 for ; Fri, 24 Sep 2021 04:14:44 +0000 (UTC) Received: by mail-qk1-f177.google.com with SMTP id t4so26496593qkb.9 for ; Thu, 23 Sep 2021 21:14:44 -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=wo5+YT4FAEs3BsYTUC5laEd8fuRm8H2TtgaNzbZpkpw=; b=N6ooeHLc0YzrYjENakNJkiFKHQBUD0A91XgGgV/FMM+yMSYxMOsf9PjmzS3MeYW7GT MnpUcorzKpM3Bj2T6vBBB3B8/9KzbNXDgkEq4F3yxn51UFR/J0CYRRVqt6kzkdEGzfPW LN4FddN72EWn80Wlq4vsK7zaxqrTIeMWfz2rK9XjDxIlfcLimv1RxmGELSMHH0v89yPG NPW+X7CBxQLbUUoN3fjV7dELdjFqNBgZP7oMZkyAFRN2CHb4xJbQniG8aFow/tpC1Zz+ ziQ4hE7iP5gpYTQI9wPNNo3zMoZVC1C/H0zb0H4bLPnMiKUkWlJ941PAJiApbrUG17Xe qZ0Q== 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=wo5+YT4FAEs3BsYTUC5laEd8fuRm8H2TtgaNzbZpkpw=; b=u1zSa4swacOIT1FlOQCZYHhxTjbc9vRDGPfNpdV1PxqkgxMz33fMmO6fGXAhO7QoSF SeI3TM8cd6MiPs/ENgz2D7VxG3NKPFvJvnLHfh2UIeyioQh4c63VBEzsdlzwJd/vnKdf ys/j36slnm0MJ1uHPMj8aHi/xoiyTa82Toqmljpy+zoc/z3L/F7ex7GH1pcQvIEGfpJn KcDKISHwRC9P5vEn6fZ0sWka4Dy+2TKxCQtCBVFksxXCXQNyf1Ksn4N1N4e/4sJM+wDg TNO+WShETQMmPHlkmV9ZS7TuxdXM1v82mS+WyhjknvHWKbUoLJ3uyODyfNjrhZJ0n70s OeBQ== X-Gm-Message-State: AOAM530srzWOm4eksyCJK/Z4SwYVkuKl19cghvFWfP0cF0MbCN6a6JS3 YSO2e98zEJypgldcwhtiekDymw== X-Google-Smtp-Source: ABdhPJxyMjL4tECiJ9L+FBKdrvjmDcTOGX+7UtU+6y/KusLb/hd9olMa99MMwXBbJf2NhPFhyKR0Uw== X-Received: by 2002:ae9:dd83:: with SMTP id r125mr8757419qkf.159.1632456883903; Thu, 23 Sep 2021 21:14:43 -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 v17sm5590811qkp.75.2021.09.23.21.14.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Sep 2021 21:14:43 -0700 (PDT) Date: Thu, 23 Sep 2021 21:14:41 -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 3/4] mm: Drop first_index/last_index in zap_details In-Reply-To: <20210915181535.11238-1-peterx@redhat.com> Message-ID: <11a5e5d0-5e91-312e-84ac-b62a153d738@google.com> References: <20210915181456.10739-1-peterx@redhat.com> <20210915181535.11238-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Rspamd-Queue-Id: C425A149CB91 X-Stat-Signature: t5641tbitphypsy7qh6i6dd8m7cdqg5e Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=N6ooeHLc; spf=pass (imf13.hostedemail.com: domain of hughd@google.com designates 209.85.222.177 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam06 X-HE-Tag: 1632456884-161465 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: > The first_index/last_index parameters in zap_details are actually only used in > unmap_mapping_range_tree(). At the meantime, this function is only called by > unmap_mapping_pages() once. Instead of passing these two variables through the > whole stack of page zapping code, remove them from zap_details and let them > simply be parameters of unmap_mapping_range_tree(), which is inlined. > > Reviewed-by: Alistair Popple > Reviewed-by: David Hildenbrand > Reviewed-by: Liam Howlett > Signed-off-by: Peter Xu And this one is fine too, thanks. I don't know whether it saves anything (ah yes, with args in registers not on the stack, should save a little), but it's helpful to limit the scope of those indices. You may wonder how they came to be in zap_details: that dates from the days of remap_file_pages(): nonlinear vmas, in which the zapper needed to check each pte_file()'s offset against first and last index, to decide whether to zap or not. They should have been removed in 4.0. Acked-by: Hugh Dickins > --- > include/linux/mm.h | 2 -- > mm/memory.c | 31 ++++++++++++++++++------------- > 2 files changed, 18 insertions(+), 15 deletions(-) > > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 73a52aba448f..d1126f731221 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -1722,8 +1722,6 @@ extern void user_shm_unlock(size_t, struct ucounts *); > */ > struct zap_details { > struct address_space *check_mapping; /* Check page->mapping if set */ > - pgoff_t first_index; /* Lowest page->index to unmap */ > - pgoff_t last_index; /* Highest page->index to unmap */ > struct page *single_page; /* Locked page to be unmapped */ > }; > > diff --git a/mm/memory.c b/mm/memory.c > index 7b095f07c4ef..a7e427177817 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -3321,20 +3321,20 @@ static void unmap_mapping_range_vma(struct vm_area_struct *vma, > } > > static inline void unmap_mapping_range_tree(struct rb_root_cached *root, > + pgoff_t first_index, > + pgoff_t last_index, > struct zap_details *details) > { > struct vm_area_struct *vma; > pgoff_t vba, vea, zba, zea; > > - vma_interval_tree_foreach(vma, root, > - details->first_index, details->last_index) { > - > + vma_interval_tree_foreach(vma, root, first_index, last_index) { > vba = vma->vm_pgoff; > vea = vba + vma_pages(vma) - 1; > - zba = details->first_index; > + zba = first_index; > if (zba < vba) > zba = vba; > - zea = details->last_index; > + zea = last_index; > if (zea > vea) > zea = vea; > > @@ -3360,18 +3360,22 @@ void unmap_mapping_page(struct page *page) > { > struct address_space *mapping = page->mapping; > struct zap_details details = { }; > + pgoff_t first_index; > + pgoff_t last_index; > > VM_BUG_ON(!PageLocked(page)); > VM_BUG_ON(PageTail(page)); > > + first_index = page->index; > + last_index = page->index + thp_nr_pages(page) - 1; > + > details.check_mapping = mapping; > - details.first_index = page->index; > - details.last_index = page->index + thp_nr_pages(page) - 1; > details.single_page = page; > > i_mmap_lock_write(mapping); > if (unlikely(!RB_EMPTY_ROOT(&mapping->i_mmap.rb_root))) > - unmap_mapping_range_tree(&mapping->i_mmap, &details); > + unmap_mapping_range_tree(&mapping->i_mmap, first_index, > + last_index, &details); > i_mmap_unlock_write(mapping); > } > > @@ -3391,16 +3395,17 @@ void unmap_mapping_pages(struct address_space *mapping, pgoff_t start, > pgoff_t nr, bool even_cows) > { > struct zap_details details = { }; > + pgoff_t first_index = start; > + pgoff_t last_index = start + nr - 1; > > details.check_mapping = even_cows ? NULL : mapping; > - details.first_index = start; > - details.last_index = start + nr - 1; > - if (details.last_index < details.first_index) > - details.last_index = ULONG_MAX; > + if (last_index < first_index) > + last_index = ULONG_MAX; > > i_mmap_lock_write(mapping); > if (unlikely(!RB_EMPTY_ROOT(&mapping->i_mmap.rb_root))) > - unmap_mapping_range_tree(&mapping->i_mmap, &details); > + unmap_mapping_range_tree(&mapping->i_mmap, first_index, > + last_index, &details); > i_mmap_unlock_write(mapping); > } > > -- > 2.31.1