From patchwork Thu Jan 12 13:10:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 13097966 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 15BF9C54EBC for ; Thu, 12 Jan 2023 13:10:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8393B8E0002; Thu, 12 Jan 2023 08:10:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E9828E0001; Thu, 12 Jan 2023 08:10:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B0F88E0002; Thu, 12 Jan 2023 08:10:26 -0500 (EST) 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 58EE88E0001 for ; Thu, 12 Jan 2023 08:10:26 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1FF441A0829 for ; Thu, 12 Jan 2023 13:10:26 +0000 (UTC) X-FDA: 80346180852.16.679D144 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf15.hostedemail.com (Postfix) with ESMTP id 60E28A0013 for ; Thu, 12 Jan 2023 13:10:24 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Ms7jMJ+Y; spf=none (imf15.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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673529024; 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=iqOcpzIMrSEP5GavyN5r0FeJAMECYA4UB+bJ9rY0Tp0=; b=0cxt4FrAOnXYbR+oLmY3jLA6C4lfGnJLjWyw64cPUu2vMKgf278yXVU0K52z97VjXYJXxM vZrxdlWRL30m9GsUg2LG4Vyl8pKV887VtiJHe4Q6D2m7yQVcnF1YUBk65G98tCSgIzL3UO vRi26O572uqMTL4GPSGLJ62ZiMAs6XU= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Ms7jMJ+Y; spf=none (imf15.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=1673529024; a=rsa-sha256; cv=none; b=eOBGHKRy+hanHvwXah2h6G989h8Y6WKMzKredoDpJbSVuXy7Nnk4ZsJLGhywy7o7LVELrS xvh12GcLJFlYBG/C+PJCbfx5guiDy7h+xQxjl/py2BXFdavcLnVhbqZnhgHuOjo9W+voDh Zk4YLF64+p85EOaLYk9cAGf5PM3IIAM= 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: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=iqOcpzIMrSEP5GavyN5r0FeJAMECYA4UB+bJ9rY0Tp0=; b=Ms7jMJ+Yy//ExUM2JZGlk4mFJT MP/jpc1RYgsS8hNErLcXoyeN6c6LeDDe+TaY2UoAcoZSXQqYwfxj2zpUrJffb+Mpe3JXoK4FSo/BW oUSgkPV+XoIQBUOmymvolQl7ifCxM9732XayHQpzegB7is/u1bOmn8MJgBaGX4jDvOl1/vO6NWQRS lNL4klVF7jl5d5ri+QOHYHNO3PLBaQM3P4wp6Ad8t1KuEfKhLIpMWVdE5BK66kabwRBbu+/5EcLCR QRcOhPCM7eoFw+1blfwCPEXLrlbDNv6Cif8Yicy0d7LyxVYADsK6j3Pxn5Y7fqL8g1x/1iMvV48AV fmxMORRg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFxLl-0054gE-Jg; Thu, 12 Jan 2023 13:10:33 +0000 From: "Matthew Wilcox (Oracle)" To: Hugh Dickins , Andrew Morton , linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" Subject: [PATCH] shmem: Convert shmem_write_end() to use a folio Date: Thu, 12 Jan 2023 13:10:31 +0000 Message-Id: <20230112131031.1209553-1-willy@infradead.org> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 60E28A0013 X-Stat-Signature: o78pe9mnxpg75uuqok8sae1q4i8fatw7 X-HE-Tag: 1673529024-668135 X-HE-Meta: U2FsdGVkX1+JHf1ySN5moShkpM9BnF9Nih6zlN+i0k9kce+2CfhXZ1LRkXsUm6I0oOsBD/Y2O/U2qDdPjE+rErXg1nHsqfdKv/D3wrBQoKWOfY3vZ9ziK9Jf87yeAiaXqzto8Zj4Lt+yNkqW0bqlgGogfFOzJqCpfpNcBhRPUzIUUvoAEC0Wi5zUHm0ih45h48rKjr8mXxUI05tw6pK6b4657M9rScRlMT605d/DCvYVImWbOIwXmmAk9HRFlglk77U2XI3LM8C4ADnsepbofO/edEpzZ578YQ2A6PFXmcpwJI6+y7+URDAQWkg3cMCAtRgesoyswLmrwQ3P9gfEnyxS+7UL9t8iUeXFV+pjZxFsEALgDsNeihedJND2AC1eKyDtraE6wfCtLrS/A5HoAQxkvrUurGCROKgBkgVwvLNrVbk4/MaZK07ZFt5Gk97/zWeNA8lrkJQnOhOfUWhgSv0MPq1xpC/W1zBi+U4r61AKQhYrYeBy1be1YKsA05wc1tK+KWKs6KQasz8FRdHNYEEXMMYUAAhI+DkoSU0gY8nVpABgkovZNMQ5gVxfA4kTVe23Cj8nnylUfZebUMmdforlmYcZKBWsqdm/yuYp5ejByKHtMy9JoXa99U4ssSGNkQkYeuPLvZj4Xo7I8ohwQahHu/98zcn2JKSG+tArA6cQxINT0Nt+zsSdrtdEhST0AVMMauiQ2q0ehMxDGJ8XakpA17aO96xquNYKj8PchX0L9pK3r5ASSOWC66puY2JLxHCnZp4WXPQBsMEDECo/BzntMehuq65X2pH87HWyYw6f0QKyWdrMw/6Do6pM8fjIUFBvcl0ExX7py7hm+IPR2mXMJsJc0Gqldsdi/B5nbBw+0d9TfoohN2qOkzd/q6c8aQNuJsP97RAphFyb4Qf+CskvXvN2NxiHsVB4eEp2uv3/0UXI+PHccQ== 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: Use a folio internally to shmem_write_end() which saves a number of calls to compound_head() and lets us get rid of the custom code to zero out the rest of a THP and supports folios of arbitrary size. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: William Kucharski --- mm/shmem.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index bc5c156ef470..c5048c6c83dd 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2578,33 +2578,23 @@ shmem_write_end(struct file *file, struct address_space *mapping, loff_t pos, unsigned len, unsigned copied, struct page *page, void *fsdata) { + struct folio *folio = page_folio(page); struct inode *inode = mapping->host; if (pos + copied > inode->i_size) i_size_write(inode, pos + copied); - if (!PageUptodate(page)) { - struct page *head = compound_head(page); - if (PageTransCompound(page)) { - int i; - - for (i = 0; i < HPAGE_PMD_NR; i++) { - if (head + i == page) - continue; - clear_highpage(head + i); - flush_dcache_page(head + i); - } - } - if (copied < PAGE_SIZE) { - unsigned from = pos & (PAGE_SIZE - 1); - zero_user_segments(page, 0, from, - from + copied, PAGE_SIZE); + if (!folio_test_uptodate(folio)) { + if (copied < folio_size(folio)) { + size_t from = offset_in_folio(folio, pos); + folio_zero_segments(folio, 0, from, + from + copied, folio_size(folio)); } - SetPageUptodate(head); + folio_mark_uptodate(folio); } - set_page_dirty(page); - unlock_page(page); - put_page(page); + folio_mark_dirty(folio); + folio_unlock(folio); + folio_put(folio); return copied; }