From patchwork Sat Sep 30 23:10:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13405245 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73ED2E748F0 for ; Sat, 30 Sep 2023 23:10:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A5DE6B0257; Sat, 30 Sep 2023 19:10:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9561D6B0259; Sat, 30 Sep 2023 19:10:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 81E216B025C; Sat, 30 Sep 2023 19:10:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 727D46B0257 for ; Sat, 30 Sep 2023 19:10:37 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 35BC3120219 for ; Sat, 30 Sep 2023 23:10:37 +0000 (UTC) X-FDA: 81294810114.12.42111AF Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) by imf01.hostedemail.com (Postfix) with ESMTP id 76F8C40003 for ; Sat, 30 Sep 2023 23:10:35 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=McvkmNMv; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf01.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.47 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696115435; a=rsa-sha256; cv=none; b=CKub3vxq9EX+LTfnz75xEWa9H1Pnl/ijTVv+JaYCTwnCKe5AfA98TpbS05Ful449h2G4cy hHQPm+neQUH11X8UZ60lOf0Pg9Uzx8Srl8p9fdfIqgEHdkZxyr+YJYjENofsMv7YBKaSQT KJd09xthnx4tL9RysmKovCxUPIYxJM4= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=McvkmNMv; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf01.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.47 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696115435; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=LZlRJtWn09ugbDVFoE3uxLCWlbXzvShTBhbpPLHoziU=; b=eL/Uc6ldlFxmv3NsUyxWBuY1pZfCGvVFo1WCC4OXjDexHBUtxgX05z/U4x+3z7+ND5uH6G 0f6lL879xVxE0DthsTu0qRZnry8+0tHi8Jo7dgsxd3OxCPedVPZFAuT8w2L68lFrkZR0N3 v3RKbvw6aVsblSZjSD/xHBpt9wzMgVs= Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-323168869daso12440217f8f.2 for ; Sat, 30 Sep 2023 16:10:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696115433; x=1696720233; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=LZlRJtWn09ugbDVFoE3uxLCWlbXzvShTBhbpPLHoziU=; b=McvkmNMvl0lzVs8ciZ+nD8RMreYoHF6g6RBFkAoZgERfLre1e2HntKTVksorG8nN6J 6Lw/E3IK9DoNhhGX0gnXwccOxn7Qnv0CW5Fo8A/ODDxeGwapDotgqJ9+Bsji2GeLlapz 6FzB5AdkNhFqHxU6+Sjzvx7JH1zpcW8yYzrk+RYDUez88cvSgdqPGLdXW7zq3NVX/4Hk PSg28/ZiwqNODEPzlgEn2/OjW69H6mhDCvvBeYJYFA5itKlcy/St+2oSJohqKPgqL7sJ SB+ozmOdRi0QrxGKP0k0Xj95M4ICgh2xeRJGQvWniRSQQczv4v/9dT2FdsnfMn7lBB8X VMqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696115433; x=1696720233; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=LZlRJtWn09ugbDVFoE3uxLCWlbXzvShTBhbpPLHoziU=; b=c+Re2Mj/CArcs8hzVkPtR0Srgj7j40DwtCWkvSYWos53YNnOJRApNnhRB6X0/X7Xv+ usKig+oOE2GeBfzfMx1iZXvFNIwNP1lnIYCkcMMiJaL17UAiZezMKKaM+zY9WLRq9zpx t3SjubkXV9qs6q0N43qvOoHISndxqzf2i6TKbKnig3miLf0tICtWaVc5Ms3UhBS4WQ0l 4SGAmeLCxUlxnUqT1cAx3GNctecZDpyqLRFZADiZlPBuFIicK8wazEcHH5o/ZtrbALOU nDrgKtFV8gkGzHv4YAW5rlyumCKTf/pAjyMog6LFB0ILL+UOYlXZHa29emwIusNJAQ+N Pa8g== X-Gm-Message-State: AOJu0YwLWov+51kwwLxJ/BvROLVee+dp5kshNGw9fxD4SMLXr9uj5Ldi T9mPgrOJKYh11BuW6J9NSYdqN8pOsf0= X-Google-Smtp-Source: AGHT+IH4Vhgtdz4wmCzsnJGkwujfW7IvU1trkSzkeS//40APhn3o+nUZc9ZUQ4FEDWPGNV62eIJfcw== X-Received: by 2002:adf:ee48:0:b0:311:1dba:ca65 with SMTP id w8-20020adfee48000000b003111dbaca65mr7040323wro.51.1696115433225; Sat, 30 Sep 2023 16:10:33 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id c10-20020a5d4f0a000000b0031f3ad17b2csm24524471wru.52.2023.09.30.16.10.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 16:10:32 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: Matthew Wilcox , Jan Kara , Lorenzo Stoakes Subject: [PATCH] mm/filemap: clarify filemap_fault() comments for not uptodate case Date: Sun, 1 Oct 2023 00:10:29 +0100 Message-ID: <20230930231029.88196-1-lstoakes@gmail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 76F8C40003 X-Stat-Signature: 3ued853i8cqt5jjtj4m4p4q68wxeuk1z X-HE-Tag: 1696115435-582373 X-HE-Meta: U2FsdGVkX18/rh1rnRaGVzdzvNc//y7BTvMP/VYNXEd+rzBPb4EA+d8D9gXjnAzvr96kQGxm803r/H8OIpqUoBu0q/maXjwjwLufNH40GB9SFzhRijLU1zIlTcZgEEijP36h9lte+X4DGdtKOx/jwzQMdbjcnp9sv6Tn393k/pcA7POWXc7YdwNLKX6iLMjB0x2kxlb6YdifddR1dbX+VPJpTG6Ryi+8egNT7g0uLqG0GkzO+kh2pYZSyjQ7ozliRSunMkupfjgs9aTeqC1bkEoCfP3zMJluxsIUpo1psXrRGWuxUXq063OSintzFxUHbDNQ3y5RgT3XTcsTAv7AXfekK9732WRzPSG8SmhqZSoMuqwgbXK8A3t4a2VAsh82UeHzDFSUcpu4jBU3P+6Aagk8zehsQFVXZfBeHp5XZo2ZRhG5GAw1yq24ttgULbxkBqPoCEl83xZdS6Pd3Mp4Y7BdUzdfuSQ6qf8MOHYGqBElKTbLoMVAga5myIevc3IwYedS8o2oJ3mHKsmYcAB+XZNoA7ysO1FpcQIG1btv33bH7AOcCCzumSy4QZXNjwXmF+fGfdboPXAQhed5HbCaRtJPIyTZ+CEn8WKRw5AyMlk4eGr2AiGPaUt6h0WxDtbbEjI78iv6cHANA7y/7xcDmMc9XrwAO7KvU4Yx5QdxUgS7yZn1LluZDpUAaUkaCraLoMi1j/tev2qfJUneROOt2xmyuHWpf1iVhqKFxjGLPmzVxy5BDPtJQj2TU8295pHiJ9KhCZJ7BIL6k7iPAdSuXaDyrnP6gFEx0/uqOH7KT/Yp7UzEscBSC+YasXN8aWZ2aJJLqT/diYw169oNCrrz+TNE2oXnCNgw3pZzvVY9sv7SDcULorZdoTtXRDB5mFBJ7rfvjcFQdTydYaRUetIy5NvDRDd+7kwN60prXIs+/T9OGHIIX4SWrajunrFgMFRQQ9sWePY+IZb1Q1z3XtX 6hTpTFGx ZOUUVtHWDzwsP7CsVnYxBD86/nd2CfMJoFqrDXqWktFJaCkvDJ7P7m90SR3J7gSt/Wl0uYj4O4Gtm402v7AxfeNuy1iPqBxXu1E0TVKlS4CSKHp6eg81BXaRt0L1zIpuqfUFwm0/dBdp+ww8C7ucOtgImuCRF1/KIWR5lhR3J9CRFZCmZLH6JaSFvPUHpuoPZ8BW0DxT0y+k2OEG+fnx3fcCmQZGtMZ3lQA/rJI4OMwcOljmB3T62/ic9kQcEcP6XXXVK7bpYDusuBl8PoWTBTOHDetz/KuPsDnpT2XgFYXGoBMtkF5hMKkjEuJ7+wFK6aoEo5pCbnYPuIlzkBMRoNV4DXKHF5Iiel9+RzrX1N1ZBfoF/Phg4kr9UuBSTWqDr6rhza34cBOJFpNKC+H7lIUD34135GvhAUPax2lOtcNZEJCdFrdwNPiJgvMfRDtIIbFQVcGVYVXYIWjEsZQXWnxqkIWUjEVcZOeiG X-Bogosity: Ham, tests=bogofilter, spamicity=0.000019, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The existing comments in filemap_fault() suggest that, after either a minor fault has occurred and filemap_get_folio() found a folio in the page cache, or a major fault arose and __filemap_get_folio(FGP_CREATE...) did the job (having relied on do_sync_mmap_readahead() or filemap_read_folio() to read in the folio), the only possible reason it could not be uptodate is because of an error. This is not so, as if, for instance, the fault occurred within a VMA which had the VM_RAND_READ flag set (via madvise() with the MADV_RANDOM flag specified), this would cause even synchronous readahead to fail to read in the folio. I confirmed this by dropping page caches and faulting in memory madvise()'d this way, observing that this code path was reached on each occasion. Clarify the comments to include this case, and additionally update the comment recently added around the invalidate lock logic to make it clear the comment explicitly refers to the minor fault case. In addition, while we're here, refer to folios rather than pages. Signed-off-by: Lorenzo Stoakes Signed-off-by: Lorenzo Stoakes Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara --- mm/filemap.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index d285ec5f9162..959694a2ade7 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3308,21 +3308,28 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) VM_BUG_ON_FOLIO(!folio_contains(folio, index), folio); /* - * We have a locked page in the page cache, now we need to check - * that it's up-to-date. If not, it is going to be due to an error. + * We have a locked folio in the page cache, now we need to check + * that it's up-to-date. If not, it is going to be due to an error, + * or because readahead was otherwise unable to retrieve it. */ if (unlikely(!folio_test_uptodate(folio))) { /* - * The page was in cache and uptodate and now it is not. - * Strange but possible since we didn't hold the page lock all - * the time. Let's drop everything get the invalidate lock and - * try again. + * If the invalidate lock is not held, the folio was in cache and + * uptodate and now it is not. Strange but possible since we + * didn't hold the page lock all the time. Let's drop everything, + * get the invalidate lock and try again. */ if (!mapping_locked) { folio_unlock(folio); folio_put(folio); goto retry_find; } + + /* + * OK, the folio is really not uptodate. This can be because the + * VMA has the VM_RAND_READ flag set, or because an error + * arose. Let's read it in directly. + */ goto page_not_uptodate; }