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=-9.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 C7023C00A89 for ; Mon, 2 Nov 2020 19:00:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 31C6622268 for ; Mon, 2 Nov 2020 19:00:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="R897Ejv8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 31C6622268 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 60F6C6B0036; Mon, 2 Nov 2020 14:00:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5C0016B005C; Mon, 2 Nov 2020 14:00:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4ACF46B006E; Mon, 2 Nov 2020 14:00:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0241.hostedemail.com [216.40.44.241]) by kanga.kvack.org (Postfix) with ESMTP id 0D22B6B0036 for ; Mon, 2 Nov 2020 14:00:13 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 9C5D3181AC9CC for ; Mon, 2 Nov 2020 19:00:12 +0000 (UTC) X-FDA: 77440393464.25.lead38_0e11894272b2 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 685F61804E3A1 for ; Mon, 2 Nov 2020 19:00:12 +0000 (UTC) X-HE-Tag: lead38_0e11894272b2 X-Filterd-Recvd-Size: 7608 Received: from mail-qk1-f194.google.com (mail-qk1-f194.google.com [209.85.222.194]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Mon, 2 Nov 2020 19:00:11 +0000 (UTC) Received: by mail-qk1-f194.google.com with SMTP id p3so12441131qkk.7 for ; Mon, 02 Nov 2020 11:00:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=XWZf9/UhYv4G6VmJ+Bk1hbFhCA//zACfvngw3x+8vNE=; b=R897Ejv8j/1FGKjM+qZ0XYnRPDaOt8eV1hOuSnVGbHFG/AVOgUIv6HeWQDiXX0Vo7n +CNJUJO1wVs2jxmHkm/ZAx33xxC7VXYIrAsDjQXnnbcEfMX4yuIVcu6/MwAeK2bWr1KD bwjkfBFICjGe5MeyHEKXc1Sa7F1xECCMRkwMPc83jvpZEAc/9IiqtEphuLHiLUIUURXW Y7XthOPVYLATfICY6nzp3UMu0j/EgJf9Y6ISj30EXY6B96Pld2AbHeTjmW1p0Da4gJTs VGDHKP2btlBWp/wCMl83S7cLbpqMHQhmBvcCF5HJouQcdf/MiHvNh8vbhrUP/+0FkhQY riew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=XWZf9/UhYv4G6VmJ+Bk1hbFhCA//zACfvngw3x+8vNE=; b=pjb8GbPXuT2MGC4eSODiVHzkwPE6PcohuuiLwcqGlBNPAiD1WT/PaWmBxTjH+2igKo UYhLG2cll6O3nwRTrlSQ1nGGJ4/1MF1hPRv2WkK8vsnk8QnQ1lAvWspam7QFaye47hvG 6a1yRVTbsn8+07c4N9LYsoWplA6S+R1OqLpwcg18/usns72i3xU44uWdl0b2UwsyQEr2 Tcyjj8DGGaMUDxriaC8I7o3CbOYTkMIEj7gBaqmQ+b361SVX2KU9TXWGnQP+zXOjzzHK NEEAsARabXyAYYyiu4g0viq5q6MDcKqAjiA3iqb1OvHtSN4MxCIYiHM/WQd6IMLBlnOS RM9Q== X-Gm-Message-State: AOAM5304gGDyGABs0WtJQL1XJ3maXJzUSbpW/M6kT1XxX3jz3wqjoyQP nQZvTj05mmTcXCj8ADiThg== X-Google-Smtp-Source: ABdhPJyEDnrCikgCG/5pzbAWtxIK0kZDt3RfBnOHMMENws2kdD0Z7dEGfSow7iEjpJF959gJ511Dtw== X-Received: by 2002:a05:620a:16b6:: with SMTP id s22mr15552936qkj.422.1604343611079; Mon, 02 Nov 2020 11:00:11 -0800 (PST) Received: from moria.home.lan (c-73-219-103-14.hsd1.vt.comcast.net. [73.219.103.14]) by smtp.gmail.com with ESMTPSA id p5sm8703768qtu.13.2020.11.02.11.00.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 11:00:10 -0800 (PST) Date: Mon, 2 Nov 2020 14:00:08 -0500 From: Kent Overstreet To: "Matthew Wilcox (Oracle)" Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, hch@lst.de Subject: Re: [PATCH 04/17] mm/filemap: Support readpage splitting a page Message-ID: <20201102190008.GG2123636@moria.home.lan> References: <20201102184312.25926-1-willy@infradead.org> <20201102184312.25926-5-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201102184312.25926-5-willy@infradead.org> 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 Mon, Nov 02, 2020 at 06:42:59PM +0000, Matthew Wilcox (Oracle) wrote: > For page splitting to succeed, the thread asking to split the > page has to be the only one with a reference to the page. Calling > wait_on_page_locked() while holding a reference to the page will > effectively prevent this from happening with sufficient threads waiting > on the same page. Use put_and_wait_on_page_locked() to sleep without > holding a reference to the page, then retry the page lookup after the > page is unlocked. > > Since we now get the page lock a little earlier in filemap_update_page(), > we can eliminate a number of duplicate checks. The original intent > (commit ebded02788b5 ("avoid unnecessary calls to lock_page when waiting > for IO to complete during a read")) behind getting the page lock later > was to avoid re-locking the page after it has been brought uptodate by > another thread. We still avoid that because we go through the normal > lookup path again after the winning thread has brought the page uptodate. > > Signed-off-by: Matthew Wilcox (Oracle) > --- > mm/filemap.c | 76 ++++++++++++++++------------------------------------ > 1 file changed, 23 insertions(+), 53 deletions(-) > > diff --git a/mm/filemap.c b/mm/filemap.c > index 709774a60379..550e023abb52 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -1347,14 +1347,6 @@ static int __wait_on_page_locked_async(struct page *page, > return ret; > } > > -static int wait_on_page_locked_async(struct page *page, > - struct wait_page_queue *wait) > -{ > - if (!PageLocked(page)) > - return 0; > - return __wait_on_page_locked_async(compound_head(page), wait, false); > -} > - > /** > * put_and_wait_on_page_locked - Drop a reference and wait for it to be unlocked > * @page: The page to wait for. > @@ -2281,64 +2273,42 @@ static struct page *filemap_update_page(struct kiocb *iocb, struct file *filp, > struct inode *inode = mapping->host; > int error; > > - /* > - * See comment in do_read_cache_page on why > - * wait_on_page_locked is used to avoid unnecessarily > - * serialisations and why it's safe. > - */ > if (iocb->ki_flags & IOCB_WAITQ) { > - error = wait_on_page_locked_async(page, > - iocb->ki_waitq); > + error = lock_page_async(page, iocb->ki_waitq); > + if (error) { > + put_page(page); > + return ERR_PTR(error); > + } > } else { > - error = wait_on_page_locked_killable(page); > - } > - if (unlikely(error)) { > - put_page(page); > - return ERR_PTR(error); > + if (!trylock_page(page)) { > + put_and_wait_on_page_locked(page, TASK_KILLABLE); > + return NULL; > + } > } > - if (PageUptodate(page)) > - return page; > > + if (!page->mapping) > + goto truncated; Since we're dropping our ref to the page, it could potentially be truncated and then reused, no? So we should be checking page->mapping == mapping && page->index == index (and stashing page->index before dropping our ref, or passing it in). > + if (PageUptodate(page)) > + goto uptodate; > if (inode->i_blkbits == PAGE_SHIFT || > !mapping->a_ops->is_partially_uptodate) > - goto page_not_up_to_date; > + goto readpage; > /* pipes can't handle partially uptodate pages */ > if (unlikely(iov_iter_is_pipe(iter))) > - goto page_not_up_to_date; > - if (!trylock_page(page)) > - goto page_not_up_to_date; > - /* Did it get truncated before we got the lock? */ > - if (!page->mapping) > - goto page_not_up_to_date_locked; > + goto readpage; > if (!mapping->a_ops->is_partially_uptodate(page, > - pos & ~PAGE_MASK, count)) > - goto page_not_up_to_date_locked; > + pos & (thp_size(page) - 1), count)) > + goto readpage; > +uptodate: > unlock_page(page); > return page; > > -page_not_up_to_date: > - /* Get exclusive access to the page ... */ > - error = lock_page_for_iocb(iocb, page); > - if (unlikely(error)) { > - put_page(page); > - return ERR_PTR(error); > - } > - > -page_not_up_to_date_locked: > - /* Did it get truncated before we got the lock? */ > - if (!page->mapping) { > - unlock_page(page); > - put_page(page); > - return NULL; > - } > - > - /* Did somebody else fill it already? */ > - if (PageUptodate(page)) { > - unlock_page(page); > - return page; > - } > - > +readpage: > return filemap_read_page(iocb, filp, mapping, page); > +truncated: > + unlock_page(page); > + put_page(page); > + return NULL; > } > > static struct page *filemap_create_page(struct kiocb *iocb, > -- > 2.28.0 >