From patchwork Fri Dec 1 16:10:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13476041 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 3F8AEC10DC1 for ; Fri, 1 Dec 2023 16:11:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7CE808D0073; Fri, 1 Dec 2023 11:11:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 77EBF8D0001; Fri, 1 Dec 2023 11:11:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 66D6E8D0073; Fri, 1 Dec 2023 11:11:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 56EE28D0001 for ; Fri, 1 Dec 2023 11:11:00 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E2274140247 for ; Fri, 1 Dec 2023 16:10:59 +0000 (UTC) X-FDA: 81518738238.23.CBE29AB Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf08.hostedemail.com (Postfix) with ESMTP id 0966D160016 for ; Fri, 1 Dec 2023 16:10:57 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf08.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701447058; 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; bh=bVry8kMQlne36m9EDaxPGVnL3P5GXBunzP7JiLCBMhs=; b=n8/Alu5y58b0ksOJBp4Vw64buxd8pE+T47jTvQcEF7ZCyT8ihZAoh9kTruscHNyjSKXq03 JEb76PBy/8RNhg89eAlLcDHLH/N8nNsBSO/uWt2k1gvPB2VElMoJ0Gg1FVtX/Pdp5pQjdS kXk4v/46b1wYTwOEsOx75ihAJTtqMMM= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf08.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701447058; a=rsa-sha256; cv=none; b=Uvp7Ash7UGcBE3w5WRp4EeihsvXg3Jsz1AmWc5kXVOdn9XcLC9rcGZIzBxlcSjLieNgboy iyNF5J4QAu0bfy6eKi4iITUW/BW4Fje7vgbuxGilO4f9/6nJIO7x7EcSrokTzBFgQZGf2A NjNcUIwYwjAZE3UgdQFkCTT5t1U1SJw= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 54F091007; Fri, 1 Dec 2023 08:11:43 -0800 (PST) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2E8253F6C4; Fri, 1 Dec 2023 08:10:56 -0800 (PST) From: Ryan Roberts To: "Matthew Wilcox (Oracle)" , Andrew Morton Cc: Ryan Roberts , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v1] mm/readahead: Do not allow order-1 folio Date: Fri, 1 Dec 2023 16:10:45 +0000 Message-Id: <20231201161045.3962614-1-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: bzaqh3sctkyx3o8aym18hoyasdub7bbh X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 0966D160016 X-HE-Tag: 1701447057-551215 X-HE-Meta: U2FsdGVkX1+PFtBVoO1FjmOeo7h94Ak1VvfUinnuma9ljYfpqJ6lLd+SEPQed1e6CNU+2cvA743ZlwYdINPdQRjsm9LSbHQzGhI1UbKFKWFHbo9BTUt7jWfatftgVTWUEJsLgR7h9ofQi6IEvErS+KVcb+63sJVh20i9jHfWd3rloN8JbNr0ag2axW5IZRa5NVS4YIeXXvsimrY3ksANTuQYDvm1SIbzsYlP+bMfwRQKewteuY9emZdTPsDbt2y7L8VnGRnMdDteCQ/7oJMufrm1GGY9hTl8kr02/NSZ5/4jC877bRI40pdE8xFaYKb1D85ZW1DutDcgsJ5NovFiCfDlf1zYxAnRO3L86nro9Hl+8loAs8c5o4QwI4zta/zcbFUFfOjtgunX2rmsM6o206VO9A3o+Cijt0OLAXlp9FrQvn4qvsmAaGK5YRc/f8rXqOda7yFxXWiEJg5H8ciz8rJ3dcDkg23KUpobtedjxvjOqiyrkx70hXCmqci5Ypg0m1xPLgske1nvD2J9hMqmAgDoG0zIjh9n347iElUbXFIyVeVbKW8fCxp9UZ39dUi8kV8rX2Otqny4tuAx/7vnvBu1ro5KAOYzbxCbtungEsLf8k6pAYcumheKf3dn0AI64w1lq6EqSv2yJuAzCcDMOM+f/dCHw1EIgGIsp58R1VuiX206FZm6ZluEMqdNsPf3jM0dx/iFkHs04vuEyJ4reLa/Zb4ngXmvKbYq4mvRUsbw0BCbEG4DLeRyIc3o6NYUIokuPG2MFjETXbc/T2PdRa71e+T1kb3CcPunbKH45R4+Cs7pKNRI1A2x7ESGdE1CN4mj6qKQzwMCZ9msBj9PZHTJ+spn2glNVV+fZn8wbp+vKB1NO6c2gUwMIrux/3IMKn460KBs8UmuIWdyWa5gOKZj7ChYoUoncQ9glioFFgtVTsflidytGh9Mqvfn/45zrza+bXXWGr7li/Kvzqq b09ahb3y E7Yfiv48sf8Hfla2RewEoB5xuECxPTkCWAeDBD0KSjJODfMSJDMElyw3r3u7w01+66oS10LcDVnYT/wUHLm+iatQXsY7nNmr32zKIDvm04Zk1z7WsdN/LO6lh8qWTE8qhbkSR76HToyyRV9yrw5SSvQeDqA== 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: List-Subscribe: List-Unsubscribe: The THP machinery does not support order-1 folios because it requires meta data spanning the first 3 `struct page`s. So order-2 is the smallest large folio that we can safely create. There was a theoretical bug whereby if ra->size was 2 or 3 pages (due to the device-specific bdi->ra_pages being set that way), we could end up with order = 1. Fix this by unconditionally checking if the preferred order is 1 and if so, set it to 0. Previously this was done in a few specific places, but with this refactoring it is done just once, unconditionally, at the end of the calculation. This is a theoretical bug found during review of the code; I have no evidence to suggest this manifests in the real world (I expect all device-specific ra_pages values are much bigger than 3). Signed-off-by: Ryan Roberts Reviewed-by: Matthew Wilcox (Oracle) --- mm/readahead.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) -- 2.25.1 diff --git a/mm/readahead.c b/mm/readahead.c index 6925e6959fd3..23620c57c122 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -511,16 +511,14 @@ void page_cache_ra_order(struct readahead_control *ractl, unsigned int order = new_order; /* Align with smaller pages if needed */ - if (index & ((1UL << order) - 1)) { + if (index & ((1UL << order) - 1)) order = __ffs(index); - if (order == 1) - order = 0; - } /* Don't allocate pages past EOF */ - while (index + (1UL << order) - 1 > limit) { - if (--order == 1) - order = 0; - } + while (index + (1UL << order) - 1 > limit) + order--; + /* THP machinery does not support order-1 */ + if (order == 1) + order = 0; err = ra_alloc_folio(ractl, index, mark, order, gfp); if (err) break;