Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3627067pxk; Tue, 29 Sep 2020 01:49:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkaCH6aI9acwOFpSzvIV1B3eLvXjIYKuteeLwqtZhZ382B2k2faaQHkMSViqVZ7BOVJT7/ X-Received: by 2002:a50:fb0e:: with SMTP id d14mr2188701edq.172.1601369345868; Tue, 29 Sep 2020 01:49:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601369345; cv=none; d=google.com; s=arc-20160816; b=Jx+wUL6JMm19dGcj3zLzn9BX8IYncpGNhusM8d+w8GXmnMMKcutnPb5cec61L4iwHs TBMPFh8eSHemWqd0TdAVpiG5H0PDz7axAz5YjmbfwC7KJOC4cUoSBHXkSgv62ilV8CWD 7xZGxSqXHsJgRYBFS52u8pA2QWzyPMw/5LDuZHxVf6QW0uQ2k6w1DTRbOBeG5WEflr5o gx4QBpbajaDLCD9+iUk67PgGjwsdOP3yZQOG8IbPaF0UnbZOEtsR9Vm5PKRfGJ/k86bO x62FcCAZi5I/6DeGCduQ5PWgGla+mxIWlRPE3/TGiFiu7KJTika/qBs/pTJNL0OOE4vi BAJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=1mn0+0Y8QkWAe56uFTHwrSiL9fCCc7vreQrRy4wrn0Y=; b=gxyYXPqXAQkA9Ffuejooe41B5YpNW0uBZ9u5YRxnrbQ68P/DQhjIZOwqqtZ/8uVjOg kfA7dJzpUhqSztzhawLRo0SZ5gdVQXD+W/WmsWk/pV0Xo9HUVy/xtgBIlT5+AMhbmrU5 q/YrYJyf3vkIkJP4aXflpdtn5FCKFUe+GG5HVmtur5OVrZyMYPwC+hIhvOgB3L5fWM6b 6d1TU++rPJpQT5M/GyOKyFZnikFO99EK7nTPyorvr9ilUVyZBejPa5AZOeefI/mY4QzX nc4Tkez3vjN/Vg2B2B0hR0TOkSj9S3/BKYxIXr6zVtQEOr8wlF+wXm6BTSOKsU0Id1zY txcA== ARC-Authentication-Results: i=1; mx.google.com; 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 g11si2207813eds.232.2020.09.29.01.48.43; Tue, 29 Sep 2020 01:49:05 -0700 (PDT) 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; 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 S1727871AbgI2Iq4 (ORCPT + 99 others); Tue, 29 Sep 2020 04:46:56 -0400 Received: from mx2.suse.de ([195.135.220.15]:54800 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725355AbgI2Iq4 (ORCPT ); Tue, 29 Sep 2020 04:46:56 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 2AE81ACA3; Tue, 29 Sep 2020 08:46:54 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id D591D1E12E9; Tue, 29 Sep 2020 10:46:53 +0200 (CEST) Date: Tue, 29 Sep 2020 10:46:53 +0200 From: Jan Kara To: "Matthew Wilcox (Oracle)" Cc: linux-mm@kvack.org, Andrew Morton , Hugh Dickins , William Kucharski , Johannes Weiner , Jan Kara , Yang Shi , Dave Chinner , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 04/12] mm/filemap: Add mapping_seek_hole_data Message-ID: <20200929084653.GC10896@quack2.suse.cz> References: <20200914130042.11442-1-willy@infradead.org> <20200914130042.11442-5-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200914130042.11442-5-willy@infradead.org> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 14-09-20 14:00:34, Matthew Wilcox (Oracle) wrote: > Rewrite shmem_seek_hole_data() and move it to filemap.c. > > Signed-off-by: Matthew Wilcox (Oracle) ... > +/** > + * mapping_seek_hole_data - Seek for SEEK_DATA / SEEK_HOLE in the page cache. > + * @mapping: Address space to search. > + * @start: First byte to consider. > + * @end: Limit of search (exclusive). > + * @whence: Either SEEK_HOLE or SEEK_DATA. > + * > + * If the page cache knows which blocks contain holes and which blocks > + * contain data, your filesystem can use this function to implement > + * SEEK_HOLE and SEEK_DATA. This is useful for filesystems which are > + * entirely memory-based such as tmpfs, and filesystems which support > + * unwritten extents. > + * > + * Return: The requested offset on successs, or -ENXIO if @whence specifies > + * SEEK_DATA and there is no data after @start. There is an implicit hole > + * after @end - 1, so SEEK_HOLE returns @end if all the bytes between @start > + * and @end contain data. > + */ > +loff_t mapping_seek_hole_data(struct address_space *mapping, loff_t start, > + loff_t end, int whence) > +{ > + XA_STATE(xas, &mapping->i_pages, start >> PAGE_SHIFT); > + pgoff_t max = (end - 1) / PAGE_SIZE; > + bool seek_data = (whence == SEEK_DATA); > + struct page *page; > + > + if (end <= start) > + return -ENXIO; > + > + rcu_read_lock(); > + while ((page = xas_find_get_entry(&xas, max, XA_PRESENT))) { > + loff_t pos = xas.xa_index * PAGE_SIZE; OK, but for ordinary filesystems this could be problematic because of exceptional entries? Also for shmem you've dropped the PageUptodate check which I'm not sure is safe? Honza -- Jan Kara SUSE Labs, CR