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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C0DBC433F5 for ; Fri, 3 Dec 2021 18:01:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 99F346B0073; Fri, 3 Dec 2021 13:01:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 94DDC6B0074; Fri, 3 Dec 2021 13:01:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EE926B0075; Fri, 3 Dec 2021 13:01:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0002.hostedemail.com [216.40.44.2]) by kanga.kvack.org (Postfix) with ESMTP id 6C7496B0073 for ; Fri, 3 Dec 2021 13:01:30 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 25E0E184B355B for ; Fri, 3 Dec 2021 18:01:20 +0000 (UTC) X-FDA: 78877249920.29.69DE4DE Received: from mail-il1-f180.google.com (mail-il1-f180.google.com [209.85.166.180]) by imf18.hostedemail.com (Postfix) with ESMTP id A5836400C349 for ; Fri, 3 Dec 2021 18:01:19 +0000 (UTC) Received: by mail-il1-f180.google.com with SMTP id i6so3577753ila.0 for ; Fri, 03 Dec 2021 10:01:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=kZ3PTnb0foNG0vY9usa7lbYMHU4ZVKt50x7xLsKrnio=; b=Ts5QOvpP0FLyXYwn86u2OJJolEMOiKtZxUH9QHycNUJ7KcUL8mw6w9AGnszkDqsJQ7 Rdgx8bfNgw1NfcCW6Hv7XPF3NT5F99LekaHU77DGZCguZqLoDpKzVp8OqoYuOgjQNcXG TMvhbr8fcvjPHYN1VL0AosK6DK1ac6pkIrc4WSVPUS/y6okyfJCjkUXoJJnsEsYJoFiQ u7fiXZFBgQziKLvZZ7J4GcY4Fc3uce1OQgv+uWFSV2zlKUIhs8R+6joQzgRyg9dN5PTl rULMZAyMJG0JFrpKQl66ppTPPGtiGoJEftmkgyEYq60dp2oWhqoZUTE1WdLTSzW64jph lP7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=kZ3PTnb0foNG0vY9usa7lbYMHU4ZVKt50x7xLsKrnio=; b=b7la1aLuxpXA5gt6PIOJVptv2WYx7g+b02B/Ci5Dq4HM6oLKGJ6Gd10dXrbt7zgC21 mVF1kknffaKsqeBmxg6R2Fxo71G+pfj5daP3DdEINawXnh0iu/zkDIX2E7sMlTkZ7jLc 0tn3Y88f0yL9O/wGT2fDVb7B4GqmDukPhBpAjN2GWT6KPgruodc5zVbne+OOy7NZb+jS /SP+MLu/eqFjsF0CJetuO04xhBZGRxIwvORT2Zso634mu5qNclUDxhUpgmATMmxNMxV4 TNF9cuARfg4KRwj+2hsJmFVRcnVZV0VL+MtwDpWm5nnHDU+QPPO21p9Xi5aNIEfxsybk mF6Q== X-Gm-Message-State: AOAM532pWIqnwjKfMGyl8A+xOY/SO/nAvEhJeDHUZ9nAu0PNrYYB9Q4Q PAmla4N5p6pw/6p8MprcEGu6viSxNko1nlCF X-Google-Smtp-Source: ABdhPJx52SmRr5isL72Jfv4cF1XEO3vFGPzYJ7ed47ahO1e7Gw97xPJ8z/WqpVtgTz9niS6tH2vZyw== X-Received: by 2002:a05:6e02:1c2a:: with SMTP id m10mr18369997ilh.279.1638554475529; Fri, 03 Dec 2021 10:01:15 -0800 (PST) Received: from [192.168.1.30] ([207.135.234.126]) by smtp.gmail.com with ESMTPSA id x18sm2235760iow.53.2021.12.03.10.01.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Dec 2021 10:01:15 -0800 (PST) Subject: Re: [PATCH 1/2] mm: move filemap_range_needs_writeback() into header From: Jens Axboe To: Matthew Wilcox Cc: linux-block@vger.kernel.org, linux-mm@kvack.org References: <20211203153829.298893-1-axboe@kernel.dk> <20211203153829.298893-2-axboe@kernel.dk> <5e92c117-0cdb-9ea6-3f1c-912e683c4e51@kernel.dk> <89810ae4-7c9b-ec8f-5450-ef8dc51ad8a4@kernel.dk> <97e253f7-d945-0c6b-3d8b-dcf597f04f69@kernel.dk> Message-ID: <9cabdcc3-e760-bab5-edfe-ae225e5d4db9@kernel.dk> Date: Fri, 3 Dec 2021 11:01:14 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Stat-Signature: p399khnhduq8oyty5t3szatqy6gf7szi Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel-dk.20210112.gappssmtp.com header.s=20210112 header.b=Ts5QOvpP; dmarc=none; spf=pass (imf18.hostedemail.com: domain of axboe@kernel.dk designates 209.85.166.180 as permitted sender) smtp.mailfrom=axboe@kernel.dk X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: A5836400C349 X-HE-Tag: 1638554479-864192 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 12/3/21 10:57 AM, Jens Axboe wrote: >> I'm happy with this, if you just move it to pagemap.h > > OK, I'll try it out. Wasn't too bad at all, actually just highlighted that I missed removing the previous declaration of filemap_range_needs_writeback() in fs.h I'll do a full compile and test, but this seems sane. commit 63c6b3846b77041d239d5b5b5a907b5c82a21c4c Author: Jens Axboe Date: Thu Oct 28 08:47:05 2021 -0600 mm: move filemap_range_needs_writeback() into header No functional changes in this patch, just in preparation for efficiently calling this light function from the block O_DIRECT handling. Signed-off-by: Jens Axboe diff --git a/include/linux/fs.h b/include/linux/fs.h index bbf812ce89a8..6b8dc1a78df6 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2847,8 +2847,6 @@ static inline int filemap_fdatawait(struct address_space *mapping) extern bool filemap_range_has_page(struct address_space *, loff_t lstart, loff_t lend); -extern bool filemap_range_needs_writeback(struct address_space *, - loff_t lstart, loff_t lend); extern int filemap_write_and_wait_range(struct address_space *mapping, loff_t lstart, loff_t lend); extern int __filemap_fdatawrite_range(struct address_space *mapping, diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 605246452305..274a0710f2c5 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -963,6 +963,35 @@ static inline int add_to_page_cache(struct page *page, int __filemap_add_folio(struct address_space *mapping, struct folio *folio, pgoff_t index, gfp_t gfp, void **shadowp); +bool filemap_range_has_writeback(struct address_space *mapping, + loff_t start_byte, loff_t end_byte); + +/** + * filemap_range_needs_writeback - check if range potentially needs writeback + * @mapping: address space within which to check + * @start_byte: offset in bytes where the range starts + * @end_byte: offset in bytes where the range ends (inclusive) + * + * Find at least one page in the range supplied, usually used to check if + * direct writing in this range will trigger a writeback. Used by O_DIRECT + * read/write with IOCB_NOWAIT, to see if the caller needs to do + * filemap_write_and_wait_range() before proceeding. + * + * Return: %true if the caller should do filemap_write_and_wait_range() before + * doing O_DIRECT to a page in this range, %false otherwise. + */ +static inline bool filemap_range_needs_writeback(struct address_space *mapping, + loff_t start_byte, + loff_t end_byte) +{ + if (!mapping->nrpages) + return false; + if (!mapping_tagged(mapping, PAGECACHE_TAG_DIRTY) && + !mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK)) + return false; + return filemap_range_has_writeback(mapping, start_byte, end_byte); +} + /** * struct readahead_control - Describes a readahead request. * diff --git a/mm/filemap.c b/mm/filemap.c index daa0e23a6ee6..655c9eec06b3 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -646,8 +646,8 @@ static bool mapping_needs_writeback(struct address_space *mapping) return mapping->nrpages; } -static bool filemap_range_has_writeback(struct address_space *mapping, - loff_t start_byte, loff_t end_byte) +bool filemap_range_has_writeback(struct address_space *mapping, + loff_t start_byte, loff_t end_byte) { XA_STATE(xas, &mapping->i_pages, start_byte >> PAGE_SHIFT); pgoff_t max = end_byte >> PAGE_SHIFT; @@ -667,34 +667,8 @@ static bool filemap_range_has_writeback(struct address_space *mapping, } rcu_read_unlock(); return page != NULL; - -} - -/** - * filemap_range_needs_writeback - check if range potentially needs writeback - * @mapping: address space within which to check - * @start_byte: offset in bytes where the range starts - * @end_byte: offset in bytes where the range ends (inclusive) - * - * Find at least one page in the range supplied, usually used to check if - * direct writing in this range will trigger a writeback. Used by O_DIRECT - * read/write with IOCB_NOWAIT, to see if the caller needs to do - * filemap_write_and_wait_range() before proceeding. - * - * Return: %true if the caller should do filemap_write_and_wait_range() before - * doing O_DIRECT to a page in this range, %false otherwise. - */ -bool filemap_range_needs_writeback(struct address_space *mapping, - loff_t start_byte, loff_t end_byte) -{ - if (!mapping_needs_writeback(mapping)) - return false; - if (!mapping_tagged(mapping, PAGECACHE_TAG_DIRTY) && - !mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK)) - return false; - return filemap_range_has_writeback(mapping, start_byte, end_byte); } -EXPORT_SYMBOL_GPL(filemap_range_needs_writeback); +EXPORT_SYMBOL_GPL(filemap_range_has_writeback); /** * filemap_write_and_wait_range - write out & wait on a file range -- Jens Axboe