From patchwork Fri May 22 20:23:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 11566129 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 425FD912 for ; Fri, 22 May 2020 20:23:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0FE2B20723 for ; Fri, 22 May 2020 20:23:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel-dk.20150623.gappssmtp.com header.i=@kernel-dk.20150623.gappssmtp.com header.b="M62vZgt7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0FE2B20723 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E1CFF8000B; Fri, 22 May 2020 16:23:23 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DA1CD80007; Fri, 22 May 2020 16:23:23 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C91D98000B; Fri, 22 May 2020 16:23:23 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0187.hostedemail.com [216.40.44.187]) by kanga.kvack.org (Postfix) with ESMTP id AFDC880007 for ; Fri, 22 May 2020 16:23:23 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 7F5EA2C94 for ; Fri, 22 May 2020 20:23:23 +0000 (UTC) X-FDA: 76845479886.21.uncle52_77aa5117f1d X-Spam-Summary: 2,0,0,fce4402cb7dd0e72,d41d8cd98f00b204,axboe@kernel.dk,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1535:1544:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3353:3865:3867:3868:3870:3871:3872:3874:4118:4250:4321:4605:5007:6261:6653:7875:8634:8957:9592:10004:11026:11473:11658:11914:12043:12291:12296:12297:12438:12517:12519:12555:12683:12895:12986:13138:13231:13894:14096:14181:14394:14721:21067:21080:21324:21444:21451:21627:21796:21990:30036:30054,0,RBL:209.85.214.195:@kernel.dk:.lbl8.mailshell.net-66.100.201.201 62.2.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: uncle52_77aa5117f1d X-Filterd-Recvd-Size: 7210 Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Fri, 22 May 2020 20:23:23 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id m7so4827820plt.5 for ; Fri, 22 May 2020 13:23:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=E5DEkxIJkQWsUJs0qbxunHfP/DfTSgAGYfxGVJ+umf8=; b=M62vZgt7Z81D/uiR+GCOQQB3NqfNockOsJ/6frjYkhnWPNPJJZTcIPvOcq1e+OIlDL A7Uaby6+5+yzzVPToxB0CyZzT5Jw1ob2YGIEZqHXjXgKhQGh5U1q8a2A9pPN0Cj5rGty y3qU1pliP06kZl8w8cUT7dvfF3ahpHIQJ7dNrjzqotZO6ri1R9SVfzOckoAebjqf/Twx j91VjdHpplZRnRM3EsEkFM0HXA1ovT2U9jd3h2He485CnEKSF5f+kF6cuKM/q9U1z8MV UmuaS9qHJ8zAaJnmJl/2IfxSZvQnvGic/q3WR7JBZtt23tccTdCAAtq96+R89GOMjP2k aoYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=E5DEkxIJkQWsUJs0qbxunHfP/DfTSgAGYfxGVJ+umf8=; b=PJfEIKt8ctMTMQskhxRaM6ZUs5YzEaPne+GFgivtf3p84V8OM+XJS5mcJUWG5nHF0x 9cJs6que5FnivicbxB0u4fu9SWVJXhr1PK9cu119NonLKgV78zt3QoEYFLODUpr+vbS6 L+Y0NjHA3VMtRzBw3qxMQK5deXZhlNT02zOHeboSePg1M3oggBCeHPa9SHiIaPPKxghw A0jqhGZZOYqtdKPZjqsCnxUIp8+zQVUD4kxCrsOLQX8pQp2Z6KDkWGVgaIPapXjbq0mZ F7X9mUT18S88nRFoVSXcxoB7vPWSj4mFTiNqCfMDZn2dlXbSGgFSSdAvhunSk2lLUigP pTZw== X-Gm-Message-State: AOAM532d9g7JhF8dmM1Vl485mAQCuPSldLTs2bwzmWPHYsxqd/Vm9ixd L0LrT8ArONWYLZYtXlbMzeLysA== X-Google-Smtp-Source: ABdhPJxj+N3pVChoXFbbBEseusfqTToenJpOK897u7XCplyacE6niX5gkU9YVqdofi7hj7Jnx22hMA== X-Received: by 2002:a17:90a:4809:: with SMTP id a9mr6555363pjh.196.1590179002017; Fri, 22 May 2020 13:23:22 -0700 (PDT) Received: from x1.lan ([2605:e000:100e:8c61:e0db:da55:b0a4:601]) by smtp.gmail.com with ESMTPSA id e19sm7295561pfn.17.2020.05.22.13.23.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 13:23:21 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Jens Axboe Subject: [PATCH 03/11] mm: add support for async page locking Date: Fri, 22 May 2020 14:23:03 -0600 Message-Id: <20200522202311.10959-4-axboe@kernel.dk> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200522202311.10959-1-axboe@kernel.dk> References: <20200522202311.10959-1-axboe@kernel.dk> MIME-Version: 1.0 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: Normally waiting for a page to become unlocked, or locking the page, requires waiting for IO to complete. Add support for lock_page_async() and wait_on_page_locked_async(), which are callback based instead. This allows a caller to get notified when a page becomes unlocked, rather than wait for it. We use the iocb->private field to pass in this necessary data for this to happen. struct wait_page_key is made public, and we define struct wait_page_async as the interface between the caller and the core. Signed-off-by: Jens Axboe --- include/linux/fs.h | 2 ++ include/linux/pagemap.h | 22 +++++++++++++++++++++ mm/filemap.c | 44 ++++++++++++++++++++++++++++++++++------- 3 files changed, 61 insertions(+), 7 deletions(-) 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) struct kiocb { struct file *ki_filp; diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index a8f7bd8ea1c6..39af9f890866 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; } +/* 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 *mm, unsigned int flags); extern void unlock_page(struct page *page); @@ -494,6 +507,15 @@ static inline int lock_page_killable(struct page *page) return 0; } +static inline int lock_page_async(struct page *page, + struct wait_page_async *wait) +{ + int ret; + if (!trylock_page(page)) + ret = __lock_page_async(page, wait); + return ret; +} + /* * 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..0bc77f431bea 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -990,13 +990,6 @@ void __init pagecache_init(void) page_writeback_init(); } -/* 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,38 @@ int wait_on_page_bit_killable(struct page *page, int bit_nr) } EXPORT_SYMBOL(wait_on_page_bit_killable); +static int __wait_on_page_locked_async(struct page *page, + struct wait_page_async *wait) +{ + struct wait_queue_head *q = page_waitqueue(page); + int ret = 0; + + wait->key.page = page; + wait->key.bit_nr = PG_locked; + + spin_lock_irq(&q->lock); + if (PageLocked(page)) { + __add_wait_queue_entry_tail(q, &wait->wait); + SetPageWaiters(page); + ret = -EIOCBQUEUED; + } + spin_unlock_irq(&q->lock); + return ret; +} + +static int wait_on_page_locked_async(struct page *page, + struct wait_page_async *wait) +{ + int ret; + if (!PageLocked(page)) + return 0; + ret = __wait_on_page_locked_async(compound_head(page), wait); + if (ret == -EIOCBQUEUED && !PageLocked(page)) + ret = 0; + return ret; +} + + /** * put_and_wait_on_page_locked - Drop a reference and wait for it to be unlocked * @page: The page to wait for. @@ -1372,6 +1397,11 @@ int __lock_page_killable(struct page *__page) } EXPORT_SYMBOL_GPL(__lock_page_killable); +int __lock_page_async(struct page *page, struct wait_page_async *wait) +{ + return wait_on_page_locked_async(page, wait); +} + /* * Return values: * 1 - page is locked; mmap_sem is still held.