From patchwork Sat Oct 17 17:55:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 11842913 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 838E417C9 for ; Sat, 17 Oct 2020 17:55:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CD7262076D for ; Sat, 17 Oct 2020 17:55:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20150623.gappssmtp.com header.i=@kernel-dk.20150623.gappssmtp.com header.b="ZGXMa4ZQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CD7262076D 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 B080E900002; Sat, 17 Oct 2020 13:55:52 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AE9356B0062; Sat, 17 Oct 2020 13:55:52 -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 9CD16900002; Sat, 17 Oct 2020 13:55:52 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0069.hostedemail.com [216.40.44.69]) by kanga.kvack.org (Postfix) with ESMTP id 6F5216B005D for ; Sat, 17 Oct 2020 13:55:52 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 01CBE180AD802 for ; Sat, 17 Oct 2020 17:55:52 +0000 (UTC) X-FDA: 77382170544.25.ducks04_2d12d9227227 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id D6B6D1804E3A0 for ; Sat, 17 Oct 2020 17:55:51 +0000 (UTC) X-Spam-Summary: 1,0,0,b519388f1f206646,d41d8cd98f00b204,axboe@kernel.dk,,RULES_HIT:41:152:355:379:800:854:960:973:988:989:1260:1261:1277:1311:1313:1314:1345:1381:1431:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2194:2198:2199:2200:2393:2559:2562:3138:3139:3140:3141:3142:3352:3865:3866:3867:3868:3870:3871:3874:4250:4321:5007:6261:6653:7514:7652:7875:8634:10004:10400:11026:11232:11658:11914:12043:12048:12295:12297:12438:12517:12519:12555:12679:12760:12895:13069:13221:13229:13311:13357:13869:14096:14097:14181:14394:14721:21080:21444:21451:21627:21966:21990:30005:30054,0,RBL:209.85.210.194:@kernel.dk:.lbl8.mailshell.net-66.100.201.201 62.2.0.100;04y8eq94c8sktj83a1osw1oauwac5ypqtgsu83ih4cikbrquggdaohgrq9y9xtw.4pk3r4dhzwzgrhouti5397kgb45r91si9bres3ah3bxt7xm9zi69jwfkdaw7awk.s-lbl8.mailshell.net-223.238.255.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:26,LUA_SUMMARY:none X-HE-Tag: ducks04_2d12d9227227 X-Filterd-Recvd-Size: 4420 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Sat, 17 Oct 2020 17:55:51 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id e15so200439pfh.6 for ; Sat, 17 Oct 2020 10:55:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:subject:to:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=YOcBc34pFiGK6iPopvJW1lXXS0DNqwy+iCnh3nw74aA=; b=ZGXMa4ZQyUBHkbPNg5ERnCJLK+H4+bgCEAiKDfV4C6ToJPQVmc1HIAMeikZ5pdZ/N5 MbsOhI3SlePzc5ik+o3WBmbnk0quVeibFI/+NqgsSCLd6y+z1Yd74ApTMK/roeMjkcKZ 3AedmCXqDCbDx1JG8xzIEgNeJXbjHeArT/HgB6xXNyXw+VE0ZuY1tvc+/8Rpcpapa999 XZtGUC2XyzGnPe7h2KXfJisHPV2ryhL2QaatfwxlYBi5pUOntpycuz3FH0hDKY+mQARq mULpxvG9mlwO3NdU2pv2o10RxRBxWjdujrHuFYgrcrIYmqtWCcGukxujMp/3e06KDxqZ 518A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=YOcBc34pFiGK6iPopvJW1lXXS0DNqwy+iCnh3nw74aA=; b=XNc7JOYt2svtwrabbiypubVpZLfyJZTZ65c8gL0Sis3Mh8a+r1RoNWYMks4MNvHpCE pMN+ebQdmwpsF9+Oho0oxBLhTe+T9G5EOIH4hxDUmHVLulhZzJVJLlwFp1ceqbKlpcC5 P01O1dSNLei0ZX73PNd/FJXz8hMIkuyy4MGjabZYmwzw2UihkM+tC8PJHS/7t3OMujKp fZWaXr5aXMyV/4/j23M7N1891VkGEexzl+xN/CkKr5NFZTnM9861uDbtUXRtqA764516 U5/KWyrbCr4DnjJCML1rX9N2ZQEYtaCkcGSH051dfEWMqy5YWZq3C/bJl3q1bUHPmFOQ CqwQ== X-Gm-Message-State: AOAM532wReUSVHEEtji50TrjAgpi9lXg863z6bDTZbTt8jeA7KQl4JJB g/AFpr7Mu2S9frsW3EaJHuTF5w== X-Google-Smtp-Source: ABdhPJxzWRGeGHdFpNhfitekHRvZGzQLlwCje5XszDfwWbgZByV9po8CZTXLR0QaltrYZfLHB71JKg== X-Received: by 2002:a63:e61:: with SMTP id 33mr7708325pgo.394.1602957350250; Sat, 17 Oct 2020 10:55:50 -0700 (PDT) Received: from [192.168.1.134] ([66.219.217.173]) by smtp.gmail.com with ESMTPSA id fh19sm3467129pjb.38.2020.10.17.10.55.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 17 Oct 2020 10:55:49 -0700 (PDT) From: Jens Axboe Subject: [PATCH v2] mm: mark async iocb read as NOWAIT once some data has been, copied To: linux-mm , Andrew Morton , Johannes Weiner , Kent Overstreet , Matthew Wilcox Message-ID: <1fb77079-eda6-3383-19a8-f1f32fd82808@kernel.dk> Date: Sat, 17 Oct 2020 11:55:48 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 Content-Language: en-US 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: Once we've copied some data for an iocb that is marked with IOCB_WAITQ, we should no longer attempt to async lock a new page. Instead make sure we return the copied amount, and let the caller retry, instead of returning -EIOCBQUEUED for a new page. This should only be possible with read-ahead disabled on the below device, and multiple threads racing on the same file. Haven't been able to reproduce on anything else. Cc: stable@vger.kernel.org # v5.9 Fixes: 1a0a7853b901 ("mm: support async buffered reads in generic_file_buffered_read()") Reported-by: Kent Overstreet Signed-off-by: Jens Axboe --- V2 - Place the NOWAIT marker when we increment 'written' (Willy) mm/filemap.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/filemap.c b/mm/filemap.c index 1a6beaf69f49..508048bfd2a5 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2329,6 +2329,15 @@ ssize_t generic_file_buffered_read(struct kiocb *iocb, put_page(page); written += ret; + + /* + * If we've already successfully copied some data, then we + * can no longer safely return -EIOCBQUEUED. Hence mark + * an async read NOWAIT at that point. + */ + if (iocb->ki_flags & IOCB_WAITQ) + iocb->ki_flags |= IOCB_NOWAIT; + if (!iov_iter_count(iter)) goto out; if (ret < nr) {