From mboxrd@z Thu Jan 1 00:00:00 1970 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 0A92DC6FA83 for ; Fri, 2 Sep 2022 19:47:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 78618800EB; Fri, 2 Sep 2022 15:47:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6BD18800F1; Fri, 2 Sep 2022 15:47:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4A03D800F3; Fri, 2 Sep 2022 15:47:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 13FCF800F1 for ; Fri, 2 Sep 2022 15:47:01 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E4D5E120B36 for ; Fri, 2 Sep 2022 19:47:00 +0000 (UTC) X-FDA: 79868178600.11.9734A06 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf16.hostedemail.com (Postfix) with ESMTP id 902AB18004E for ; Fri, 2 Sep 2022 19:47:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=KHdw5Sh1ebNYRtUN9/JSFbx5sWfjgmqbdXN+cIr0Ikw=; b=ex27bDTNAsdr2lYDRVKroPTZKz Bj8I2yfEzR7FrOstpA18q3Wm8NvGiSQFQCByCeoqYe2kpu1KgwmVH9G0jg71Xcdlnm/1R4eYWlafA uyAakz4DiNG2ZzK/j04ThWt1WnTPFx9BIMfzB4OFZgjHnnbbuSgx48dGV590qlyQNFeLDzxNMCdE8 3q+3DLZZO5wjKluQq9I/291snmbUU1s0znYDJsm7HQhGoo6wqsp7lQEB5H+hdPi7BWYR9FF+dH+TL yi7QYtNRAmD61/3iq90ZINpENcOjTSsrUIEPnMi5X+oZ6alPjyDA5Lc5qPUPAUoOE+G5yBgR+qQTQ LJYHTwfQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oUCd2-007Idl-Na; Fri, 02 Sep 2022 19:47:00 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH v2 28/57] shmem: Convert shmem_fallocate() to use a folio Date: Fri, 2 Sep 2022 20:46:24 +0100 Message-Id: <20220902194653.1739778-29-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220902194653.1739778-1-willy@infradead.org> References: <20220902194653.1739778-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662148020; 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=KHdw5Sh1ebNYRtUN9/JSFbx5sWfjgmqbdXN+cIr0Ikw=; b=Ck8G348qCsH22CQwJCfGiCi0facgHW2EQrsczBMb0CGY9mboqOsMrU28LLNDlITA22AiMf iYB1M4vJ/z8ZsG+KtPI1cQcJnM/opYnWap48H1YoXPkRL2gAqIbJXvuLEwm1RnDNhtyj5w PeWb5XeJi86rzqR021rplEqs5s+CUmc= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=ex27bDTN; dmarc=none; spf=none (imf16.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662148020; a=rsa-sha256; cv=none; b=GcUk0dYxiN2v5594k/6kNt6oTcKXJtoMwHAH2XWaZ9Y7Ic/dGTyewKyv2QSf1FXmk1fIIH 0MhwrlXxHmv+CW4X7LPR2jnNUnANHwt2GPgTqPBGFfdcBLx7X3ArETWHFlqoVSZRFJaYOc JwjhHy4TG7GTY7pylIJGF0LE6vAPLLI= X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 902AB18004E Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=ex27bDTN; dmarc=none; spf=none (imf16.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-Rspam-User: X-Stat-Signature: fxfumhsqg1du16jisheims1nsfxwg3o7 X-HE-Tag: 1662148020-80621 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: Call shmem_get_folio() and use the folio APIs instead of the page APIs. Saves several calls to compound_head() and removes assumptions about the size of a large folio. Signed-off-by: Matthew Wilcox (Oracle) --- mm/shmem.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 214887812adb..f251b026e83f 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2786,7 +2786,7 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset, info->fallocend = end; for (index = start; index < end; ) { - struct page *page; + struct folio *folio; /* * Good, the fallocate(2) manpage permits EINTR: we may have @@ -2797,10 +2797,11 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset, else if (shmem_falloc.nr_unswapped > shmem_falloc.nr_falloced) error = -ENOMEM; else - error = shmem_getpage(inode, index, &page, SGP_FALLOC); + error = shmem_get_folio(inode, index, &folio, + SGP_FALLOC); if (error) { info->fallocend = undo_fallocend; - /* Remove the !PageUptodate pages we added */ + /* Remove the !uptodate folios we added */ if (index > start) { shmem_undo_range(inode, (loff_t)start << PAGE_SHIFT, @@ -2809,37 +2810,34 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset, goto undone; } - index++; /* * Here is a more important optimization than it appears: - * a second SGP_FALLOC on the same huge page will clear it, - * making it PageUptodate and un-undoable if we fail later. + * a second SGP_FALLOC on the same large folio will clear it, + * making it uptodate and un-undoable if we fail later. */ - if (PageTransCompound(page)) { - index = round_up(index, HPAGE_PMD_NR); - /* Beware 32-bit wraparound */ - if (!index) - index--; - } + index = folio_next_index(folio); + /* Beware 32-bit wraparound */ + if (!index) + index--; /* * Inform shmem_writepage() how far we have reached. * No need for lock or barrier: we have the page lock. */ - if (!PageUptodate(page)) + if (!folio_test_uptodate(folio)) shmem_falloc.nr_falloced += index - shmem_falloc.next; shmem_falloc.next = index; /* - * If !PageUptodate, leave it that way so that freeable pages + * If !uptodate, leave it that way so that freeable folios * can be recognized if we need to rollback on error later. - * But set_page_dirty so that memory pressure will swap rather - * than free the pages we are allocating (and SGP_CACHE pages + * But mark it dirty so that memory pressure will swap rather + * than free the folios we are allocating (and SGP_CACHE folios * might still be clean: we now need to mark those dirty too). */ - set_page_dirty(page); - unlock_page(page); - put_page(page); + folio_mark_dirty(folio); + folio_unlock(folio); + folio_put(folio); cond_resched(); } -- 2.35.1