Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp676806pxb; Thu, 12 Nov 2020 13:30:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJxJAD1SNLR0h7I/X0v0Bgz/EwvpXBc0vsLvZ9VJXB2LknGYhalVVZ2FC+rMECdB5bZXvWKH X-Received: by 2002:a05:6402:1218:: with SMTP id c24mr2041382edw.259.1605216604058; Thu, 12 Nov 2020 13:30:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605216604; cv=none; d=google.com; s=arc-20160816; b=rZoImEJh5RElAnn5bjXdz+MWDD3xUwRtEKhZqMttEGZLUbzzlsOOKKoSf5XzCaMqc2 MLWxpFvo6LqjkzloNcaEp9FkjN6D75J1pRnCLT1FgXBsidXQtsbluxllRDO0YLV51VZV R1k6uE9qL2P/6+uW1Pgd0L9sxEUwShf7baE8WLd8JUo5pQ2hN7VKaghD1VV17rsU8ddU RjCEHN+hME2z6tL7lKbEKIPcDFjM3XS0kqcZtlWrjUS1izlkc6OSVLEYjPf41W4peBud Fxqp0EweFC9dFIStC5t5aR8ajBDGV1/lnxGo7/YLQ1ql6wDZHNfM29o1VZvMyyYNqW8b pyag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qbzmVFagUCXYcU5rqtSiOvPsAwsTj6kZyDh1iXpm+g8=; b=qX8UmwYi96SJQEj97ZpnBexBb3PIoPtJBFYub3URWDsDAVbRODWTvkBzMB8cAKaIeS AViGzXIWDfQgR3KG8T7K1iQtHWnAb4Br/GKnAgt0Fa1jJYyneSg7DyHbv/OIIZQq5wEM 9pNKxRHjfMSErubX7JeOG8rnzwtCf42m3qw/9iDoD2ZjHbHd8aD8W0FA+0MJ6mfP8zG9 X1QXSY9RhYSx0pwFA+hhjWyt2hrwp19bjUfn0XQ9AWz431bA09LGEYY+vvbcyHP14lg0 hdQWGkOOj1nljXFa9c7DoYad/muYTMgXhZWooeHG8oslL1KPzi/4g3oPVULtozuWgdNy b9vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=crwQX+of; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e18si4386390eji.106.2020.11.12.13.29.41; Thu, 12 Nov 2020 13:30:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=crwQX+of; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727487AbgKLV07 (ORCPT + 99 others); Thu, 12 Nov 2020 16:26:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727448AbgKLV0x (ORCPT ); Thu, 12 Nov 2020 16:26:53 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E28AC0613D1; Thu, 12 Nov 2020 13:26:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=qbzmVFagUCXYcU5rqtSiOvPsAwsTj6kZyDh1iXpm+g8=; b=crwQX+ofqsb4dwJIDejthD3rlI DfM1w6S4JFiJhDoILV7BLJ8eA/dmU2eThfVU39XCsCt23dHYcQlwEWw1EIKOnK6lp1fDK9mQaElvX A9/hA1zBksSTeN0qL4XJIdgBUSS/CMxV6eqidkNLja4FT+ciQzk38m622FhtcyOc8Uoo/YguzCf4w +z1pPgjU0XhG/Zq5hcbrE3oQa7CkaK5hPqRk1gMLI3XldOygpSoHx/6diRSxUhNxWMuRd/7mdTdjZ ZndubeNT/0NmVYgvpWR1LSOzUS5QiIoySacMtm8rz+Yaepr/jS4xKWHfCs0d17D9qV6wj1dlZLwlC jFrOHkXg==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdK7H-0007Hx-A1; Thu, 12 Nov 2020 21:26:51 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , akpm@linux-foundation.org, hughd@google.com, hch@lst.de, hannes@cmpxchg.org, yang.shi@linux.alibaba.com, dchinner@redhat.com, linux-kernel@vger.kernel.org, Jan Kara , William Kucharski Subject: [PATCH v4 16/16] mm/filemap: Return only head pages from find_get_entries Date: Thu, 12 Nov 2020 21:26:41 +0000 Message-Id: <20201112212641.27837-17-willy@infradead.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201112212641.27837-1-willy@infradead.org> References: <20201112212641.27837-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org All callers now expect head (and base) pages, and can handle multiple head pages in a single batch, so make find_get_entries() behave that way. Also take the opportunity to make it use the pagevec infrastructure instead of open-coding how pvecs behave. This has the side-effect of being able to append to a pagevec with existing contents, although we don't make use of that functionality anywhere yet. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Jan Kara Reviewed-by: William Kucharski --- include/linux/pagemap.h | 2 -- mm/filemap.c | 36 ++++++++---------------------------- mm/internal.h | 2 ++ 3 files changed, 10 insertions(+), 30 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 46d4b1704770..65ef8db8eaab 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -448,8 +448,6 @@ static inline struct page *find_subpage(struct page *head, pgoff_t index) return head + (index & (thp_nr_pages(head) - 1)); } -unsigned find_get_entries(struct address_space *mapping, pgoff_t start, - pgoff_t end, struct pagevec *pvec, pgoff_t *indices); unsigned find_get_pages_range(struct address_space *mapping, pgoff_t *start, pgoff_t end, unsigned int nr_pages, struct page **pages); diff --git a/mm/filemap.c b/mm/filemap.c index 479cbbadd93b..f8c294905e8d 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1878,49 +1878,29 @@ static inline struct page *find_get_entry(struct xa_state *xas, pgoff_t max, * the mapping. The entries are placed in @pvec. find_get_entries() * takes a reference on any actual pages it returns. * - * The search returns a group of mapping-contiguous page cache entries - * with ascending indexes. There may be holes in the indices due to - * not-present pages. + * The entries have ascending indexes. The indices may not be consecutive + * due to not-present entries or THPs. * * Any shadow entries of evicted pages, or swap entries from * shmem/tmpfs, are included in the returned array. * - * If it finds a Transparent Huge Page, head or tail, find_get_entries() - * stops at that page: the caller is likely to have a better way to handle - * the compound page as a whole, and then skip its extent, than repeatedly - * calling find_get_entries() to return all its tails. - * - * Return: the number of pages and shadow entries which were found. + * Return: The number of entries which were found. */ unsigned find_get_entries(struct address_space *mapping, pgoff_t start, pgoff_t end, struct pagevec *pvec, pgoff_t *indices) { XA_STATE(xas, &mapping->i_pages, start); struct page *page; - unsigned int ret = 0; - unsigned nr_entries = PAGEVEC_SIZE; rcu_read_lock(); while ((page = find_get_entry(&xas, end, XA_PRESENT))) { - /* - * Terminate early on finding a THP, to allow the caller to - * handle it all at once; but continue if this is hugetlbfs. - */ - if (!xa_is_value(page) && PageTransHuge(page) && - !PageHuge(page)) { - page = find_subpage(page, xas.xa_index); - nr_entries = ret + 1; - } - - indices[ret] = xas.xa_index; - pvec->pages[ret] = page; - if (++ret == nr_entries) + indices[pvec->nr] = xas.xa_index; + if (!pagevec_add(pvec, page)) break; } rcu_read_unlock(); - pvec->nr = ret; - return ret; + return pagevec_count(pvec); } /** @@ -1939,8 +1919,8 @@ unsigned find_get_entries(struct address_space *mapping, pgoff_t start, * not returned. * * The entries have ascending indexes. The indices may not be consecutive - * due to not-present entries, THP pages, pages which could not be locked - * or pages under writeback. + * due to not-present entries, THPs, pages which could not be locked or + * pages under writeback. * * Return: The number of entries which were found. */ diff --git a/mm/internal.h b/mm/internal.h index cb7487efa856..1f137a5d66bb 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -60,6 +60,8 @@ static inline void force_page_cache_readahead(struct address_space *mapping, force_page_cache_ra(&ractl, &file->f_ra, nr_to_read); } +unsigned find_get_entries(struct address_space *mapping, pgoff_t start, + pgoff_t end, struct pagevec *pvec, pgoff_t *indices); unsigned find_lock_entries(struct address_space *mapping, pgoff_t start, pgoff_t end, struct pagevec *pvec, pgoff_t *indices); -- 2.28.0