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=-0.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 01757C2D0DB for ; Fri, 24 Jan 2020 11:21:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 955F2206D4 for ; Fri, 24 Jan 2020 11:21:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="uw5i2aWn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 955F2206D4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E134D6B0003; Fri, 24 Jan 2020 06:21:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D9D916B0005; Fri, 24 Jan 2020 06:21:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C8B6F6B0006; Fri, 24 Jan 2020 06:21:21 -0500 (EST) 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 AC3D76B0003 for ; Fri, 24 Jan 2020 06:21:21 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id 6ECD24DC5 for ; Fri, 24 Jan 2020 11:21:21 +0000 (UTC) X-FDA: 76412286762.22.shape62_80231e8acb05a X-HE-Tag: shape62_80231e8acb05a X-Filterd-Recvd-Size: 4403 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Fri, 24 Jan 2020 11:21:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=8NtwvVXwMbEeKGtQBpJWoIGytCazgM6ygP8M0AMB/oU=; b=uw5i2aWn7LL3opxrLL8s3yLU7 OlFhXFgymnVfWwiFsQv7xuY8rEzyIYDxDrHR1EfJUBpR7CaOxyBVzpag72ZwQO2HsATPjMEIsqnMx FxGLIux7G5uCfbbZhltleiqFqOnQCntQkAm0DW8m4MmYDdbxw8O7gP6HVg9EeIiP0WRgTu1FdaMrp sNjmWJFMBE4hR09qjY/ekkPZvjZt2jLDGLhd60fvpVg5yQRhlgUOINx0CfZL49q8mhHt7CRiDnSXO 6evHpbTq9I7kRdNX3bFlOnM+U412f1nq4ftd26DBGGCqqkRFB56va9jGFf2xU4ezJZL49Z2jGV82m +eJ6gnGNQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1iux1R-0002C3-Uo; Fri, 24 Jan 2020 11:21:09 +0000 Date: Fri, 24 Jan 2020 03:21:09 -0800 From: Matthew Wilcox To: David Howells Cc: Alexander Viro , Andrew Morton , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [RFC][PATCH] iov_iter: Add ITER_MAPPING Message-ID: <20200124112109.GK4675@bombadil.infradead.org> References: <20200122193306.GB4675@bombadil.infradead.org> <3577430.1579705075@warthog.procyon.org.uk> <3785795.1579777499@warthog.procyon.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3785795.1579777499@warthog.procyon.org.uk> 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 Thu, Jan 23, 2020 at 11:04:59AM +0000, David Howells wrote: > Matthew Wilcox wrote: > > > It's perfectly legal to have compound pages in the page cache. Call > > find_subpage(page, xas.xa_index) unconditionally. > > Like this? > > #define iterate_mapping(i, n, __v, skip, STEP) { \ > struct page *page; \ > size_t wanted = n, seg, offset; \ > loff_t start = i->mapping_start + skip; \ > pgoff_t index = start >> PAGE_SHIFT; \ > \ > XA_STATE(xas, &i->mapping->i_pages, index); \ > \ > rcu_read_lock(); \ > xas_for_each(&xas, page, ULONG_MAX) { \ I actually quite liked the iterator you had before; I was thinking of wrapping it up as xas_for_each_contig(). > if (xas_retry(&xas, page) || xa_is_value(page)) { \ > WARN_ON(1); \ > break; \ > } \ Actually, xas_retry() can happen, even with the page itself pinned. It indicates the xarray data structure changed under you while walking it and you need to restart the walk from the top (arguably this shouldn't be exposed to callers at all, and in the future it may not be ... it's something inherited from the radix tree interface). So this should be: if (xas_retry(&xas, page)) continue; if (WARN_ON(xa_is_value(page))) break; > __v.bv_page = find_subpage(page, xas.xa_index); \ Yes. > offset = (i->mapping_start + skip) & ~PAGE_MASK; \ > seg = PAGE_SIZE - offset; \ > __v.bv_offset = offset; \ > __v.bv_len = min(n, seg); \ > (void)(STEP); \ > n -= __v.bv_len; \ > skip += __v.bv_len; \ > if (n == 0) \ > break; \ > } \ > rcu_read_unlock(); \ > n = wanted - n; \ > } > > Note that the walk is not restartable - and the array is supposed to have been > fully populated by the caller for the range specified - so I've made it print > a warning and end the loop if xas_retry() or xa_is_value() return true (which > takes care of the !page case too). Possibly I could just leave it to fault in > this case and not check. > > If PageHuge(page) is true, I presume I need to support that too. How do I > find out how big the page is? PageHuge() is only going to be true for hugetlbfs mappings. I'm OK with not supporting those for now ... eventually I want to get rid of the special cases in the page cache for hugetlbfs, but there's about six other projects standing between me and that.