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 82563C25B0C for ; Mon, 8 Aug 2022 19:36:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 56F888E0003; Mon, 8 Aug 2022 15:36:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4814994000C; Mon, 8 Aug 2022 15:36:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2AD2D8E000C; Mon, 8 Aug 2022 15:36:02 -0400 (EDT) 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 106AB8E0003 for ; Mon, 8 Aug 2022 15:36:02 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E81BAC0126 for ; Mon, 8 Aug 2022 19:36:01 +0000 (UTC) X-FDA: 79777430922.02.DD5AEF2 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf10.hostedemail.com (Postfix) with ESMTP id 9E08EC015E for ; Mon, 8 Aug 2022 19:36:01 +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=D77zS7INJVOvYz/CP+vtDGyyfpLH7LZUg0F9gzXZvLY=; b=s7rZApVf2Kbm/Lnu0ELGxlHGmt RXHe5vgdsozolMWSknEbAmtJhbUndGxycNtgBYiL2s8PY6UvR2YlxTCTCuCOWdxdjbE7c+dZhXA6p UApJEsNhewFlNfBBNOZBC33TiYPWFeRuREG40GqM/3YU3OoQs6CU5H9eZQfLe8UOWx9IUAst44J4z 3NbYURaGxSqxQO73CFeG6IwzcS5O+t2FpQd1LaIYl3Gkwjxlzc7TVtpBU+mxymHGCKVjOPDvJWgmY Y2J1QPKOgv75xtjPFUa5xli3vwIWyZ7cIc4W4fIeG/NecPY15tL4oqPp1Ruaw+x2uUHLOmrdJFQJW QRrpVpBw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oL8X6-00EAy2-U5; Mon, 08 Aug 2022 19:35:25 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , hughd@google.com Subject: [PATCH 31/59] shmem: Convert shmem_fallocate() to use a folio Date: Mon, 8 Aug 2022 20:33:59 +0100 Message-Id: <20220808193430.3378317-32-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220808193430.3378317-1-willy@infradead.org> References: <20220808193430.3378317-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=s7rZApVf; spf=none (imf10.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659987361; a=rsa-sha256; cv=none; b=WhINbTeMG+tGQ8xOMe0pgjdE9jVhSMP/K7WGvTKH4dZ26QboXBahltOSam74zhQBQPOjYk kizdyvfRHozfJtqc1TKTUUUKBRg0zkDcxzDMeHr8jKiuE58wL6cDr71fZG++AarwiGhoUj ATR0vuvu4QSYg0sQQ5QqJOuckyCq1ug= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659987361; 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=D77zS7INJVOvYz/CP+vtDGyyfpLH7LZUg0F9gzXZvLY=; b=OaYlcdc2ivvDpB7Qg/8rky+enU8CbJ2VLA1p+tY3Yq+UlFAcEGz3a4TMc95MiyZgaoWIHT tnKzCUGeFp1OPWwOCaIUoTywyTRL95Lc0IMm5qMm0zk4NaXlesVSs29NjveVdaS99HJOyt 5eb8BxIHd23JhyFjdRhJ1Ba1aLdbUeU= X-Stat-Signature: fwpfi4d5wseo6waana7xf794tk3wfz5t X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 9E08EC015E Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=s7rZApVf; spf=none (imf10.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-HE-Tag: 1659987361-234266 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 51a1934f8353..fda56776b510 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2771,7 +2771,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 @@ -2782,10 +2782,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, @@ -2794,37 +2795,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