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 X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89245C433DF for ; Fri, 15 May 2020 13:42:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 48ACA20657 for ; Fri, 15 May 2020 13:42:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="IrKApeK6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 48ACA20657 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EC94D80062; Fri, 15 May 2020 09:42:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E7AC28004F; Fri, 15 May 2020 09:42:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D8EA780062; Fri, 15 May 2020 09:42:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0119.hostedemail.com [216.40.44.119]) by kanga.kvack.org (Postfix) with ESMTP id BF35D8004F for ; Fri, 15 May 2020 09:42:18 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 8277F8248047 for ; Fri, 15 May 2020 13:42:18 +0000 (UTC) X-FDA: 76819067556.01.cub44_141e3709bb824 X-HE-Tag: cub44_141e3709bb824 X-Filterd-Recvd-Size: 4408 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Fri, 15 May 2020 13:42:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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=luxQMNxsjlyzL3dO3H8OF5FGGq+cc+hC23qWt+yodv4=; b=IrKApeK6phIQeXhoHj4kPI5S8S XeGzPvU83JQejjMGg8APALZX1J1Q5EbV23IP/xOwbnUm1FMW2R4QIcamD1sleFTdLT3RYG0kx2fBW bF9dq4KaFOXTD/Bqa0Vjf4PggEMMpTkKBoKcx3Jx1j+ENl2bbpz7yOC3eFHY0fq43mnn7x2b59Or7 bsNeUPBYbk79pxc31kviLIYJmuXH2YhyG/qbfxhx3p+86UO9tuU9/I//9EKKRAOnBAFC72tuhCOUA gQhA19GX5d4X8Cpjvq7YmvG2bswxh09rloovGJNylk1BERy9swl/lARgJygMaRkRZ/kUrCvgSpZpq Onefk2EQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jZaD1-0005qC-2E; Fri, 15 May 2020 13:17:03 +0000 From: Matthew Wilcox To: linux-fsdevel@vger.kernel.org Cc: William Kucharski , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Matthew Wilcox Subject: [PATCH v4 36/36] mm: Align THP mappings for non-DAX Date: Fri, 15 May 2020 06:16:56 -0700 Message-Id: <20200515131656.12890-37-willy@infradead.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200515131656.12890-1-willy@infradead.org> References: <20200515131656.12890-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: William Kucharski When we have the opportunity to use transparent huge pages to map a file, we want to follow the same rules as DAX. Signed-off-by: William Kucharski [Inline __thp_get_unmapped_area() into thp_get_unmapped_area()] Signed-off-by: Matthew Wilcox (Oracle) --- mm/huge_memory.c | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 15a86b06befc..e78686b628ae 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -535,30 +535,30 @@ bool is_transparent_hugepage(struct page *page) } EXPORT_SYMBOL_GPL(is_transparent_hugepage); =20 -static unsigned long __thp_get_unmapped_area(struct file *filp, - unsigned long addr, unsigned long len, - loff_t off, unsigned long flags, unsigned long size) +unsigned long thp_get_unmapped_area(struct file *filp, unsigned long add= r, + unsigned long len, unsigned long pgoff, unsigned long flags) { + loff_t off =3D (loff_t)pgoff << PAGE_SHIFT; loff_t off_end =3D off + len; - loff_t off_align =3D round_up(off, size); + loff_t off_align =3D round_up(off, PMD_SIZE); unsigned long len_pad, ret; =20 - if (off_end <=3D off_align || (off_end - off_align) < size) - return 0; + if (off_end <=3D off_align || (off_end - off_align) < PMD_SIZE) + goto regular; =20 - len_pad =3D len + size; + len_pad =3D len + PMD_SIZE; if (len_pad < len || (off + len_pad) < off) - return 0; + goto regular; =20 ret =3D current->mm->get_unmapped_area(filp, addr, len_pad, off >> PAGE_SHIFT, flags); =20 /* - * The failure might be due to length padding. The caller will retry - * without the padding. + * The failure might be due to length padding. Retry without + * the padding. */ if (IS_ERR_VALUE(ret)) - return 0; + goto regular; =20 /* * Do not try to align to THP boundary if allocation at the address @@ -567,23 +567,9 @@ static unsigned long __thp_get_unmapped_area(struct = file *filp, if (ret =3D=3D addr) return addr; =20 - ret +=3D (off - ret) & (size - 1); + ret +=3D (off - ret) & (PMD_SIZE - 1); return ret; -} - -unsigned long thp_get_unmapped_area(struct file *filp, unsigned long add= r, - unsigned long len, unsigned long pgoff, unsigned long flags) -{ - unsigned long ret; - loff_t off =3D (loff_t)pgoff << PAGE_SHIFT; - - if (!IS_DAX(filp->f_mapping->host) || !IS_ENABLED(CONFIG_FS_DAX_PMD)) - goto out; - - ret =3D __thp_get_unmapped_area(filp, addr, len, off, flags, PMD_SIZE); - if (ret) - return ret; -out: +regular: return current->mm->get_unmapped_area(filp, addr, len, pgoff, flags); } EXPORT_SYMBOL_GPL(thp_get_unmapped_area); --=20 2.26.2