From patchwork Mon Feb 8 22:18:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 12076605 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=-11.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 7EBF6C433E0 for ; Mon, 8 Feb 2021 22:18:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AEC5C64E9A for ; Mon, 8 Feb 2021 22:18:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AEC5C64E9A 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 F015D6B0005; Mon, 8 Feb 2021 17:18:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EB25A6B006C; Mon, 8 Feb 2021 17:18:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D52166B006E; Mon, 8 Feb 2021 17:18:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0031.hostedemail.com [216.40.44.31]) by kanga.kvack.org (Postfix) with ESMTP id BC8946B0005 for ; Mon, 8 Feb 2021 17:18:37 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 80D1818021C89 for ; Mon, 8 Feb 2021 22:18:37 +0000 (UTC) X-FDA: 77796515874.22.bells90_1a002e827602 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 56FD9181CE5B0 for ; Mon, 8 Feb 2021 22:18:37 +0000 (UTC) X-HE-Tag: bells90_1a002e827602 X-Filterd-Recvd-Size: 4269 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Mon, 8 Feb 2021 22:18:36 +0000 (UTC) Received: by mail-pl1-f171.google.com with SMTP id u11so8587819plg.13 for ; Mon, 08 Feb 2021 14:18:36 -0800 (PST) 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:mime-version :content-transfer-encoding; bh=d+p4V3Uds2r1nqxPoujfGyPXKob2/IV0lWtEI4+ZvEg=; b=MCUOts+F6kQY/nu6UyvRrlXSoyvu5xOrN2/S+S9DWUJuNC6onmSzj1BmOb7N2a8bSU hZdJ68ZQ8XXn74dwvSh+dF9j6GE9YrSGhLk47gTGhv6H4gsmfLw3spc3j0a3144mAKyW pMWT0uhDrLwukYwKMCFV7BXkvdyL+qV8Ns00rCppn4ctjDaHE4NkgqOwNH9NS265iVxb j0WtWGZnJ6lNGoXYyC3Zp5tkEwVTA+b+yQVzFAZiw0AIN5QJhLymyYeli85lm+GdxThI hOJy0fcjiftVzMApESZ8penZ/O7w6r8c0SAtyr7uea8xRk2JscS0ZKa1LsuD6Uv5LoX1 ucYw== 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:mime-version :content-transfer-encoding; bh=d+p4V3Uds2r1nqxPoujfGyPXKob2/IV0lWtEI4+ZvEg=; b=k+h0D4pO+hodX/PKMCbhXWg/wGbDFEnY3lfq/peTBShC6WDYLIGJZdE9bGqHy6AFHf sHh0py0aN07FfhG6lVVt2eynWXp/K6oVqHdC75rF3m1EMT9lbfhyFAoo/cvdQ3O7EyQe CatVFaLYuOVf+OUHr62YW+Xli+B8LP/LQDp4frmkYlEkdCkapc9gzeMyVIQel/93jxJv YT51Vvcu5jkzaz5Hsi/FgJEXUuHuDwqRARx0enVQYnpFEkt8hCVKcBNTpeGsMwkkIKcZ +7Nxapi7Y5EcwWdNelts/KadA9XAkb9sg6niOmGzs46BuMNjLjZ88XX9q3TXxJY6Fn5g wKnQ== X-Gm-Message-State: AOAM530QFwoqfPvl84IL0UqF2S/iZK53H2ZfJ4JpGR1OlLk/d60Ic+fU LNAMB234JdjRrhwzbZXcGvLoWg== X-Google-Smtp-Source: ABdhPJztojDx2x8WNq5jT6fElvzP7MG7VRij6fFOjelaAvaWg9vgyxKKNiezcD5sKJ+bJGAjSNVdHA== X-Received: by 2002:a17:90a:d34b:: with SMTP id i11mr867673pjx.235.1612822715591; Mon, 08 Feb 2021 14:18:35 -0800 (PST) Received: from localhost.localdomain ([2600:380:4a36:d38a:f60:a5d4:5474:9bbc]) by smtp.gmail.com with ESMTPSA id o10sm19324472pfp.87.2021.02.08.14.18.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 14:18:35 -0800 (PST) From: Jens Axboe To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: hch@infradead.org, akpm@linux-foundation.org Subject: [PATCHSET 0/3] Improve IOCB_NOWAIT O_DIRECT Date: Mon, 8 Feb 2021 15:18:26 -0700 Message-Id: <20210208221829.17247-1-axboe@kernel.dk> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000038, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi, Ran into an issue with IOCB_NOWAIT and O_DIRECT, which causes a rather serious performance issue. If IOCB_NOWAIT is set, the generic/iomap iterators check for page cache presence in the given range, and return -EAGAIN if any is there. This is rather simplistic and looks like something that was never really finished. For !IOCB_NOWAIT, we simply call filemap_write_and_wait_range() to issue (if any) and wait on the range. The fact that we have page cache entries for this range does not mean that we cannot safely do O_DIRECT IO to/from it. This series adds filemap_range_needs_writeback(), which checks if we have pages in the range that do require us to call filemap_write_and_wait_range(). If we don't, then we can proceed just fine with IOCB_NOWAIT. The problem manifested itself in a production environment, where someone is doing O_DIRECT on a raw block device. Due to other circumstances, blkid was triggered on this device periodically, and blkid very helpfully does a number of page cache reads on the device. Now the mapping has page cache entries, and performance falls to pieces because we can no longer reliably do IOCB_NOWAIT O_DIRECT. Patch 1 adds the helper, patch 2 uses it for the generic iterators, and patch 3 applies the same to the iomap direct-io code. fs/iomap/direct-io.c | 10 ++++----- include/linux/fs.h | 2 ++ mm/filemap.c | 52 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 56 insertions(+), 8 deletions(-)