From patchwork Fri Sep 15 18:38:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13387465 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 190E5EED61A for ; Fri, 15 Sep 2023 18:39:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A3AB66B03B5; Fri, 15 Sep 2023 14:39:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C1FC6B03B6; Fri, 15 Sep 2023 14:39:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 750B26B03B7; Fri, 15 Sep 2023 14:39:08 -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 6305E6B03B5 for ; Fri, 15 Sep 2023 14:39:08 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3C0881607A8 for ; Fri, 15 Sep 2023 18:39:08 +0000 (UTC) X-FDA: 81239693976.15.B2FCF51 Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) by imf11.hostedemail.com (Postfix) with ESMTP id 925C74000D for ; Fri, 15 Sep 2023 18:39:06 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=hVgB1L3L; dmarc=none; spf=pass (imf11.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.161 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694803146; 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:in-reply-to:references:references:dkim-signature; bh=vFsIs+qRJRSVkUkhUlyZ9H4Jh3BsQexeaTYNPM7knQw=; b=jb4gVOCxHjZcqH/kMVhLF3hQI1u11YjjKjkOJDnmNp23Dx2JQPTt4vy62hazOw5IsIujnB g/jerPgd5R2AiV1+3sCECIeXHpOt74W2PZNXZuG3YNA8RhemPsMReD7qUjG9omqUReabZq 7KKdh4iZ1ElEElk4U+YVQh2jQDfpZsM= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=hVgB1L3L; dmarc=none; spf=pass (imf11.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.161 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694803146; a=rsa-sha256; cv=none; b=S/tCa/ogKP/+B9moT7jMuRJcvkYZ97zgPmRVbfcHH8olmjUfeNbCmuj4h1TPKlYGkeh5hc zLoNPwIcfAD1xTl8/4KMiM1YBJrcH4NH3CGRrklNzxDV6eBtMABWEADJ3EuYNsvtMNOdOD VbspP2LvSI5pD4S6QKKSt8PVX5cmz7U= Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4RnNJ73F62z9spF; Fri, 15 Sep 2023 20:39:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1694803143; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vFsIs+qRJRSVkUkhUlyZ9H4Jh3BsQexeaTYNPM7knQw=; b=hVgB1L3L+hfbOFs9pzt7JSZ0hL75va+f5dGTqbKq35/LHth7vuCtJyolpUYaCtZSdpXEix JXkNguxLkbblJKEYeBRWw4sugGoImquURo+WUPFARno3LgpZs20LLYLTi+D1WoWj+VLGNq uk+eLY+KxGkhRGjoDU09147fIC6cq8HBY7YH1MqbB89sTKYaddEmbOywPuL2wAm0HAG1d7 uT6Hp9zxX7OT0WFkFyl90rEJTT/PqBgWimlkD0UmghcqOvuwIJ8F+Ojn/orHfim//bDchH UtjJ+Oczct31qILqny72oU57MW1XThTi8wVKz646qcGe6HdWO6Pw8qfKMm7E8Q== From: Pankaj Raghav To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: p.raghav@samsung.com, david@fromorbit.com, da.gomez@samsung.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, willy@infradead.org, djwong@kernel.org, linux-mm@kvack.org, chandan.babu@oracle.com, mcgrof@kernel.org, gost.dev@samsung.com Subject: [RFC 04/23] filemap: set the order of the index in page_cache_delete_batch() Date: Fri, 15 Sep 2023 20:38:29 +0200 Message-Id: <20230915183848.1018717-5-kernel@pankajraghav.com> In-Reply-To: <20230915183848.1018717-1-kernel@pankajraghav.com> References: <20230915183848.1018717-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 925C74000D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: am16ridcmn3oju8wr5gbmkwc4ai11y83 X-HE-Tag: 1694803146-388863 X-HE-Meta: U2FsdGVkX18y3B8Ip7B1ZUUaqZSGSN+ygQ65Ozb+5ibrA6hhvu5PcD1OtdtH/fPsTjeQMQ6rdFPe5LgOrYEbW143aPG64s5waI8kvv4Mn3BrIpQqt4MIinwPs+6QZ/seIN2pUYUbjPvJF8aUgttfQ7EZ0xhfuSq2u06rdfFJU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Ga40o6WKy67tBHb3/BPxs4+W+8KavJLyR4pYgRJLVIoOsM34izoiUWM1bX3Az98HxE20RC9ZhGFlFevUytviijOiQyDUlu8A0arRe4Bfziy9e+mq1kitz+uzPGULv3MYcZ4= 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: From: Luis Chamberlain Similar to page_cache_delete(), call xas_set_order for non-hugetlb pages while deleting an entry from the page cache. Also put BUG_ON if the order of the folio is less than the mapping min_order. Signed-off-by: Luis Chamberlain --- mm/filemap.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/filemap.c b/mm/filemap.c index b1ce63143df5..2c47729dc8b0 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -126,6 +126,7 @@ static void page_cache_delete(struct address_space *mapping, struct folio *folio, void *shadow) { + unsigned int min_order = mapping_min_folio_order(mapping); XA_STATE(xas, &mapping->i_pages, folio->index); long nr = 1; @@ -134,6 +135,7 @@ static void page_cache_delete(struct address_space *mapping, xas_set_order(&xas, folio->index, folio_order(folio)); nr = folio_nr_pages(folio); + VM_BUG_ON_FOLIO(folio_order(folio) < min_order, folio); VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); xas_store(&xas, shadow); @@ -276,6 +278,7 @@ void filemap_remove_folio(struct folio *folio) static void page_cache_delete_batch(struct address_space *mapping, struct folio_batch *fbatch) { + unsigned int min_order = mapping_min_folio_order(mapping); XA_STATE(xas, &mapping->i_pages, fbatch->folios[0]->index); long total_pages = 0; int i = 0; @@ -304,6 +307,11 @@ static void page_cache_delete_batch(struct address_space *mapping, WARN_ON_ONCE(!folio_test_locked(folio)); + /* hugetlb pages are represented by a single entry in the xarray */ + if (!folio_test_hugetlb(folio)) { + VM_BUG_ON_FOLIO(folio_order(folio) < min_order, folio); + xas_set_order(&xas, folio->index, folio_order(folio)); + } folio->mapping = NULL; /* Leave folio->index set: truncation lookup relies on it */