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=-6.5 required=3.0 tests=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 B8AC8C433E0 for ; Sat, 23 May 2020 08:30:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2ECC12071C for ; Sat, 23 May 2020 08:30:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2ECC12071C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sina.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 69EFC80008; Sat, 23 May 2020 04:30:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6281B80007; Sat, 23 May 2020 04:30:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C8B580008; Sat, 23 May 2020 04:30:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0115.hostedemail.com [216.40.44.115]) by kanga.kvack.org (Postfix) with ESMTP id 3133880007 for ; Sat, 23 May 2020 04:30:11 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id DDC9E824556B for ; Sat, 23 May 2020 08:30:10 +0000 (UTC) X-FDA: 76847311380.17.pets06_58a2a0930cc08 X-HE-Tag: pets06_58a2a0930cc08 X-Filterd-Recvd-Size: 5748 Received: from r3-20.sinamail.sina.com.cn (r3-20.sinamail.sina.com.cn [202.108.3.20]) by imf39.hostedemail.com (Postfix) with SMTP for ; Sat, 23 May 2020 08:30:08 +0000 (UTC) Received: from unknown (HELO localhost.localdomain)([123.123.26.246]) by sina.com with ESMTP id 5EC8DF050002753D; Sat, 23 May 2020 16:29:58 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com X-SMAIL-MID: 98829415073736 From: Hillf Danton To: Jens Axboe , io-uring@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2 03/11] mm: add support for async page locking Date: Sat, 23 May 2020 16:29:44 +0800 Message-Id: <20200523082944.12860-1-hdanton@sina.com> In-Reply-To: <43ad2c54-1e42-35ed-26be-6535cb0541b6@kernel.dk> References: <20200522202311.10959-1-axboe@kernel.dk> <20200522202311.10959-4-axboe@kernel.dk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 Fri, 22 May 2020 14:57:20 -0600 Jens Axboe wrote: >=20 > I did some reshuffling of this patch before sending it out, and > I ended up sending a previous version. Please look at this one instead. >=20 > commit d8f0a0bfc4a0742cb461287561b956bc56e90976 > Author: Jens Axboe > Date: Fri May 22 09:12:09 2020 -0600 >=20 > mm: add support for async page locking > =20 > Normally waiting for a page to become unlocked, or locking the page= , > requires waiting for IO to complete. Add support for lock_page_asyn= c() > and wait_on_page_locked_async(), which are callback based instead. = This > allows a caller to get notified when a page becomes unlocked, rathe= r > than wait for it. > =20 > We use the iocb->private field to pass in this necessary data for t= his > to happen. struct wait_page_key is made public, and we define struc= t > wait_page_async as the interface between the caller and the core. > =20 > Signed-off-by: Jens Axboe >=20 > diff --git a/include/linux/fs.h b/include/linux/fs.h > index 7e84d823c6a8..82b989695ab9 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -314,6 +314,8 @@ enum rw_hint { > #define IOCB_SYNC (1 << 5) > #define IOCB_WRITE (1 << 6) > #define IOCB_NOWAIT (1 << 7) > +/* iocb->private holds wait_page_async struct */ > +#define IOCB_WAITQ (1 << 8) > =20 > struct kiocb { > struct file *ki_filp; > diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h > index a8f7bd8ea1c6..e260bcd071e4 100644 > --- a/include/linux/pagemap.h > +++ b/include/linux/pagemap.h > @@ -456,8 +456,21 @@ static inline pgoff_t linear_page_index(struct vm_= area_struct *vma, > return pgoff; > } > =20 > +/* This has the same layout as wait_bit_key - see fs/cachefiles/rdwr.c= */ > +struct wait_page_key { > + struct page *page; > + int bit_nr; > + int page_match; > +}; > + > +struct wait_page_async { > + struct wait_queue_entry wait; > + struct wait_page_key key; > +}; > + > extern void __lock_page(struct page *page); > extern int __lock_page_killable(struct page *page); > +extern int __lock_page_async(struct page *page, struct wait_page_async= *wait); > extern int __lock_page_or_retry(struct page *page, struct mm_struct *m= m, > unsigned int flags); > extern void unlock_page(struct page *page); > @@ -494,6 +507,14 @@ static inline int lock_page_killable(struct page *= page) > return 0; > } > =20 Feel free to add doc to avoid toes curling... > +static inline int lock_page_async(struct page *page, > + struct wait_page_async *wait) > +{ > + if (!trylock_page(page)) > + return __lock_page_async(page, wait); > + return 0; > +} > + > /* > * lock_page_or_retry - Lock the page, unless this would block and the > * caller indicated that it can handle a retry. > diff --git a/mm/filemap.c b/mm/filemap.c > index 80747f1377d5..ebee7350ea3b 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -990,13 +990,6 @@ void __init pagecache_init(void) > page_writeback_init(); > } > =20 > -/* This has the same layout as wait_bit_key - see fs/cachefiles/rdwr.c= */ > -struct wait_page_key { > - struct page *page; > - int bit_nr; > - int page_match; > -}; > - > struct wait_page_queue { > struct page *page; > int bit_nr; > @@ -1210,6 +1203,33 @@ int wait_on_page_bit_killable(struct page *page,= int bit_nr) > } > EXPORT_SYMBOL(wait_on_page_bit_killable); > =20 > +static int __wait_on_page_locked_async(struct page *page, > + struct wait_page_async *wait) > +{ > + struct wait_queue_head *q =3D page_waitqueue(page); > + int ret =3D 0; > + > + wait->key.page =3D page; > + wait->key.bit_nr =3D PG_locked; > + > + spin_lock_irq(&q->lock); > + if (PageLocked(page)) { > + __add_wait_queue_entry_tail(q, &wait->wait); > + SetPageWaiters(page); > + ret =3D -EIOCBQUEUED; > + } > + spin_unlock_irq(&q->lock); > + return ret; > +} > + > +static int wait_on_page_locked_async(struct page *page, > + struct wait_page_async *wait) > +{ > + if (!PageLocked(page)) > + return 0; > + return __wait_on_page_locked_async(compound_head(page), wait); > +} > + > /** > * put_and_wait_on_page_locked - Drop a reference and wait for it to b= e unlocked > * @page: The page to wait for. > @@ -1372,6 +1392,11 @@ int __lock_page_killable(struct page *__page) > } > EXPORT_SYMBOL_GPL(__lock_page_killable); > =20 > +int __lock_page_async(struct page *page, struct wait_page_async *wait) > +{ > + return wait_on_page_locked_async(page, wait); The slow path seems harder to read than the fast one. And one of the qui= ck questions rises: is it a locked page after return?